Search in sources :

Example 11 with SampleEventListener

use of org.motechproject.event.listener.SampleEventListener in project motech by motech.

the class EventListenerRegistryTest method testHasListener_YesWildcard.

@Test
public void testHasListener_YesWildcard() {
    registry.registerListener(new SampleEventListener(), "org.motechproject.server.*");
    assertTrue(registry.hasListener("org.motechproject.server.someevent"));
}
Also used : OtherSampleEventListener(org.motechproject.event.listener.OtherSampleEventListener) SampleEventListener(org.motechproject.event.listener.SampleEventListener) Test(org.junit.Test)

Example 12 with SampleEventListener

use of org.motechproject.event.listener.SampleEventListener in project motech by motech.

the class EventListenerRegistryTest method testHasListener_No.

@Test
public void testHasListener_No() {
    registry.registerListener(new SampleEventListener(), "org.motechproject.server.someevent");
    assertFalse(registry.hasListener("org.motechproject.client.otherevent"));
}
Also used : OtherSampleEventListener(org.motechproject.event.listener.OtherSampleEventListener) SampleEventListener(org.motechproject.event.listener.SampleEventListener) Test(org.junit.Test)

Example 13 with SampleEventListener

use of org.motechproject.event.listener.SampleEventListener in project motech by motech.

the class EventListenerRegistryTest method testRegisterForMultipleEvents.

@Test
public void testRegisterForMultipleEvents() {
    List<String> et = new ArrayList<String>();
    et.add("org.motechproject.server.someevent");
    et.add("org.motechproject.server.someotherevent");
    EventListener sel = new SampleEventListener();
    registry.registerListener(sel, et);
    Set<EventListener> el = registry.getListeners(et.get(0));
    assertNotNull(el);
    assertTrue(el.size() == 1);
    assertTrue(el.contains(sel));
    el = registry.getListeners(et.get(1));
    assertNotNull(el);
    assertTrue(el.size() == 1);
    assertTrue(el.contains(sel));
}
Also used : ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) OtherSampleEventListener(org.motechproject.event.listener.OtherSampleEventListener) EventListener(org.motechproject.event.listener.EventListener) SampleEventListener(org.motechproject.event.listener.SampleEventListener) OtherSampleEventListener(org.motechproject.event.listener.OtherSampleEventListener) SampleEventListener(org.motechproject.event.listener.SampleEventListener) Test(org.junit.Test)

Example 14 with SampleEventListener

use of org.motechproject.event.listener.SampleEventListener in project motech by motech.

the class EventListenerRegistryTest method testRemovingListenerPreservesOtherListeners.

@Test
public void testRemovingListenerPreservesOtherListeners() {
    List<String> et = new ArrayList<String>();
    et.add("org.motechproject.server.someevent");
    EventListener sel = new SampleEventListener();
    EventListener se2 = new OtherSampleEventListener();
    registry.registerListener(sel, et);
    registry.registerListener(se2, et);
    Set<EventListener> el = registry.getListeners("org.motechproject.server.someevent");
    assertEquals(2, el.size());
    registry.clearListenersForBean("TestEventListener");
    el = registry.getListeners("org.motechproject.server.someevent");
    assertEquals(1, el.size());
    registry.clearListenersForBean("TestEventListener2");
    el = registry.getListeners("org.motechproject.server.someevent");
    assertEquals(0, el.size());
}
Also used : OtherSampleEventListener(org.motechproject.event.listener.OtherSampleEventListener) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) OtherSampleEventListener(org.motechproject.event.listener.OtherSampleEventListener) EventListener(org.motechproject.event.listener.EventListener) SampleEventListener(org.motechproject.event.listener.SampleEventListener) OtherSampleEventListener(org.motechproject.event.listener.OtherSampleEventListener) SampleEventListener(org.motechproject.event.listener.SampleEventListener) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 SampleEventListener (org.motechproject.event.listener.SampleEventListener)14 OtherSampleEventListener (org.motechproject.event.listener.OtherSampleEventListener)13 EventListener (org.motechproject.event.listener.EventListener)11 ArrayList (java.util.ArrayList)7 Matchers.anyString (org.mockito.Matchers.anyString)7 EventListenerTree (org.motechproject.event.listener.impl.EventListenerTree)1