コード例 #1
0
  @Test
  public void testSubscribeWithWeakReference() {
    StringListener listener =
        new StringListener() {
          int cnt = 0;

          @Override
          public void onEvent(Event<String> event) {
            cnt++;
            if (cnt > 1) {
              fail("I should have been garbage collected by now");
            }
          }
        };
    applicationEventBus.subscribeWithWeakReference(listener);
    applicationEventBus.publish(this, "Hello World Application");
    listener = null;
    System.gc();
    applicationEventBus.publish(this, "Hello World Application");
  }
コード例 #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 testPropagateToChildWithListenerMethods() {
    MultipleListeners listener = new MultipleListeners();

    applicationEventBus.subscribe(listener);
    applicationEventBus.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(expected = UnsupportedOperationException.class)
 public void testPublishToInvalidScope() {
   applicationEventBus.publish(EventScope.SESSION, this, "fail");
 }