Search in sources :

Example 46 with MockJavaBean

use of org.apache.harmony.beans.tests.support.mock.MockJavaBean in project j2objc by google.

the class IndexedPropertyDescriptorTest method testSetIndexedWriteMethod.

public void testSetIndexedWriteMethod() 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 });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, null);
    assertNull(ipd.getIndexedWriteMethod());
    ipd.setIndexedWriteMethod(indexedWriteMethod);
    assertSame(indexedWriteMethod, ipd.getIndexedWriteMethod());
}
Also used : MockJavaBean(org.apache.harmony.beans.tests.support.mock.MockJavaBean) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) Method(java.lang.reflect.Method)

Example 47 with MockJavaBean

use of org.apache.harmony.beans.tests.support.mock.MockJavaBean 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 48 with MockJavaBean

use of org.apache.harmony.beans.tests.support.mock.MockJavaBean 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 49 with MockJavaBean

use of org.apache.harmony.beans.tests.support.mock.MockJavaBean in project j2objc by google.

the class IndexedPropertyDescriptorTest method testIndexedPropertyDescriptorStringClassStringStringStringString_RWNull.

/**
     * indexed read/write null
     *
     */
public void testIndexedPropertyDescriptorStringClassStringStringStringString_RWNull() throws IntrospectionException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, beanClass, null, null, "get" + propertyName, "set" + propertyName);
    assertNull(ipd.getReadMethod());
    assertNull(ipd.getWriteMethod());
    assertEquals(String.class, ipd.getIndexedPropertyType());
    assertNull(ipd.getPropertyType());
}
Also used : MockJavaBean(org.apache.harmony.beans.tests.support.mock.MockJavaBean) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor)

Example 50 with MockJavaBean

use of org.apache.harmony.beans.tests.support.mock.MockJavaBean in project j2objc by google.

the class IndexedPropertyDescriptorTest method testEquals_ReadMethod.

/*
     * Read method
     */
public void testEquals_ReadMethod() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("getPropertyFive", (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);
    IndexedPropertyDescriptor ipd2 = new IndexedPropertyDescriptor(propertyName, beanClass);
    assertFalse(ipd.equals(ipd2));
}
Also used : MockJavaBean(org.apache.harmony.beans.tests.support.mock.MockJavaBean) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) Method(java.lang.reflect.Method)

Aggregations

MockJavaBean (org.apache.harmony.beans.tests.support.mock.MockJavaBean)89 Method (java.lang.reflect.Method)66 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)49 PropertyDescriptor (java.beans.PropertyDescriptor)34 IntrospectionException (java.beans.IntrospectionException)24 MethodDescriptor (java.beans.MethodDescriptor)3 BeanDescriptor (java.beans.BeanDescriptor)2 ParameterDescriptor (java.beans.ParameterDescriptor)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1