Przeglądaj źródła

Added unit test for /kick

tags/0.6.3m1rc1
Chris Smith 15 lat temu
rodzic
commit
c459267c1e

+ 100
- 0
test/com/dmdirc/commandparser/commands/channel/KickReasonTest.java Wyświetl plik

@@ -0,0 +1,100 @@
1
+/*
2
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.commandparser.commands.channel;
24
+
25
+import com.dmdirc.Channel;
26
+import com.dmdirc.config.IdentityManager;
27
+import com.dmdirc.commandparser.CommandArguments;
28
+import com.dmdirc.config.ConfigManager;
29
+import com.dmdirc.parser.irc.ChannelClientInfo;
30
+import com.dmdirc.parser.irc.ChannelInfo;
31
+import com.dmdirc.ui.interfaces.InputWindow;
32
+
33
+import org.junit.BeforeClass;
34
+import org.junit.Test;
35
+import static org.mockito.Mockito.*;
36
+
37
+public class KickReasonTest {
38
+
39
+    @BeforeClass
40
+    public static void setUpClass() throws Exception {
41
+        IdentityManager.load();
42
+    }
43
+    
44
+    private final KickReason command = new KickReason();
45
+
46
+    @Test
47
+    public void testUsage() {
48
+        final InputWindow tiw = mock(InputWindow.class);
49
+        command.execute(tiw, null, null, false, new CommandArguments("/kick"));
50
+        
51
+        verify(tiw).addLine(eq("commandUsage"), anyChar(), anyString(), anyString());
52
+    }
53
+
54
+    @Test
55
+    public void testUnknown() {
56
+        final InputWindow tiw = mock(InputWindow.class);
57
+        final ChannelInfo channelInfo = mock(ChannelInfo.class);
58
+        final Channel channel = mock(Channel.class);
59
+
60
+        when(channel.getChannelInfo()).thenReturn(channelInfo);
61
+        when(channelInfo.getUser(anyString())).thenReturn(null);
62
+
63
+        command.execute(tiw, null, channel, false, new CommandArguments("/kick user1"));
64
+
65
+        verify(tiw).addLine(eq("commandError"), matches(".*user1"));
66
+    }
67
+
68
+    @Test
69
+    public void testWithReason() {
70
+        final InputWindow tiw = mock(InputWindow.class);
71
+        final ChannelInfo channelInfo = mock(ChannelInfo.class);
72
+        final Channel channel = mock(Channel.class);
73
+        final ChannelClientInfo cci = mock(ChannelClientInfo.class);
74
+
75
+        when(channel.getChannelInfo()).thenReturn(channelInfo);
76
+        when(channelInfo.getUser("user1")).thenReturn(cci);
77
+
78
+        command.execute(tiw, null, channel, false, new CommandArguments("/kick user1 reason here"));
79
+
80
+        verify(cci).kick("reason here");
81
+    }
82
+
83
+    @Test
84
+    public void testWithoutReason() {
85
+        final InputWindow tiw = mock(InputWindow.class);
86
+        final ConfigManager manager = mock(ConfigManager.class);
87
+        final ChannelInfo channelInfo = mock(ChannelInfo.class);
88
+        final Channel channel = mock(Channel.class);
89
+        final ChannelClientInfo cci = mock(ChannelClientInfo.class);
90
+
91
+        when(tiw.getConfigManager()).thenReturn(manager);
92
+        when(channel.getChannelInfo()).thenReturn(channelInfo);
93
+        when(channelInfo.getUser("user1")).thenReturn(cci);
94
+        when(manager.getOption("general", "kickmessage")).thenReturn("reason here");
95
+
96
+        command.execute(tiw, null, channel, false, new CommandArguments("/kick user1"));
97
+
98
+        verify(cci).kick("reason here");
99
+    }
100
+}

Ładowanie…
Anuluj
Zapisz