コード例 #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());
  }
コード例 #2
0
  @Test
  @SuppressWarnings({"unchecked", "rawtypes"})
  public void testPropagateToChild() {
    StringListener stringListener = mock(StringListener.class);

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

    ArgumentCaptor<Event> event = ArgumentCaptor.forClass(Event.class);
    verify(stringListener).onEvent(event.capture());
    assertEquals("Hello World", event.getValue().getPayload());
  }
コード例 #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);
  }
コード例 #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);
  }
コード例 #5
0
 @Test(expected = IllegalArgumentException.class)
 public void testSubscribeAndPublishWithListenerMethodsAndTooManyParameters() {
   sessionEventBus.subscribe(new InvalidListener2());
 }