Search in sources :

Example 31 with MockJavaBean

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

the class PropertyDescriptorTest method testPropertyDescriptorStringMethodMethod_ReadMethodNull.

public void testPropertyDescriptorStringMethodMethod_ReadMethodNull() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String propertyName = "PropertyOne";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = null;
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String.class });
    PropertyDescriptor pd = new PropertyDescriptor(propertyName, readMethod, writeMethod);
    assertEquals(String.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());
}
Also used : MockJavaBean(org.apache.harmony.beans.tests.support.mock.MockJavaBean) PropertyDescriptor(java.beans.PropertyDescriptor) Method(java.lang.reflect.Method)

Example 32 with MockJavaBean

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

the class PropertyDescriptorTest method testSetWriteMethod.

/**
 * normal input
 */
public void testSetWriteMethod() throws SecurityException, NoSuchMethodException, IntrospectionException {
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    String propertyName = "PropertyOne";
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String.class });
    PropertyDescriptor pd = new PropertyDescriptor(propertyName, null, null);
    assertNull(pd.getWriteMethod());
    pd.setWriteMethod(writeMethod);
    assertSame(writeMethod, pd.getWriteMethod());
}
Also used : MockJavaBean(org.apache.harmony.beans.tests.support.mock.MockJavaBean) PropertyDescriptor(java.beans.PropertyDescriptor) Method(java.lang.reflect.Method)

Example 33 with MockJavaBean

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

the class PropertyDescriptorTest method testPropertyDescriptorStringClassStringString.

/*
     * Class under test for void PropertyDescriptor(String, Class, String,
     * String)
     */
public void testPropertyDescriptorStringClassStringString() throws IntrospectionException {
    String propertyName = "PropertyTwo";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    PropertyDescriptor pd = new PropertyDescriptor(propertyName, beanClass, "get" + propertyName, "set" + propertyName);
    assertEquals(Integer.class, pd.getPropertyType());
    assertEquals("get" + propertyName, pd.getReadMethod().getName());
    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());
}
Also used : MockJavaBean(org.apache.harmony.beans.tests.support.mock.MockJavaBean) PropertyDescriptor(java.beans.PropertyDescriptor)

Example 34 with MockJavaBean

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

the class PropertyDescriptorTest method testSetReadMethod_ReadWriteIncompatible.

/**
 * Read method is incompatible with write method getPropertyOn vs.
 * setPropertyTow
 */
public void testSetReadMethod_ReadWriteIncompatible() throws SecurityException, NoSuchMethodException, IntrospectionException {
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    String propertyName = "PropertyOne";
    Method readMethod = beanClass.getMethod("get" + "PropertyOne", (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + "PropertyTwo", new Class[] { Integer.class });
    PropertyDescriptor pd = new PropertyDescriptor(propertyName, null, writeMethod);
    assertNull(pd.getReadMethod());
    try {
        pd.setReadMethod(readMethod);
        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)

Example 35 with MockJavaBean

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

the class PropertyDescriptorTest method testSetReadMethod_Invalid.

/**
 * Read method is incompatible with property name getPropertyTwo vs.
 * PropertyOne (writeMethod=null)
 */
public void testSetReadMethod_Invalid() throws SecurityException, NoSuchMethodException, IntrospectionException {
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    String propertyName = "PropertyOne";
    Method readMethod = beanClass.getMethod("get" + "PropertyTwo", (Class[]) null);
    PropertyDescriptor pd = new PropertyDescriptor(propertyName, null, null);
    assertNull(pd.getReadMethod());
    pd.setReadMethod(readMethod);
    assertSame(readMethod, pd.getReadMethod());
}
Also used : MockJavaBean(org.apache.harmony.beans.tests.support.mock.MockJavaBean) PropertyDescriptor(java.beans.PropertyDescriptor) 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