BAEL-639: Guide to Guava's EventBus Tests - removed EventWrapper and added DeadEvent Subscriber
This commit is contained in:
parent
746ed952db
commit
9135c6073e
|
@ -1,5 +1,6 @@
|
|||
package org.baeldung.guava;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -9,25 +10,27 @@ import static org.junit.Assert.*;
|
|||
public class GuavaEventBusTest {
|
||||
|
||||
private EventListener listener;
|
||||
private EventBus eventBus;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
eventBus = new EventBus();
|
||||
listener = new EventListener();
|
||||
EventBusWrapper.register(listener);
|
||||
|
||||
eventBus.register(listener);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
EventBusWrapper.unregister(listener);
|
||||
eventBus.unregister(listener);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStringEvent_whenEventHandled_thenSuccess() {
|
||||
listener.resetEventsHandled();
|
||||
|
||||
EventBusWrapper.post("String Event");
|
||||
eventBus.post("String Event");
|
||||
assertEquals(1, listener.getEventsHandled());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -35,8 +38,17 @@ public class GuavaEventBusTest {
|
|||
listener.resetEventsHandled();
|
||||
|
||||
CustomEvent customEvent = new CustomEvent("Custom Event");
|
||||
EventBusWrapper.post(customEvent);
|
||||
eventBus.post(customEvent);
|
||||
|
||||
assertEquals(1, listener.getEventsHandled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenUnSubscribedEvent_whenEventHandledByDeadEvent_thenSuccess() {
|
||||
listener.resetEventsHandled();
|
||||
|
||||
eventBus.post(12345);
|
||||
assertEquals(1, listener.getEventsHandled());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue