Exemplo n.º 1
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);
  }
Exemplo n.º 2
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");
  }
Exemplo n.º 3
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());
  }
Exemplo n.º 4
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);
  }
Exemplo n.º 5
0
 @Test(expected = UnsupportedOperationException.class)
 public void testPublishToInvalidScope() {
   applicationEventBus.publish(EventScope.SESSION, this, "fail");
 }
Exemplo n.º 6
0
 @After
 public void tearDown() {
   sessionEventBus.destroy();
   applicationEventBus.destroy();
 }