|
@@ -22,14 +22,92 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.addons.nickkeep;
|
24
|
24
|
|
|
25
|
+import com.dmdirc.Channel;
|
|
26
|
+import com.dmdirc.DMDircMBassador;
|
|
27
|
+import com.dmdirc.config.profiles.Profile;
|
|
28
|
+import com.dmdirc.events.ChannelNickChangeEvent;
|
|
29
|
+import com.dmdirc.interfaces.Connection;
|
|
30
|
+
|
|
31
|
+import com.google.common.collect.Lists;
|
|
32
|
+
|
|
33
|
+import java.util.Optional;
|
|
34
|
+
|
25
|
35
|
import org.junit.Before;
|
|
36
|
+import org.junit.Test;
|
26
|
37
|
import org.junit.runner.RunWith;
|
|
38
|
+import org.mockito.Mock;
|
27
|
39
|
import org.mockito.runners.MockitoJUnitRunner;
|
28
|
40
|
|
|
41
|
+import static org.mockito.Matchers.anyString;
|
|
42
|
+import static org.mockito.Mockito.never;
|
|
43
|
+import static org.mockito.Mockito.verify;
|
|
44
|
+import static org.mockito.Mockito.when;
|
|
45
|
+
|
29
|
46
|
@RunWith(MockitoJUnitRunner.class)
|
30
|
47
|
public class NickKeepManagerTest {
|
31
|
48
|
|
|
49
|
+ @Mock private DMDircMBassador eventBus;
|
|
50
|
+ @Mock private ChannelNickChangeEvent event;
|
|
51
|
+ @Mock private Channel channel;
|
|
52
|
+ @Mock private Connection connection;
|
|
53
|
+ @Mock private Profile profile;
|
|
54
|
+ private NickKeepManager instance;
|
|
55
|
+
|
32
|
56
|
@Before
|
33
|
57
|
public void setUp() throws Exception {
|
|
58
|
+ instance = new NickKeepManager(eventBus);
|
|
59
|
+ when(event.getChannel()).thenReturn(channel);
|
|
60
|
+ when(channel.getConnection()).thenReturn(Optional.of(connection));
|
|
61
|
+ when(connection.getProfile()).thenReturn(profile);
|
|
62
|
+ when(profile.getNicknames()).thenReturn(Lists.newArrayList("one", "two", "three"));
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ @Test
|
|
66
|
+ public void testLoad() throws Exception {
|
|
67
|
+ instance.load();
|
|
68
|
+ verify(eventBus).subscribe(instance);
|
|
69
|
+ }
|
|
70
|
+
|
|
71
|
+ @Test
|
|
72
|
+ public void testUnload() throws Exception {
|
|
73
|
+ instance.unload();
|
|
74
|
+ verify(eventBus).unsubscribe(instance);
|
|
75
|
+ }
|
|
76
|
+
|
|
77
|
+ @Test
|
|
78
|
+ public void testHandleNickChange_NoConnection() throws Exception {
|
|
79
|
+ when(channel.getConnection()).thenReturn(Optional.empty());
|
|
80
|
+ instance.handleNickChange(event);
|
|
81
|
+ verify(connection, never()).setNickname("one");
|
|
82
|
+ }
|
|
83
|
+
|
|
84
|
+ @Test
|
|
85
|
+ public void testHandleNickChange_NoCurrentNickname() throws Exception {
|
|
86
|
+ when(connection.getNickname()).thenReturn(Optional.empty());
|
|
87
|
+ instance.handleNickChange(event);
|
|
88
|
+ verify(connection, never()).setNickname("one");
|
|
89
|
+ }
|
|
90
|
+
|
|
91
|
+ @Test
|
|
92
|
+ public void testHandleNickChange_NoNicknames() throws Exception {
|
|
93
|
+ when(profile.getNicknames()).thenReturn(Lists.newArrayList());
|
|
94
|
+ instance.handleNickChange(event);
|
|
95
|
+ verify(connection, never()).setNickname(anyString());
|
|
96
|
+ }
|
|
97
|
+
|
|
98
|
+ @Test
|
|
99
|
+ public void testHandleNickChange_NotDesired() throws Exception {
|
|
100
|
+ when(event.getOldNick()).thenReturn("RAR");
|
|
101
|
+ when(connection.getNickname()).thenReturn(Optional.of("one"));
|
|
102
|
+ instance.handleNickChange(event);
|
|
103
|
+ verify(connection, never()).setNickname("one");
|
|
104
|
+ }
|
|
105
|
+
|
|
106
|
+ @Test
|
|
107
|
+ public void testHandleNickChange_Desired() throws Exception {
|
|
108
|
+ when(event.getOldNick()).thenReturn("one");
|
|
109
|
+ when(connection.getNickname()).thenReturn(Optional.of("RAR"));
|
|
110
|
+ instance.handleNickChange(event);
|
|
111
|
+ verify(connection).setNickname("one");
|
34
|
112
|
}
|
35
|
113
|
}
|