File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
data-bus/src/test/java/com/iluwatar/databus Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .iluwatar .databus ;
2+
3+ import org .junit .Before ;
4+ import org .junit .Test ;
5+ import org .mockito .Mock ;
6+ import org .mockito .MockitoAnnotations ;
7+
8+ import static org .mockito .BDDMockito .then ;
9+ import static org .mockito .Mockito .never ;
10+
11+ /**
12+ * Tests for {@link DataBus}.
13+ *
14+ * @author Paul Campbell (pcampbell@kemitix.net)
15+ */
16+ public class DataBusTest {
17+
18+ @ Mock
19+ private Member member ;
20+
21+ @ Mock
22+ private DataType event ;
23+
24+ @ Before
25+ public void setUp () {
26+ MockitoAnnotations .initMocks (this );
27+ }
28+
29+ @ Test
30+ public void publishedEventIsReceivedBySubscribedMember () {
31+ //given
32+ final DataBus dataBus = DataBus .getInstance ();
33+ dataBus .subscribe (member );
34+ //when
35+ dataBus .publish (event );
36+ //then
37+ then (member ).should ().accept (event );
38+ }
39+
40+ @ Test
41+ public void publishedEventIsNotReceivedByMemberAfterUnsubscribing () {
42+ //given
43+ final DataBus dataBus = DataBus .getInstance ();
44+ dataBus .subscribe (member );
45+ dataBus .unsubscribe (member );
46+ //when
47+ dataBus .publish (event );
48+ //then
49+ then (member ).should (never ()).accept (event );
50+ }
51+
52+ }
You can’t perform that action at this time.
0 commit comments