Пример #1
0
  @Test
  public void unregisterInHandler() {
    UnregisteringStringCatcher catcher = new UnregisteringStringCatcher(bus);
    bus.register(catcher);
    bus.post(EVENT);

    assertEquals(
        "One correct event should be delivered.", Arrays.asList(EVENT), catcher.getEvents());

    bus.post(EVENT);
    bus.post(EVENT);
    assertEquals(
        "Shouldn't catch any more events when unregistered.",
        Arrays.asList(EVENT),
        catcher.getEvents());
  }
Пример #2
0
  @Test
  public void unregisterInHandlerWhenEventProduced() throws Exception {
    UnregisteringStringCatcher catcher = new UnregisteringStringCatcher(bus);

    bus.register(new StringProducer());
    bus.register(catcher);
    assertEquals(Arrays.asList(StringProducer.VALUE), catcher.getEvents());

    bus.post(EVENT);
    bus.post(EVENT);
    assertEquals(
        "Shouldn't catch any more events when unregistered.",
        Arrays.asList(StringProducer.VALUE),
        catcher.getEvents());
  }