Search in sources :

Example 16 with EventSetDescriptor

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

the class EventSetDescriptorTest method testSetUnicast_false.

public void testSetUnicast_false() 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);
    assertFalse(esd.isUnicast());
    esd.setInDefaultEventSet(false);
    assertFalse(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 17 with EventSetDescriptor

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

the class EventSetDescriptorTest method test_EventSetDescriptor_Constructor.

public void test_EventSetDescriptor_Constructor() throws Exception {
    EventSetDescriptor eventSetDescriptor = new EventSetDescriptor((String) null, (Class<?>) null, new MethodDescriptor[] { null, null }, (Method) null, (Method) null);
    assertNull(eventSetDescriptor.getName());
    assertNull(eventSetDescriptor.getListenerType());
    assertNull(eventSetDescriptor.getAddListenerMethod());
    assertNull(eventSetDescriptor.getRemoveListenerMethod());
    try {
        eventSetDescriptor.getListenerMethods();
        fail("should throw NullPointerException");
    } catch (NullPointerException e) {
    // Expected
    }
}
Also used : EventSetDescriptor(java.beans.EventSetDescriptor)

Example 18 with EventSetDescriptor

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

the class IntrospectorTest method testUnicastEventSetDescriptor.

/**
     * The test checks the getEventSetDescriptors method
     *
     * @throws IntrospectionException
     */
public void testUnicastEventSetDescriptor() throws IntrospectionException {
    BeanInfo info = Introspector.getBeanInfo(SampleBean.class);
    assertNotNull(info);
    EventSetDescriptor[] descriptors = info.getEventSetDescriptors();
    assertNotNull(descriptors);
    for (EventSetDescriptor descriptor : descriptors) {
        Method m = descriptor.getAddListenerMethod();
        if (m != null) {
            Class<?>[] exceptionTypes = m.getExceptionTypes();
            boolean found = false;
            for (Class<?> et : exceptionTypes) {
                if (et.equals(TooManyListenersException.class)) {
                    assertTrue(descriptor.isUnicast());
                    found = true;
                    break;
                }
            }
            if (!found) {
                assertFalse(descriptor.isUnicast());
            }
        }
    }
}
Also used : 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) Method(java.lang.reflect.Method) EventSetDescriptor(java.beans.EventSetDescriptor)

Example 19 with EventSetDescriptor

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

the class IntrospectorTest method testGetBeanInfoClassint_IGNORE_ALL_Event.

/*
     * FLAG=IGNORE_ALL_BEANINFO;
     */
public void testGetBeanInfoClassint_IGNORE_ALL_Event() throws IntrospectionException {
    BeanInfo info = Introspector.getBeanInfo(MockFooSub.class, Introspector.IGNORE_ALL_BEANINFO);
    EventSetDescriptor[] esds = info.getEventSetDescriptors();
    assertEquals(1, esds.length);
    assertTrue(contains("mockPropertyChange", esds));
}
Also used : BeanInfo(java.beans.BeanInfo) SimpleBeanInfo(java.beans.SimpleBeanInfo) FakeFox01BeanInfo(org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo) EventSetDescriptor(java.beans.EventSetDescriptor)

Example 20 with EventSetDescriptor

use of java.beans.EventSetDescriptor in project groovy by apache.

the class StrangeBeanBeanInfo method getEventSetDescriptors.

public EventSetDescriptor[] getEventSetDescriptors() {
    try {
        Method[] events = StrangeEventListener.class.getMethods();
        Method addListener = StrangeBean.class.getMethod("addStrangeEventListener", new Class[] { StrangeEventListener.class });
        Method removeListener = StrangeBean.class.getMethod("removeStrangeEventListener", new Class[] { StrangeEventListener.class });
        Method getListeners = StrangeBean.class.getMethod("getStrangeEventListeners", new Class[0]);
        return new EventSetDescriptor[] { new EventSetDescriptor("strangeEvent", StrangeEventListener.class, events, addListener, removeListener, getListeners) };
    } catch (Exception e) {
        e.printStackTrace(System.out);
        return super.getEventSetDescriptors();
    }
}
Also used : Method(java.lang.reflect.Method) EventSetDescriptor(java.beans.EventSetDescriptor)

Aggregations

EventSetDescriptor (java.beans.EventSetDescriptor)55 Method (java.lang.reflect.Method)34 MockPropertyChangeListener (org.apache.harmony.beans.tests.support.mock.MockPropertyChangeListener)31 BeanInfo (java.beans.BeanInfo)10 MethodDescriptor (java.beans.MethodDescriptor)10 IntrospectionException (java.beans.IntrospectionException)9 PropertyDescriptor (java.beans.PropertyDescriptor)6 MockPropertyChangeEvent (org.apache.harmony.beans.tests.support.mock.MockPropertyChangeEvent)6 SimpleBeanInfo (java.beans.SimpleBeanInfo)5 FakeFox01BeanInfo (org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo)5 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)3 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)2 BeanDescriptor (java.beans.BeanDescriptor)2 PrivilegedActionException (java.security.PrivilegedActionException)2 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)2 CachedMethod (org.codehaus.groovy.reflection.CachedMethod)2 GeneratedMetaMethod (org.codehaus.groovy.reflection.GeneratedMetaMethod)2 ClosureMetaMethod (org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod)2 MixinInstanceMetaMethod (org.codehaus.groovy.runtime.metaclass.MixinInstanceMetaMethod)2 NewInstanceMetaMethod (org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod)2