Ejemplo n.º 1
0
  @Test
  public void testSubscribeAndPublishWithListenerMethodsWithTopic() {
    MultipleListeners listener = new MultipleListeners();

    sessionEventBus.subscribe(listener);
    sessionEventBus.publish("shouldSucceed", this, "Hello World");
    sessionEventBus.publish("shouldSucceed.int", this, 10);

    // null because not called with topic
    assertNull(listener.theStringPayload);
    assertNull(listener.theStringEvent);
    assertNull(listener.theIntegerPayload);
    assertNull(listener.theIntegerEvent);

    // null because topic must fail
    assertNull(listener.theStringPayloadWithTopicFail);
    assertNull(listener.theIntegerPayloadWithTopicFail);
    assertNull(listener.theIntegerEventWithTopic);

    assertNotNull(listener.theStringPayloadWithTopic);
    assertNotNull(listener.theStringEventWithTopic);

    assertEquals("Hello World", listener.theStringPayloadWithTopic);
    assertEquals("Hello World", listener.theStringEventWithTopic.getPayload());
    assertEquals(10, listener.theIntegerPayloadWithTopic.intValue());
  }
Ejemplo n.º 2
0
  @Test
  @SuppressWarnings({"unchecked", "rawtypes"})
  public void testSubscribeAndPublish() {
    StringListener stringListener = mock(StringListener.class);

    sessionEventBus.subscribe(stringListener);
    sessionEventBus.publish(this, "Hello World");

    ArgumentCaptor<Event> event = ArgumentCaptor.forClass(Event.class);
    verify(stringListener).onEvent(event.capture());
    assertEquals("Hello World", event.getValue().getPayload());
  }
Ejemplo n.º 3
0
  @Test
  public void testSubscribeAndPublishWithListenerMethods() {
    MultipleListeners listener = new MultipleListeners();

    sessionEventBus.subscribe(listener);
    sessionEventBus.publish(this, "Hello World");

    assertNull(listener.theIntegerEvent);
    assertNull(listener.theIntegerPayload);
    assertNotNull(listener.theStringEvent);
    assertEquals("Hello World", listener.theStringEvent.getPayload());
    assertEquals("Hello World", listener.theStringPayload);
  }
Ejemplo n.º 4
0
  @Test
  public void testNoPropagationToChildWithListenerMethods() {
    MultipleListeners listener = new MultipleListeners();

    sessionEventBus.subscribe(listener, false);
    sessionEventBus.publish(this, "Hello World Session");
    applicationEventBus.publish(this, "Hello World Application");

    assertNull(listener.theIntegerEvent);
    assertNull(listener.theIntegerPayload);
    assertNotNull(listener.theStringEvent);
    assertEquals("Hello World Session", listener.theStringEvent.getPayload());
    assertEquals("Hello World Session", listener.theStringPayload);
  }
Ejemplo n.º 5
0
  @Test
  @SuppressWarnings({"unchecked", "rawtypes"})
  public void testNoPropagationToChild() {
    StringListener stringListener = mock(StringListener.class);

    sessionEventBus.subscribe(stringListener, false);
    applicationEventBus.publish(this, "Hello World");
    sessionEventBus.publish(this, "Hello World");

    ArgumentCaptor<Event> event = ArgumentCaptor.forClass(Event.class);
    verify(stringListener, only()).onEvent(event.capture());
    verifyNoMoreInteractions(stringListener);
    assertEquals("Hello World", event.getValue().getPayload());
  }
Ejemplo n.º 6
0
  @Test
  public void testPublishToParentScopeWithListenerMethods() {
    MultipleListeners listener = new MultipleListeners();

    applicationEventBus.subscribe(listener);
    sessionEventBus.publish(EventScope.APPLICATION, this, "Hello World");

    assertNull(listener.theIntegerEvent);
    assertNull(listener.theIntegerPayload);
    assertNotNull(listener.theStringEvent);
    assertEquals("Hello World", listener.theStringEvent.getPayload());
    assertEquals("Hello World", listener.theStringPayload);
  }
Ejemplo n.º 7
0
 @Test(expected = IllegalArgumentException.class)
 public void testSubscribeAndPublishWithListenerMethodsAndTooManyParameters() {
   sessionEventBus.subscribe(new InvalidListener2());
 }
Ejemplo n.º 8
0
 @After
 public void tearDown() {
   sessionEventBus.destroy();
   applicationEventBus.destroy();
 }