|
1 | 1 | package org.baeldung.guava; |
2 | 2 |
|
| 3 | +import com.google.common.eventbus.EventBus; |
3 | 4 | import org.junit.After; |
4 | 5 | import org.junit.Before; |
5 | 6 | import org.junit.Test; |
|
9 | 10 | public class GuavaEventBusTest { |
10 | 11 |
|
11 | 12 | private EventListener listener; |
| 13 | + private EventBus eventBus; |
12 | 14 |
|
13 | 15 | @Before |
14 | 16 | public void setUp() { |
| 17 | + eventBus = new EventBus(); |
15 | 18 | listener = new EventListener(); |
16 | | - EventBusWrapper.register(listener); |
| 19 | + |
| 20 | + eventBus.register(listener); |
17 | 21 | } |
18 | 22 |
|
19 | 23 | @After |
20 | 24 | public void tearDown() { |
21 | | - EventBusWrapper.unregister(listener); |
| 25 | + eventBus.unregister(listener); |
22 | 26 | } |
23 | 27 |
|
24 | 28 | @Test |
25 | 29 | public void givenStringEvent_whenEventHandled_thenSuccess() { |
26 | 30 | listener.resetEventsHandled(); |
27 | 31 |
|
28 | | - EventBusWrapper.post("String Event"); |
| 32 | + eventBus.post("String Event"); |
29 | 33 | assertEquals(1, listener.getEventsHandled()); |
30 | | - |
31 | 34 | } |
32 | 35 |
|
33 | 36 | @Test |
34 | 37 | public void givenCustomEvent_whenEventHandled_thenSuccess() { |
35 | 38 | listener.resetEventsHandled(); |
36 | 39 |
|
37 | 40 | CustomEvent customEvent = new CustomEvent("Custom Event"); |
38 | | - EventBusWrapper.post(customEvent); |
| 41 | + eventBus.post(customEvent); |
39 | 42 |
|
40 | 43 | assertEquals(1, listener.getEventsHandled()); |
41 | 44 | } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void givenUnSubscribedEvent_whenEventHandledByDeadEvent_thenSuccess() { |
| 48 | + listener.resetEventsHandled(); |
| 49 | + |
| 50 | + eventBus.post(12345); |
| 51 | + assertEquals(1, listener.getEventsHandled()); |
| 52 | + } |
| 53 | + |
42 | 54 | } |
0 commit comments