@Test public void testAddEventListenerWithPrivateAddMethod() { final PropertyChangeSource src = new PropertyChangeSource(); final EventCountingInvociationHandler handler = new EventCountingInvociationHandler(); final VetoableChangeListener listener = handler.createListener(VetoableChangeListener.class); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Class " + src.getClass().getName() + " does not have a public add" + VetoableChangeListener.class.getSimpleName() + " method which takes a parameter of type " + VetoableChangeListener.class.getName() + "."); EventUtils.addEventListener(src, VetoableChangeListener.class, listener); }
@Test public void testAddEventListenerWithNoAddMethod() { final PropertyChangeSource src = new PropertyChangeSource(); final EventCountingInvociationHandler handler = new EventCountingInvociationHandler(); final ObjectChangeListener listener = handler.createListener(ObjectChangeListener.class); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Class " + src.getClass().getName() + " does not have a public add" + ObjectChangeListener.class.getSimpleName() + " method which takes a parameter of type " + ObjectChangeListener.class.getName() + "."); EventUtils.addEventListener(src, ObjectChangeListener.class, listener); }
@Test public void testAddEventListener() { final PropertyChangeSource src = new PropertyChangeSource(); final EventCountingInvociationHandler handler = new EventCountingInvociationHandler(); final PropertyChangeListener listener = handler.createListener(PropertyChangeListener.class); assertEquals(0, handler.getEventCount("propertyChange")); EventUtils.addEventListener(src, PropertyChangeListener.class, listener); assertEquals(0, handler.getEventCount("propertyChange")); src.setProperty("newValue"); assertEquals(1, handler.getEventCount("propertyChange")); }