@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);
  }
  @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");
  }
  @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());
  }
  @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);
  }
 @Test(expected = UnsupportedOperationException.class)
 public void testPublishToInvalidScope() {
   applicationEventBus.publish(EventScope.SESSION, this, "fail");
 }
 @After
 public void tearDown() {
   sessionEventBus.destroy();
   applicationEventBus.destroy();
 }