@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());
  }
Test case for subscribers which unregister while handling an event.
otto/src/test/java/com/squareup/otto/UnregisteringHandlerTest.java