Search in sources :

Example 31 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)

Example 32 with MethodDescriptor

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

the class EventSetDescriptorTest method testSetUnicast.

public void testSetUnicast() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String eventSetName = "MockPropertyChange";
    Class<?> listenerType = MockPropertyChangeListener.class;
    Method[] listenerMethods = { listenerType.getMethod("mockPropertyChange", new Class[] { MockPropertyChangeEvent.class }), listenerType.getMethod("mockPropertyChange2", new Class[] { MockPropertyChangeEvent.class }) };
    MethodDescriptor[] listenerMethodDescriptors = { new MethodDescriptor(listenerMethods[0]), new MethodDescriptor(listenerMethods[1]) };
    Class<MockSourceClass> sourceClass = MockSourceClass.class;
    Method addMethod = sourceClass.getMethod("addMockPropertyChangeListener", new Class[] { listenerType });
    Method removeMethod = sourceClass.getMethod("removeMockPropertyChangeListener", new Class[] { listenerType });
    EventSetDescriptor esd = new EventSetDescriptor(eventSetName, listenerType, listenerMethodDescriptors, addMethod, removeMethod);
    assertFalse(esd.isUnicast());
    esd.setInDefaultEventSet(true);
    assertTrue(esd.isInDefaultEventSet());
}
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 33 with MethodDescriptor

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

the class EventSetDescriptorTest method testEventSetDescriptorStringClassMethodDescriptorArrayMethodMethod_ListenerMDNull.

/*
     * listenerMethodDescriptors is null
     */
public void testEventSetDescriptorStringClassMethodDescriptorArrayMethodMethod_ListenerMDNull() throws IntrospectionException, NoSuchMethodException {
    String eventSetName = "MockPropertyChange";
    Class<?> listenerType = MockPropertyChangeListener.class;
    Class<MockSourceClass> sourceClass = MockSourceClass.class;
    Method addMethod = sourceClass.getMethod("addMockPropertyChangeListener", listenerType);
    Method removeMethod = sourceClass.getMethod("removeMockPropertyChangeListener", listenerType);
    EventSetDescriptor esd = new EventSetDescriptor(eventSetName, listenerType, (MethodDescriptor[]) null, addMethod, removeMethod);
    assertNull(esd.getListenerMethodDescriptors());
    assertNull(esd.getListenerMethods());
}
Also used : MockPropertyChangeListener(org.apache.harmony.beans.tests.support.mock.MockPropertyChangeListener) Method(java.lang.reflect.Method) EventSetDescriptor(java.beans.EventSetDescriptor) MethodDescriptor(java.beans.MethodDescriptor)

Example 34 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 35 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)

Aggregations

MethodDescriptor (java.beans.MethodDescriptor)36 Method (java.lang.reflect.Method)22 BeanInfo (java.beans.BeanInfo)14 PropertyDescriptor (java.beans.PropertyDescriptor)11 EventSetDescriptor (java.beans.EventSetDescriptor)10 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)7 MockPropertyChangeListener (org.apache.harmony.beans.tests.support.mock.MockPropertyChangeListener)7 IntrospectionException (java.beans.IntrospectionException)6 MockPropertyChangeEvent (org.apache.harmony.beans.tests.support.mock.MockPropertyChangeEvent)6 SimpleBeanInfo (java.beans.SimpleBeanInfo)5 ArrayList (java.util.ArrayList)5 FakeFox01BeanInfo (org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo)5 BeanDescriptor (java.beans.BeanDescriptor)4 ParameterDescriptor (java.beans.ParameterDescriptor)4 MockJavaBean (org.apache.harmony.beans.tests.support.mock.MockJavaBean)3 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1