下面列出了怎么用javax.naming.event.ObjectChangeListener的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void testAddEventListenerWithNoAddMethod()
{
final PropertyChangeSource src = new PropertyChangeSource();
EventCountingInvociationHandler handler = new EventCountingInvociationHandler();
ObjectChangeListener listener = handler.createListener(ObjectChangeListener.class);
try
{
EventUtils.addEventListener(src, ObjectChangeListener.class, listener);
fail("Should not be allowed to add a listener to an object that doesn't support it.");
}
catch (IllegalArgumentException e)
{
assertEquals("Class " + src.getClass().getName() + " does not have a public add" + ObjectChangeListener.class.getSimpleName() + " method which takes a parameter of type " + ObjectChangeListener.class.getName() + ".", e.getMessage());
}
}
@Test
public void testAddEventListenerWithNoAddMethod()
{
final PropertyChangeSource src = new PropertyChangeSource();
final EventCountingInvociationHandler handler = new EventCountingInvociationHandler();
final ObjectChangeListener listener = handler.createListener(ObjectChangeListener.class);
try
{
EventUtils.addEventListener(src, ObjectChangeListener.class, listener);
fail("Should not be allowed to add a listener to an object that doesn't support it.");
}
catch (final IllegalArgumentException e)
{
assertEquals("Class " + src.getClass().getName() + " does not have a public add" + ObjectChangeListener.class.getSimpleName() + " method which takes a parameter of type " + ObjectChangeListener.class.getName() + ".", e.getMessage());
}
}
@Test
public void testAddEventListenerWithNoAddMethod()
{
final PropertyChangeSource src = new PropertyChangeSource();
EventCountingInvociationHandler handler = new EventCountingInvociationHandler();
ObjectChangeListener listener = handler.createListener(ObjectChangeListener.class);
try
{
EventUtils.addEventListener(src, ObjectChangeListener.class, listener);
fail("Should not be allowed to add a listener to an object that doesn't support it.");
}
catch (IllegalArgumentException e)
{
assertEquals("Class " + src.getClass().getName() + " does not have a public add" + ObjectChangeListener.class.getSimpleName() + " method which takes a parameter of type " + ObjectChangeListener.class.getName() + ".", e.getMessage());
}
}
public void testAddEventListenerWithNoAddMethod()
{
final PropertyChangeSource src = new PropertyChangeSource();
EventCountingInvociationHandler handler = new EventCountingInvociationHandler();
ObjectChangeListener listener = handler.createListener(ObjectChangeListener.class);
try
{
EventUtils.addEventListener(src, ObjectChangeListener.class, listener);
fail("Should not be allowed to add a listener to an object that doesn't support it.");
}
catch (IllegalArgumentException e)
{
assertEquals("Class " + src.getClass().getName() + " does not have a public add" + ObjectChangeListener.class.getSimpleName() + " method which takes a parameter of type " + ObjectChangeListener.class.getName() + ".", e.getMessage());
}
}