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;
|
package org.baeldung.guava;
|
||||||
|
|
||||||
|
import com.google.common.eventbus.EventBus;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -9,25 +10,27 @@ import static org.junit.Assert.*;
|
|||||||
public class GuavaEventBusTest {
|
public class GuavaEventBusTest {
|
||||||
|
|
||||||
private EventListener listener;
|
private EventListener listener;
|
||||||
|
private EventBus eventBus;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
eventBus = new EventBus();
|
||||||
listener = new EventListener();
|
listener = new EventListener();
|
||||||
EventBusWrapper.register(listener);
|
|
||||||
|
eventBus.register(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
EventBusWrapper.unregister(listener);
|
eventBus.unregister(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenStringEvent_whenEventHandled_thenSuccess() {
|
public void givenStringEvent_whenEventHandled_thenSuccess() {
|
||||||
listener.resetEventsHandled();
|
listener.resetEventsHandled();
|
||||||
|
|
||||||
EventBusWrapper.post("String Event");
|
eventBus.post("String Event");
|
||||||
assertEquals(1, listener.getEventsHandled());
|
assertEquals(1, listener.getEventsHandled());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -35,8 +38,17 @@ public class GuavaEventBusTest {
|
|||||||
listener.resetEventsHandled();
|
listener.resetEventsHandled();
|
||||||
|
|
||||||
CustomEvent customEvent = new CustomEvent("Custom Event");
|
CustomEvent customEvent = new CustomEvent("Custom Event");
|
||||||
EventBusWrapper.post(customEvent);
|
eventBus.post(customEvent);
|
||||||
|
|
||||||
assertEquals(1, listener.getEventsHandled());
|
assertEquals(1, listener.getEventsHandled());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenUnSubscribedEvent_whenEventHandledByDeadEvent_thenSuccess() {
|
||||||
|
listener.resetEventsHandled();
|
||||||
|
|
||||||
|
eventBus.post(12345);
|
||||||
|
assertEquals(1, listener.getEventsHandled());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user