Code example for EventBus

Methods: registersleep

0
 * Time: 5:53 PM 
 */ 
public class EventCoalescorTest { 
    @Test
    public void should_coalesce() throws Exception {
        EventBus eventBus = new EventBus();
        final List<String> messages = new ArrayList<>();
 
        eventBus.register(new Object() {
            @Subscribe 
            public void onMessage(String msg) { 
                messages.add(msg); 
            } 
        }); 
 
        EventCoalescor coalescor = new EventCoalescor(eventBus, 30);
 
        coalescor.post("test1");
        coalescor.post("test2");
        coalescor.post("test1");
        coalescor.post("test3");
 
        Thread.sleep(40);
 
        assertThat(messages).containsExactly("test1", "test2", "test3");
 
        messages.clear();
        coalescor.post("test2");
        coalescor.post("test1");
        coalescor.post("test1");
        coalescor.post("test1");
        coalescor.post("test1");
        Thread.sleep(40);
 
        assertThat(messages).containsExactly("test2", "test1");
    } 
}