Search in sources :

Example 61 with IntrospectionException

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

the class IndexedPropertyDescriptorTest method testSetIndexedWriteMethod_InvalidIndexType.

public void testSetIndexedWriteMethod_InvalidIndexType() 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("setPropertyFourInvalid2", new Class[] { String.class, String.class });
    try {
        ipd.setIndexedWriteMethod(badArgType);
        fail("Should throw IntrospectionException");
    } catch (IntrospectionException e) {
    }
    ipd = new IndexedPropertyDescriptor("data", NormalBean.class);
    ipd.setIndexedReadMethod(null);
    try {
        ipd.setIndexedWriteMethod(NormalBean.class.getMethod("setData", Integer.TYPE, Integer.TYPE));
        fail("should throw IntrospectionException");
    } 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 62 with IntrospectionException

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

the class IndexedPropertyDescriptorTest method testSetIndexedReadMethod_RInvalidReturn.

/*
     * indexed read method with void return.
     */
public void testSetIndexedReadMethod_RInvalidReturn() 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());
    Method voidMethod = beanClass.getMethod("getPropertyFourInvalid", new Class[] { Integer.TYPE });
    try {
        ipd.setIndexedReadMethod(voidMethod);
        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 63 with IntrospectionException

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

the class IntrospectionExceptionTest method testIntrospectionExceptionMessage.

public void testIntrospectionExceptionMessage() {
    // Regression for HARMONY-235
    IntrospectionException e = new IntrospectionException("test message");
    assertEquals("test message", e.getMessage());
}
Also used : IntrospectionException(java.beans.IntrospectionException)

Example 64 with IntrospectionException

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

the class EventSetDescriptorTest method testEventSetDescriptorClassStringClassStringArrayStringStringString.

/*
     * Class under test for void EventSetDescriptor(Class, String, Class,
     * String[], String, String, String)
     */
public void testEventSetDescriptorClassStringClassStringArrayStringStringString() throws IntrospectionException {
    Class<MockSourceClass> sourceClass = MockSourceClass.class;
    String eventSetName = "MockPropertyChange";
    Class<?> listenerType = MockPropertyChangeListener.class;
    String[] listenerMethodNames = { "mockPropertyChange", "mockPropertyChange2" };
    String addMethod = "addMockPropertyChangeListener";
    String removeMethod = "removeMockPropertyChangeListener";
    String getMethod = "getMockPropertyChangeListener";
    EventSetDescriptor esd = new EventSetDescriptor(sourceClass, eventSetName, listenerType, listenerMethodNames, addMethod, removeMethod, getMethod);
    assertEquals(addMethod, esd.getAddListenerMethod().getName());
    assertEquals(removeMethod, esd.getRemoveListenerMethod().getName());
    assertNull(esd.getGetListenerMethod());
    assertEquals(2, esd.getListenerMethods().length);
    assertEquals(listenerMethodNames[0], esd.getListenerMethods()[0].getName());
    assertEquals(listenerMethodNames[1], esd.getListenerMethods()[1].getName());
    assertEquals(2, esd.getListenerMethodDescriptors().length);
    assertEquals(listenerMethodNames[0], esd.getListenerMethodDescriptors()[0].getMethod().getName());
    assertEquals(listenerMethodNames[1], esd.getListenerMethodDescriptors()[1].getMethod().getName());
    assertEquals(listenerType, esd.getListenerType());
    assertTrue(esd.isInDefaultEventSet());
    assertFalse(esd.isUnicast());
    // Regression for HARMONY-1237
    try {
        new EventSetDescriptor(Thread.class, "0xABCD", Thread.class, new String[] {}, "aaa", null, "bbb");
        fail("IntrospectionException expected");
    } catch (IntrospectionException e) {
    // expected
    }
}
Also used : MockPropertyChangeListener(org.apache.harmony.beans.tests.support.mock.MockPropertyChangeListener) IntrospectionException(java.beans.IntrospectionException) EventSetDescriptor(java.beans.EventSetDescriptor)

Example 65 with IntrospectionException

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

the class IndexedPropertyDescriptorTest method testIndexedPropertyDescriptorStringClassStringStringStringString.

/*
     * Class under test for void IndexedPropertyDescriptor(String, Class,
     * String, String, String, String)
     */
public void testIndexedPropertyDescriptorStringClassStringStringStringString() throws IntrospectionException, SecurityException, NoSuchMethodException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, beanClass, "get" + propertyName, "set" + propertyName, "get" + propertyName, "set" + propertyName);
    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 });
    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());
    //empty method name
    new IndexedPropertyDescriptor(propertyName, beanClass, "get" + propertyName, "set" + propertyName, "", "set" + propertyName);
    try {
        new IndexedPropertyDescriptor("a", MyClass.class, "getA", "setA", "", "setA");
        fail("Shoule throw exception");
    } catch (IntrospectionException e) {
    // expected
    }
    try {
        new IndexedPropertyDescriptor(propertyName, beanClass, "", "set" + propertyName, "get" + propertyName, "set" + propertyName);
        fail("Shoule throw exception");
    } catch (IntrospectionException e) {
    // expected
    }
    try {
        new IndexedPropertyDescriptor(propertyName, beanClass, "get" + propertyName, "", "get" + propertyName, "set" + propertyName);
        fail("Shoule throw exception");
    } catch (IntrospectionException e) {
    // expected
    }
    try {
        new IndexedPropertyDescriptor(propertyName, beanClass, "get" + propertyName, "set" + propertyName, "get" + propertyName, "");
        fail("Shoule throw exception");
    } catch (IntrospectionException e) {
    // expected
    }
    //null method name
    new IndexedPropertyDescriptor(propertyName, beanClass, "get" + propertyName, "set" + propertyName, null, "set" + propertyName);
    new IndexedPropertyDescriptor(propertyName, beanClass, null, "set" + propertyName, "get" + propertyName, "set" + propertyName);
    new IndexedPropertyDescriptor(propertyName, beanClass, "get" + propertyName, null, "get" + propertyName, "set" + propertyName);
    new IndexedPropertyDescriptor(propertyName, beanClass, "get" + propertyName, "set" + propertyName, "get" + propertyName, null);
}
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