瀏覽代碼

Add unit test for /mode and fix bug with external invocations not

working (oops!)
tags/0.6.3m1rc1
Chris Smith 15 年之前
父節點
當前提交
a6b420b787

+ 2
- 2
src/com/dmdirc/Channel.java 查看文件

@@ -54,8 +54,8 @@ import java.util.Map;
54 54
  *
55 55
  * @author chris
56 56
  */
57
-public final class Channel extends MessageTarget
58
-        implements ConfigChangeListener, Serializable {
57
+public class Channel extends MessageTarget implements ConfigChangeListener,
58
+        Serializable {
59 59
 
60 60
     /**
61 61
      * A version number for this class. It should be changed whenever the class

+ 2
- 2
src/com/dmdirc/commandparser/commands/channel/Mode.java 查看文件

@@ -67,10 +67,10 @@ public final class Mode extends ChannelCommand implements IntelligentCommand,
67 67
     @Override
68 68
     public void execute(final InputWindow origin, final Server server,
69 69
             final String channel, final boolean isSilent, final CommandArguments args) {
70
-        if (args.getArguments().length == 0) {
70
+        if (args.getArguments().length == 1) {
71 71
             server.getParser().sendLine("MODE " + channel);
72 72
         } else {
73
-            server.getParser().sendLine("MODE " + channel + " " + args.getArgumentsAsString());
73
+            server.getParser().sendLine("MODE " + channel + " " + args.getArgumentsAsString(1));
74 74
         }
75 75
     }
76 76
 

+ 1
- 1
src/com/dmdirc/parser/irc/ChannelInfo.java 查看文件

@@ -37,7 +37,7 @@ import java.util.Queue;
37 37
  * @author Chris Smith
38 38
  * @see IRCParser
39 39
  */
40
-public final class ChannelInfo {
40
+public class ChannelInfo {
41 41
 	/**
42 42
 	 * Boolean repreenting the status of names requests.
43 43
 	 * When this is false, any new names reply will cause current known channelclients to be removed.

+ 104
- 0
test/com/dmdirc/commandparser/commands/channel/ModeTest.java 查看文件

@@ -0,0 +1,104 @@
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.Server;
27
+import com.dmdirc.commandparser.CommandArguments;
28
+import com.dmdirc.config.IdentityManager;
29
+import com.dmdirc.parser.irc.ChannelInfo;
30
+import com.dmdirc.parser.irc.IRCParser;
31
+import com.dmdirc.ui.interfaces.InputWindow;
32
+
33
+import org.junit.Before;
34
+import org.junit.BeforeClass;
35
+import org.junit.Test;
36
+import static org.mockito.Mockito.*;
37
+
38
+public class ModeTest {
39
+
40
+    private final Mode command = new Mode();
41
+    private ChannelInfo channelinfo;
42
+    private Channel channel;
43
+    private Server server;
44
+    private IRCParser parser;
45
+
46
+    @BeforeClass
47
+    public static void setUpClass() {
48
+        IdentityManager.load();
49
+    }
50
+
51
+    @Before
52
+    public void setUp() {
53
+        IdentityManager.load();
54
+        
55
+        parser = mock(IRCParser.class);
56
+        server = mock(Server.class);
57
+        channel = mock(Channel.class);
58
+        channelinfo = mock(ChannelInfo.class);
59
+
60
+        when(server.getParser()).thenReturn(parser);
61
+        when(channel.getChannelInfo()).thenReturn(channelinfo);
62
+        when(channelinfo.getModeStr()).thenReturn("my mode string!");
63
+        when(channelinfo.toString()).thenReturn("#chan");
64
+    }
65
+
66
+    @Test
67
+    public void testWithoutArgs() {
68
+        final InputWindow origin = mock(InputWindow.class);
69
+        
70
+        command.execute(origin, server, channel, false, new CommandArguments("/mode"));
71
+
72
+        verify(origin).addLine("channelModeDiscovered", "my mode string!", channelinfo);
73
+    }
74
+
75
+    @Test
76
+    public void testWithArgs() {
77
+        final InputWindow origin = mock(InputWindow.class);
78
+
79
+        command.execute(origin, server, channel, false, new CommandArguments("/mode +hello -bye"));
80
+
81
+        verify(parser).sendLine("MODE #chan +hello -bye");
82
+    }
83
+
84
+    @Test
85
+    public void testExternalWithArgs() {
86
+        final InputWindow origin = mock(InputWindow.class);
87
+
88
+        command.execute(origin, server, "#chan", false,
89
+                new CommandArguments("/mode #chan +hello -bye"));
90
+
91
+        verify(parser).sendLine("MODE #chan +hello -bye");
92
+    }
93
+
94
+    @Test
95
+    public void testExternalWithoutArgs() {
96
+        final InputWindow origin = mock(InputWindow.class);
97
+
98
+        command.execute(origin, server, "#chan", false,
99
+                new CommandArguments("/mode #chan"));
100
+
101
+        verify(parser).sendLine("MODE #chan");
102
+    }
103
+
104
+}

Loading…
取消
儲存