Search in sources :

Example 51 with MockJavaBean

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

the class IndexedPropertyDescriptorTest method testIndexedPropertyDescriptorStringClassStringStringStringString_IndexedRWIncompatible.

/**
     * IndexedRead/IndexedWrite incompatible
     *
     * @throws IntrospectionException
     *
     */
public void testIndexedPropertyDescriptorStringClassStringStringStringString_IndexedRWIncompatible() throws IntrospectionException {
    String propertyName = "PropertyFour";
    String anotherProp = "PropertyFive";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, beanClass, "get" + propertyName, "set" + propertyName, "get" + propertyName, "set" + anotherProp);
    assertEquals(String.class, ipd.getIndexedPropertyType());
    assertEquals(String[].class, ipd.getPropertyType());
    assertEquals("set" + anotherProp, ipd.getIndexedWriteMethod().getName());
}
Also used : MockJavaBean(org.apache.harmony.beans.tests.support.mock.MockJavaBean) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor)

Example 52 with MockJavaBean

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

Example 53 with MockJavaBean

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

the class IndexedPropertyDescriptorTest method testIndexedPropertyDescriptorStringClassStringStringStringString_allNull.

public void testIndexedPropertyDescriptorStringClassStringStringStringString_allNull() throws IntrospectionException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, beanClass, null, null, null, null);
    assertNull(ipd.getIndexedPropertyType());
    assertNull(ipd.getPropertyType());
    assertNull(ipd.getReadMethod());
    assertNull(ipd.getIndexedReadMethod());
}
Also used : MockJavaBean(org.apache.harmony.beans.tests.support.mock.MockJavaBean) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor)

Example 54 with MockJavaBean

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

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

the class IndexedPropertyDescriptorTest method testSetIndexedWriteMethod_return.

public void testSetIndexedWriteMethod_return() 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("setPropertyFourInvalid", new Class[] { Integer.TYPE, String.class });
    ipd.setIndexedWriteMethod(badArgType);
    assertEquals(String.class, ipd.getIndexedPropertyType());
    assertEquals(String[].class, ipd.getPropertyType());
    assertEquals(Integer.TYPE, ipd.getIndexedWriteMethod().getReturnType());
}
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