Search in sources :

Example 6 with SampleEventListener

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

the class EventListenerRegistryTest method testEmptyEventListRegistration.

@Test
public void testEmptyEventListRegistration() throws NoSuchFieldException {
    List<String> subjects = new ArrayList<String>();
    EventListener sel = new SampleEventListener();
    EventListenerTree mockTree = mock(EventListenerTree.class);
    PrivateAccessor.setField(registry, "listenerTree", mockTree);
    registry.registerListener(sel, subjects);
    verify(mockTree, times(0)).addListener(Matchers.<EventListener>anyObject(), anyString());
}
Also used : EventListenerTree(org.motechproject.event.listener.impl.EventListenerTree) 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 7 with SampleEventListener

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

the class EventListenerRegistryTest method testRegisterSingleListener.

@Test
public void testRegisterSingleListener() {
    EventListener sel = new SampleEventListener();
    registry.registerListener(sel, "org.motechproject.server.someevent");
    Set<EventListener> listeners = registry.getListeners("org.motechproject.server.someevent");
    assertNotNull(listeners);
    assertTrue(listeners.size() == 1);
    assertEquals(listeners.iterator().next(), sel);
}
Also used : 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 8 with SampleEventListener

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

the class EventListenerRegistryTest method testRegisterTwice.

@Test
public void testRegisterTwice() {
    EventListener sel = new SampleEventListener();
    registry.registerListener(sel, "org.motechproject.server.someevent");
    registry.registerListener(sel, "org.motechproject.server.someevent");
    Set<EventListener> el = registry.getListeners("org.motechproject.server.someevent");
    assertNotNull(el);
    assertTrue(el.size() == 1);
    assertTrue(el.contains(sel));
}
Also used : 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 9 with SampleEventListener

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

the class EventListenerTreeTest method testAddListener_UniversalListener.

@Test
public void testAddListener_UniversalListener() {
    EventListener listener1 = new SampleEventListener();
    EventListener listener2 = new SampleEventListener();
    tree.addListener(listener1, "*");
    tree.addListener(listener2, "org.test");
    Set<EventListener> listeners = tree.getListeners("*");
    assertTrue(listeners.size() == 1);
    assertTrue(listeners.contains(listener1));
    listeners = tree.getListeners("org.test");
    assertTrue(listeners.size() == 2);
    assertTrue(listeners.contains(listener1));
    assertTrue(listeners.contains(listener2));
    listeners = tree.getListeners("com.pqr.xyz");
    assertTrue(listeners.size() == 1);
    assertTrue(listeners.contains(listener1));
}
Also used : EventListener(org.motechproject.event.listener.EventListener) SampleEventListener(org.motechproject.event.listener.SampleEventListener) SampleEventListener(org.motechproject.event.listener.SampleEventListener) Test(org.junit.Test)

Example 10 with SampleEventListener

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

the class EventListenerRegistryTest method testGetListeners.

@Test
public void testGetListeners() {
    List<String> et = new ArrayList<String>();
    et.add("org.motechproject.server.someevent");
    EventListener sel = new SampleEventListener();
    registry.registerListener(sel, et);
    Set<EventListener> el = registry.getListeners("org.motechproject.server.someevent");
    assertNotNull(el);
    assertEquals(1, el.size());
    assertEquals(el.iterator().next(), 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)

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