1 | package geniusweb.party;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertNotNull;
|
---|
4 | import static org.junit.Assert.assertNull;
|
---|
5 | import static org.mockito.Matchers.any;
|
---|
6 | import static org.mockito.Mockito.mock;
|
---|
7 | import static org.mockito.Mockito.times;
|
---|
8 | import static org.mockito.Mockito.verify;
|
---|
9 |
|
---|
10 | import org.junit.Before;
|
---|
11 | import org.junit.Test;
|
---|
12 |
|
---|
13 | import geniusweb.actions.Action;
|
---|
14 | import geniusweb.connection.ConnectionEnd;
|
---|
15 | import geniusweb.inform.Inform;
|
---|
16 | import tudelft.utilities.listener.Listener;
|
---|
17 |
|
---|
18 | public class DefaultPartyTest {
|
---|
19 |
|
---|
20 | private DefaultParty party;
|
---|
21 |
|
---|
22 | @Before
|
---|
23 | public void before() {
|
---|
24 | party = new DefaultParty() {
|
---|
25 |
|
---|
26 | @Override
|
---|
27 | public void notifyChange(Inform data) {
|
---|
28 | // TODO Auto-generated method stub
|
---|
29 |
|
---|
30 | }
|
---|
31 |
|
---|
32 | @Override
|
---|
33 | public String getDescription() {
|
---|
34 | // TODO Auto-generated method stub
|
---|
35 | return null;
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override
|
---|
39 | public Capabilities getCapabilities() {
|
---|
40 | // TODO Auto-generated method stub
|
---|
41 | return null;
|
---|
42 | }
|
---|
43 | };
|
---|
44 |
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Test
|
---|
48 | public void smoke() {
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Test
|
---|
52 | public void getReporter() {
|
---|
53 | assertNotNull(party.getReporter());
|
---|
54 | }
|
---|
55 |
|
---|
56 | @SuppressWarnings("unchecked")
|
---|
57 | @Test
|
---|
58 | public void connect() {
|
---|
59 |
|
---|
60 | ConnectionEnd<Inform, Action> connection = mock(ConnectionEnd.class);
|
---|
61 | party.connect(connection);
|
---|
62 |
|
---|
63 | verify(connection, times(1)).addListener(any(Listener.class));
|
---|
64 | assertNotNull(party.getConnection());
|
---|
65 | }
|
---|
66 |
|
---|
67 | @SuppressWarnings("unchecked")
|
---|
68 | @Test
|
---|
69 | public void disconnect() {
|
---|
70 |
|
---|
71 | ConnectionEnd<Inform, Action> connection = mock(ConnectionEnd.class);
|
---|
72 | party.connect(connection);
|
---|
73 |
|
---|
74 | party.disconnect();
|
---|
75 | verify(connection, times(1)).removeListener(any(Listener.class));
|
---|
76 | assertNull(party.getConnection());
|
---|
77 |
|
---|
78 | // check second disconnect is ignored
|
---|
79 | party.disconnect();
|
---|
80 | verify(connection, times(1)).removeListener(any(Listener.class));
|
---|
81 | assertNull(party.getConnection());
|
---|
82 |
|
---|
83 | }
|
---|
84 |
|
---|
85 | @SuppressWarnings("unchecked")
|
---|
86 | @Test
|
---|
87 | public void terminate() {
|
---|
88 |
|
---|
89 | ConnectionEnd<Inform, Action> connection = mock(ConnectionEnd.class);
|
---|
90 | party.connect(connection);
|
---|
91 |
|
---|
92 | party.terminate();
|
---|
93 | verify(connection, times(1)).removeListener(any(Listener.class));
|
---|
94 | assertNull(party.getConnection());
|
---|
95 |
|
---|
96 | // check second terminate is ignored
|
---|
97 | party.terminate();
|
---|
98 | verify(connection, times(1)).removeListener(any(Listener.class));
|
---|
99 | assertNull(party.getConnection());
|
---|
100 |
|
---|
101 | }
|
---|
102 |
|
---|
103 | }
|
---|