@Test
  public void testEventInterfaceHierarchy() {
    eventBus.register(this);

    eventBus.post(new MyEvent());
    assertEquals(0, countMyEventInterface);

    eventBus.post(new MyEventExtended());
    assertEquals(0, countMyEventInterface);
    assertEquals(0, countMyEventInterfaceExtended);
  }
  @Test
  public void testEventClassHierarchy() {
    eventBus.register(this);

    eventBus.post("Hello");
    assertEquals(0, countObjectEvent);

    eventBus.post(new MyEvent());
    assertEquals(0, countObjectEvent);
    assertEquals(1, countMyEvent);

    eventBus.post(new MyEventExtended());
    assertEquals(0, countObjectEvent);
    assertEquals(1, countMyEvent);
    assertEquals(1, countMyEventExtended);
  }
  @Test
  public void testSubscriberClassHierarchyWithoutNewSubscriberMethod() {
    SubscriberExtendedWithoutNewSubscriberMethod subscriber =
        new SubscriberExtendedWithoutNewSubscriberMethod();
    eventBus.register(subscriber);

    eventBus.post("Hello");
    assertEquals(0, subscriber.countObjectEvent);

    eventBus.post(new MyEvent());
    assertEquals(0, subscriber.countObjectEvent);
    assertEquals(1, subscriber.countMyEvent);

    eventBus.post(new MyEventExtended());
    assertEquals(0, subscriber.countObjectEvent);
    assertEquals(1, subscriber.countMyEvent);
    assertEquals(1, subscriber.countMyEventExtended);
  }
Ejemplo n.º 4
0
  public void testNoReentrantEvents() {
    ReentrantEventsHater hater = new ReentrantEventsHater();
    bus.register(hater);

    bus.post(FIRST);

    assertEquals(
        "ReentrantEventHater expected 2 events",
        Lists.<Object>newArrayList(FIRST, SECOND),
        hater.eventsReceived);
  }
Ejemplo n.º 5
0
  public void testEventOrderingIsPredictable() {
    EventProcessor processor = new EventProcessor();
    bus.register(processor);

    EventRecorder recorder = new EventRecorder();
    bus.register(recorder);

    bus.post(FIRST);

    assertEquals(
        "EventRecorder expected events in order",
        Lists.<Object>newArrayList(FIRST, SECOND),
        recorder.eventsReceived);
  }