Search in sources :

Example 71 with IntrospectionException

use of java.beans.IntrospectionException in project j2objc by google.

the class IndexedPropertyDescriptorTest method testSetIndexedWriteMethod_noargs.

/*
     * bad arg count
     */
public void testSetIndexedWriteMethod_noargs() throws IntrospectionException, NoSuchMethodException, NoSuchMethodException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, null);
    assertNull(ipd.getIndexedWriteMethod());
    try {
        ipd.setIndexedWriteMethod(indexedReadMethod);
        fail("Should throw IntrospectionException.");
    } catch (IntrospectionException e) {
    }
}
Also used : MockJavaBean(org.apache.harmony.beans.tests.support.mock.MockJavaBean) IntrospectionException(java.beans.IntrospectionException) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) Method(java.lang.reflect.Method)

Example 72 with IntrospectionException

use of java.beans.IntrospectionException in project j2objc by google.

the class IndexedPropertyDescriptorTest method testSetIndexedReadMethodFollowANullValue.

public void testSetIndexedReadMethodFollowANullValue() throws Exception {
    try {
        IndexedPropertyDescriptor i = new IndexedPropertyDescriptor("a", DummyBean.class, "readMethod", "writeMethod", null, "indexedReadMethod");
        Method irm = DummyBean.class.getDeclaredMethod("indexedReadMethod", Integer.TYPE);
        i.setIndexedReadMethod(irm);
        fail("should throw IntrospectionException.");
    } catch (IntrospectionException e) {
    // expected
    }
}
Also used : IntrospectionException(java.beans.IntrospectionException) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) Method(java.lang.reflect.Method)

Example 73 with IntrospectionException

use of java.beans.IntrospectionException in project j2objc by google.

the class IndexedPropertyDescriptorTest method testSetIndexedWriteMethod_badargtype.

/*
     * bad arg type
     */
public void testSetIndexedWriteMethod_badargtype() throws IntrospectionException, NoSuchMethodException, NoSuchMethodException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, null);
    assertNull(ipd.getIndexedWriteMethod());
    Method badArgType = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, Integer.TYPE });
    try {
        ipd.setIndexedWriteMethod(badArgType);
        fail("Should throw IntrospectionException");
    } catch (IntrospectionException e) {
    }
}
Also used : MockJavaBean(org.apache.harmony.beans.tests.support.mock.MockJavaBean) IntrospectionException(java.beans.IntrospectionException) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) Method(java.lang.reflect.Method)

Example 74 with IntrospectionException

use of java.beans.IntrospectionException in project j2objc by google.

the class PropertyDescriptorTest method testPropertyDescriptorStringClassStringString_ReadMethodNull.

public void testPropertyDescriptorStringClassStringString_ReadMethodNull() throws IntrospectionException {
    String propertyName = "PropertyTwo";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    PropertyDescriptor pd = new PropertyDescriptor(propertyName, beanClass, null, "set" + propertyName);
    assertEquals(Integer.class, pd.getPropertyType());
    assertNull(pd.getReadMethod());
    assertEquals("set" + propertyName, pd.getWriteMethod().getName());
    assertFalse(pd.isBound());
    assertFalse(pd.isConstrained());
    assertEquals(propertyName, pd.getDisplayName());
    assertEquals(propertyName, pd.getName());
    assertEquals(propertyName, pd.getShortDescription());
    assertNotNull(pd.attributeNames());
    assertFalse(pd.isExpert());
    assertFalse(pd.isHidden());
    assertFalse(pd.isPreferred());
    try {
        pd = new PropertyDescriptor(propertyName, beanClass, "", "set" + propertyName);
        fail("should throw exception");
    } catch (IntrospectionException e) {
    }
}
Also used : MockJavaBean(org.apache.harmony.beans.tests.support.mock.MockJavaBean) PropertyDescriptor(java.beans.PropertyDescriptor) IntrospectionException(java.beans.IntrospectionException)

Example 75 with IntrospectionException

use of java.beans.IntrospectionException in project j2objc by google.

the class PropertyDescriptorTest method testSetWriteMethod_WriteReadIncompatible.

/**
     * write method is incompatible with read method
     */
public void testSetWriteMethod_WriteReadIncompatible() throws SecurityException, NoSuchMethodException, IntrospectionException {
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    String propertyName = "PropertyOne";
    Method readMethod = beanClass.getMethod("get" + "PropertyTwo", (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String.class });
    PropertyDescriptor pd = new PropertyDescriptor(propertyName, readMethod, null);
    assertNull(pd.getWriteMethod());
    try {
        pd.setWriteMethod(writeMethod);
        fail("Should throw IntrospectionException.");
    } catch (IntrospectionException e) {
    }
}
Also used : MockJavaBean(org.apache.harmony.beans.tests.support.mock.MockJavaBean) PropertyDescriptor(java.beans.PropertyDescriptor) IntrospectionException(java.beans.IntrospectionException) Method(java.lang.reflect.Method)

Aggregations

IntrospectionException (java.beans.IntrospectionException)111 PropertyDescriptor (java.beans.PropertyDescriptor)65 Method (java.lang.reflect.Method)46 BeanInfo (java.beans.BeanInfo)44 MockJavaBean (org.apache.harmony.beans.tests.support.mock.MockJavaBean)24 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)17 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 Field (java.lang.reflect.Field)9 EventSetDescriptor (java.beans.EventSetDescriptor)7 List (java.util.List)6 Map (java.util.Map)6 MessageFormat (java.text.MessageFormat)5 UUID (java.util.UUID)5 Assert (org.springframework.util.Assert)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 Optional (java.util.Optional)4 RecursiveChildrenListManager (cern.gp.explorer.test.helpers.RecursiveChildrenListManager)3 SimpleDemoBean (cern.gp.explorer.test.helpers.SimpleDemoBean)3