Code example for EventBus

Methods: postregister

0
   * it can fail here. 
   */ 
  public void testAnonymous() { 
    final AtomicReference<String> holder = new AtomicReference<String>();
    final AtomicInteger deliveries = new AtomicInteger();
    EventBus bus = new EventBus();
    bus.register(new Object() {
      @Subscribe 
      public void accept(String str) { 
        holder.set(str); 
        deliveries.incrementAndGet(); 
      } 
    }); 
 
    String EVENT = "Hello!";
    bus.post(EVENT);
 
    assertEquals("Only one event should be delivered.", 1, deliveries.get());
    assertEquals("Correct string should be delivered.", EVENT, holder.get());
  } 
}