Code example for EventBus

Methods: postregister

0
 
    @Test
    public void shouldReceiveMultipleEventTypesFromBus() throws Exception {
 
        // given 
        EventBus eventBus = new EventBus("test");
        EventListener listener = new EventListener(); 
        EventReader reader = new EventReader();
        StringEventListener stringEventListener = new StringEventListener();
 
        eventBus.register(listener);
        eventBus.register(reader);
        eventBus.register(stringEventListener);
 
        // when 
        eventBus.post(new OurTestEvent(200));
        eventBus.post(new StringTestEvent("Hello events!"));
 
 
        // then 
        assertThat(reader.getLastMessage()).isEqualTo(200);
        assertThat(listener.getLastMessage()).isEqualTo(200);