public void testRemoveTripletErrors()
throws Exception
{
NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport();
Object handback = new Object();
NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(DEFAULT_TYPE);
Listener listener = new Listener();
boolean caught = false;
try
{
broadcaster.removeNotificationListener(null, null, null);
}
catch (ListenerNotFoundException e)
{
caught = true;
}
assertTrue("Expected ListenerNotFoundException for null listener", caught);
caught = false;
try
{
broadcaster.removeNotificationListener(listener, null, null);
}
catch (ListenerNotFoundException e)
{
caught = true;
}
assertTrue("Expected ListenerNotFoundException for listener never added", caught);
caught = false;
try
{
broadcaster.addNotificationListener(listener, null, null);
broadcaster.removeNotificationListener(listener, null, null);
broadcaster.removeNotificationListener(listener, null, null);
}
catch (ListenerNotFoundException e)
{
caught = true;
}
assertTrue("Expected ListenerNotFoundException for listener remove twice", caught);
caught = false;
try
{
broadcaster.addNotificationListener(listener, filter, null);
broadcaster.removeNotificationListener(listener, new NotificationFilterSupport(), null);
}
catch (ListenerNotFoundException e)
{
caught = true;
broadcaster.removeNotificationListener(listener, filter, null);
}
assertTrue("Expected ListenerNotFoundException for wrong filter", caught);
caught = false;
try
{
broadcaster.addNotificationListener(listener, null, handback);
broadcaster.removeNotificationListener(listener, null, new Object());
}
catch (ListenerNotFoundException e)
{
caught = true;
broadcaster.removeNotificationListener(listener, null, handback);
}
assertTrue("Expected ListenerNotFoundException for wrong handback", caught);
caught = false;
try
{
broadcaster.addNotificationListener(listener, filter, handback);
broadcaster.removeNotificationListener(listener, new NotificationFilterSupport(), new Object());
}
catch (ListenerNotFoundException e)
{
caught = true;
broadcaster.removeNotificationListener(listener, filter, handback);