Search in sources :

Example 66 with IntrospectionException

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

the class IndexedPropertyDescriptorTest method testSetIndexedReadMethod_RInvalidArgType.

/*
     * indexed read method with invalid arg type (!Integer.TYPE)
     */
public void testSetIndexedReadMethod_RInvalidArgType() throws SecurityException, NoSuchMethodException, IntrospectionException {
    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 });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, indexedWriteMethod);
    assertSame(indexedReadMethod, ipd.getIndexedReadMethod());
    try {
        ipd.setIndexedReadMethod(writeMethod);
        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 67 with IntrospectionException

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

the class IndexedPropertyDescriptorTest method testSetIndexedMethodNullNull.

public void testSetIndexedMethodNullNull() throws Exception {
    try {
        IndexedPropertyDescriptor i = new IndexedPropertyDescriptor("a", NormalBean.class, "getData", "setData", null, "setData");
        i.setIndexedWriteMethod(null);
        fail("should throw IntrospectionException.");
    } catch (IntrospectionException e) {
    // expected
    }
    try {
        IndexedPropertyDescriptor i = new IndexedPropertyDescriptor("a", NormalBean.class, "getData", "setData", "getData", null);
        i.setIndexedReadMethod(null);
        fail("should throw IntrospectionException.");
    } catch (IntrospectionException e) {
    // expected
    }
}
Also used : IntrospectionException(java.beans.IntrospectionException) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor)

Example 68 with IntrospectionException

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

the class IndexedPropertyDescriptorTest method testIndexedPropertyDescriptorStringMethodMethodMethodMethod_propEmpty.

/*
     * propertyname="";
     */
public void testIndexedPropertyDescriptorStringMethodMethodMethodMethod_propEmpty() throws SecurityException, 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 });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    try {
        new IndexedPropertyDescriptor("", readMethod, writeMethod, indexedReadMethod, indexedWriteMethod);
        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 69 with IntrospectionException

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

the class IndexedPropertyDescriptorTest method testIndexedPropertyDescriptorStringClass.

/*
     * Class under test for void IndexedPropertyDescriptor(String, Class)
     */
public void testIndexedPropertyDescriptorStringClass() throws IntrospectionException, SecurityException, NoSuchMethodException {
    String propertyName = "propertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, beanClass);
    String capitalName = propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1);
    Method readMethod = beanClass.getMethod("get" + capitalName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + capitalName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + capitalName, new Class[] { Integer.TYPE });
    Method indexedWriteMethod = beanClass.getMethod("set" + capitalName, new Class[] { Integer.TYPE, String.class });
    assertEquals(readMethod, ipd.getReadMethod());
    assertEquals(writeMethod, ipd.getWriteMethod());
    assertEquals(indexedReadMethod, ipd.getIndexedReadMethod());
    assertEquals(indexedWriteMethod, ipd.getIndexedWriteMethod());
    assertEquals(String[].class, ipd.getPropertyType());
    assertEquals(String.class, ipd.getIndexedPropertyType());
    assertFalse(ipd.isBound());
    assertFalse(ipd.isConstrained());
    assertEquals(propertyName, ipd.getDisplayName());
    assertEquals(propertyName, ipd.getName());
    assertEquals(propertyName, ipd.getShortDescription());
    assertNotNull(ipd.attributeNames());
    assertFalse(ipd.isExpert());
    assertFalse(ipd.isHidden());
    assertFalse(ipd.isPreferred());
    // Regression for HARMONY-1236
    try {
        new IndexedPropertyDescriptor("0xDFRF", Float.TYPE);
        fail("IntrospectionException expected");
    } catch (IntrospectionException e) {
    // expected
    }
}
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 70 with IntrospectionException

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

the class IndexedPropertyDescriptorTest method testSetIndexedReadMethod_invalid.

public void testSetIndexedReadMethod_invalid() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, null, null, indexedReadMethod, indexedWriteMethod);
    Method indexedReadMethod2 = beanClass.getMethod("getPropertySix", new Class[] { Integer.TYPE });
    try {
        ipd.setIndexedReadMethod(indexedReadMethod2);
        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)

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