Search in sources :

Example 16 with MethodDescriptor

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

the class EventSetDescriptorTest method testEventSetDescriptorStringClassMethodDescriptorArrayMethodMethod_ListenerMDInvalid.

/*
     * listenerMethodDescriptors is invalid
     */
public void testEventSetDescriptorStringClassMethodDescriptorArrayMethodMethod_ListenerMDInvalid() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String eventSetName = "MockPropertyChange";
    Class<?> listenerType = MockPropertyChangeListener.class;
    Method[] listenerMethods = { listenerType.getMethod("mockPropertyChange", MockPropertyChangeEvent.class), listenerType.getMethod("mockPropertyChange_Invalid") };
    MethodDescriptor[] listenerMethodDescriptors = { new MethodDescriptor(listenerMethods[0]), new MethodDescriptor(listenerMethods[1]) };
    Class<MockSourceClass> sourceClass = MockSourceClass.class;
    Method addMethod = sourceClass.getMethod("addMockPropertyChangeListener", listenerType);
    Method removeMethod = sourceClass.getMethod("removeMockPropertyChangeListener", listenerType);
    // RI doesn't check parameters of listener methods
    EventSetDescriptor esd = new EventSetDescriptor(eventSetName, listenerType, listenerMethodDescriptors, addMethod, removeMethod);
    assertEquals(0, esd.getListenerMethods()[1].getParameterTypes().length);
    assertEquals(listenerMethodDescriptors[1], esd.getListenerMethodDescriptors()[1]);
}
Also used : MockPropertyChangeListener(org.apache.harmony.beans.tests.support.mock.MockPropertyChangeListener) MockPropertyChangeEvent(org.apache.harmony.beans.tests.support.mock.MockPropertyChangeEvent) Method(java.lang.reflect.Method) MethodDescriptor(java.beans.MethodDescriptor) EventSetDescriptor(java.beans.EventSetDescriptor)

Example 17 with MethodDescriptor

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

the class IntrospectorTest method testGetBeanInfo_StaticMethods.

/*
     * Introspect static methods
     */
public void testGetBeanInfo_StaticMethods() throws Exception {
    BeanInfo beanInfo = Introspector.getBeanInfo(StaticClazz.class);
    PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
    assertEquals(1, propertyDescriptors.length);
    assertTrue(contains("class", Class.class, propertyDescriptors));
    MethodDescriptor[] methodDescriptors = beanInfo.getMethodDescriptors();
    assertTrue(contains("getStaticMethod", methodDescriptors));
    assertTrue(contains("setStaticMethod", methodDescriptors));
    beanInfo = Introspector.getBeanInfo(StaticClazzWithProperty.class);
    propertyDescriptors = beanInfo.getPropertyDescriptors();
    assertEquals(1, propertyDescriptors.length);
    methodDescriptors = beanInfo.getMethodDescriptors();
    assertTrue(contains("getStaticName", methodDescriptors));
    assertTrue(contains("setStaticName", methodDescriptors));
}
Also used : IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) PropertyDescriptor(java.beans.PropertyDescriptor) BeanInfo(java.beans.BeanInfo) SimpleBeanInfo(java.beans.SimpleBeanInfo) FakeFox01BeanInfo(org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo) MockNullSubClass(org.apache.harmony.beans.tests.support.mock.MockNullSubClass) MethodDescriptor(java.beans.MethodDescriptor)

Example 18 with MethodDescriptor

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

the class EventSetDescriptorTest method testEventSetDescriptorStringClassMethodDescriptorArrayMethodMethod.

/*
     * Class under test for void EventSetDescriptor(String, Class,
     * MethodDescriptor[], Method, Method)
     */
public void testEventSetDescriptorStringClassMethodDescriptorArrayMethodMethod() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String eventSetName = "MockPropertyChange";
    Class<?> listenerType = MockPropertyChangeListener.class;
    Method[] listenerMethods = { listenerType.getMethod("mockPropertyChange", MockPropertyChangeEvent.class), listenerType.getMethod("mockPropertyChange2", MockPropertyChangeEvent.class) };
    MethodDescriptor[] listenerMethodDescriptors = { new MethodDescriptor(listenerMethods[0]), new MethodDescriptor(listenerMethods[1]) };
    Class<MockSourceClass> sourceClass = MockSourceClass.class;
    Method addMethod = sourceClass.getMethod("addMockPropertyChangeListener", listenerType);
    Method removeMethod = sourceClass.getMethod("removeMockPropertyChangeListener", listenerType);
    EventSetDescriptor esd = new EventSetDescriptor(eventSetName, listenerType, listenerMethodDescriptors, addMethod, removeMethod);
    assertEquals(addMethod, esd.getAddListenerMethod());
    assertEquals(removeMethod, esd.getRemoveListenerMethod());
    assertNull(esd.getGetListenerMethod());
    assertEquals(listenerMethods[0], esd.getListenerMethods()[0]);
    assertEquals(listenerMethods[1], esd.getListenerMethods()[1]);
    assertEquals(2, esd.getListenerMethodDescriptors().length);
    assertEquals(listenerMethods[0], esd.getListenerMethodDescriptors()[0].getMethod());
    assertEquals(listenerMethods[1], esd.getListenerMethodDescriptors()[1].getMethod());
    assertEquals(listenerType, esd.getListenerType());
    assertTrue(esd.isInDefaultEventSet());
    assertFalse(esd.isUnicast());
}
Also used : MockPropertyChangeListener(org.apache.harmony.beans.tests.support.mock.MockPropertyChangeListener) MockPropertyChangeEvent(org.apache.harmony.beans.tests.support.mock.MockPropertyChangeEvent) Method(java.lang.reflect.Method) MethodDescriptor(java.beans.MethodDescriptor) EventSetDescriptor(java.beans.EventSetDescriptor)

Example 19 with MethodDescriptor

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

the class MethodDescriptorTest method testMethodDescriptorMethod.

/*
     * Class under test for void MethodDescriptor(Method)
     */
public void testMethodDescriptorMethod() throws SecurityException, NoSuchMethodException {
    String beanName = "MethodDescriptorTest.bean";
    MockJavaBean bean = new MockJavaBean(beanName);
    Method method = bean.getClass().getMethod("getBeanName", (Class[]) null);
    MethodDescriptor md = new MethodDescriptor(method);
    assertSame(method, md.getMethod());
    assertNull(md.getParameterDescriptors());
    assertEquals(method.getName(), md.getDisplayName());
    assertEquals(method.getName(), md.getName());
    assertEquals(method.getName(), md.getShortDescription());
    assertNotNull(md.attributeNames());
    assertFalse(md.isExpert());
    assertFalse(md.isHidden());
    assertFalse(md.isPreferred());
}
Also used : MockJavaBean(org.apache.harmony.beans.tests.support.mock.MockJavaBean) Method(java.lang.reflect.Method) MethodDescriptor(java.beans.MethodDescriptor)

Example 20 with MethodDescriptor

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

the class MethodDescriptorTest method testMethodDescriptorMethodParameterDescriptorArray.

/*
     * Class under test for void MethodDescriptor(Method, ParameterDescriptor[])
     */
public void testMethodDescriptorMethodParameterDescriptorArray() throws SecurityException, NoSuchMethodException {
    String beanName = "MethodDescriptorTest.bean";
    MockJavaBean bean = new MockJavaBean(beanName);
    Method method = bean.getClass().getMethod("setPropertyOne", new Class[] { String.class });
    ParameterDescriptor[] pds = new ParameterDescriptor[1];
    pds[0] = new ParameterDescriptor();
    pds[0].setValue(method.getName(), method.getReturnType());
    MethodDescriptor md = new MethodDescriptor(method, pds);
    assertSame(method, md.getMethod());
    assertSame(pds, md.getParameterDescriptors());
    assertEquals(pds[0].getValue(method.getName()), md.getParameterDescriptors()[0].getValue(method.getName()));
    assertEquals(method.getName(), md.getDisplayName());
    assertEquals(method.getName(), md.getName());
    assertEquals(method.getName(), md.getShortDescription());
    assertNotNull(md.attributeNames());
    assertFalse(md.isExpert());
    assertFalse(md.isHidden());
    assertFalse(md.isPreferred());
}
Also used : MockJavaBean(org.apache.harmony.beans.tests.support.mock.MockJavaBean) ParameterDescriptor(java.beans.ParameterDescriptor) Method(java.lang.reflect.Method) MethodDescriptor(java.beans.MethodDescriptor)

Aggregations

MethodDescriptor (java.beans.MethodDescriptor)26 Method (java.lang.reflect.Method)18 EventSetDescriptor (java.beans.EventSetDescriptor)9 BeanInfo (java.beans.BeanInfo)8 MockPropertyChangeListener (org.apache.harmony.beans.tests.support.mock.MockPropertyChangeListener)7 MockPropertyChangeEvent (org.apache.harmony.beans.tests.support.mock.MockPropertyChangeEvent)6 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)5 PropertyDescriptor (java.beans.PropertyDescriptor)5 SimpleBeanInfo (java.beans.SimpleBeanInfo)5 FakeFox01BeanInfo (org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo)5 ParameterDescriptor (java.beans.ParameterDescriptor)4 BeanDescriptor (java.beans.BeanDescriptor)3 MockJavaBean (org.apache.harmony.beans.tests.support.mock.MockJavaBean)3 IntrospectionException (java.beans.IntrospectionException)2 ArrayList (java.util.ArrayList)2 KeyEvent (java.awt.event.KeyEvent)1 KeyListener (java.awt.event.KeyListener)1 FeatureDescriptor (java.beans.FeatureDescriptor)1 IndexedPropertyChangeEvent (java.beans.IndexedPropertyChangeEvent)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1