|
@@ -23,35 +23,71 @@
|
23
|
23
|
package com.dmdirc.addons.channelwho;
|
24
|
24
|
|
25
|
25
|
import com.dmdirc.DMDircMBassador;
|
|
26
|
+import com.dmdirc.events.ServerConnectingEvent;
|
|
27
|
+import com.dmdirc.events.ServerDisconnectedEvent;
|
|
28
|
+import com.dmdirc.interfaces.Connection;
|
26
|
29
|
import com.dmdirc.interfaces.ConnectionManager;
|
27
|
30
|
|
|
31
|
+import com.google.common.collect.Lists;
|
|
32
|
+
|
28
|
33
|
import org.junit.Before;
|
29
|
34
|
import org.junit.Test;
|
30
|
35
|
import org.junit.runner.RunWith;
|
31
|
36
|
import org.mockito.Mock;
|
32
|
37
|
import org.mockito.runners.MockitoJUnitRunner;
|
33
|
38
|
|
|
39
|
+import static org.mockito.Mockito.never;
|
|
40
|
+import static org.mockito.Mockito.verify;
|
|
41
|
+import static org.mockito.Mockito.when;
|
|
42
|
+
|
34
|
43
|
@RunWith(MockitoJUnitRunner.class)
|
35
|
44
|
public class ChannelWhoManagerTest {
|
36
|
45
|
|
37
|
46
|
@Mock private ConnectionHandlerFactory connectionHandlerFactory;
|
|
47
|
+ @Mock private ConnectionHandler connectionHandler;
|
38
|
48
|
@Mock private ConnectionManager connectionManager;
|
|
49
|
+ @Mock private Connection connection;
|
|
50
|
+ @Mock private Connection connection2;
|
39
|
51
|
@Mock private DMDircMBassador eventBus;
|
40
|
52
|
|
41
|
53
|
private ChannelWhoManager instance;
|
42
|
54
|
|
43
|
55
|
@Before
|
44
|
56
|
public void setUp() throws Exception {
|
|
57
|
+ when(connectionManager.getConnections()).thenReturn(Lists.newArrayList(connection));
|
|
58
|
+ when(connectionHandlerFactory.get(connection)).thenReturn(connectionHandler);
|
45
|
59
|
instance = new ChannelWhoManager(connectionHandlerFactory, connectionManager, eventBus);
|
|
60
|
+ instance.load();
|
46
|
61
|
}
|
47
|
62
|
|
48
|
63
|
@Test
|
49
|
64
|
public void testLoad() throws Exception {
|
50
|
|
-
|
|
65
|
+ verify(eventBus).subscribe(instance);
|
|
66
|
+ verify(connectionHandlerFactory).get(connection);
|
51
|
67
|
}
|
52
|
68
|
|
53
|
69
|
@Test
|
54
|
70
|
public void testUnload() throws Exception {
|
|
71
|
+ instance.unload();
|
|
72
|
+ verify(eventBus).unsubscribe(instance);
|
|
73
|
+ verify(connectionHandler).unload();
|
|
74
|
+ }
|
55
|
75
|
|
|
76
|
+ @Test
|
|
77
|
+ public void testServerConnectionEvent() throws Exception {
|
|
78
|
+ instance.handleServerConnectingEvent(new ServerConnectingEvent(connection2));
|
|
79
|
+ verify(connectionHandlerFactory).get(connection);
|
|
80
|
+ }
|
|
81
|
+
|
|
82
|
+ @Test
|
|
83
|
+ public void testServerDisconnectionEvent_Existing() throws Exception {
|
|
84
|
+ instance.handleServerDisconnectedEvent(new ServerDisconnectedEvent(connection));
|
|
85
|
+ verify(connectionHandler).unload();
|
|
86
|
+ }
|
|
87
|
+
|
|
88
|
+ @Test
|
|
89
|
+ public void testServerDisconnectionEvent_Unknown() throws Exception {
|
|
90
|
+ instance.handleServerDisconnectedEvent(new ServerDisconnectedEvent(connection2));
|
|
91
|
+ verify(connectionHandler, never()).unload();
|
56
|
92
|
}
|
57
|
93
|
}
|