Browse Source

Test the command too.

pull/127/head
Greg Holmes 9 years ago
parent
commit
9fcd8047fe

+ 0
- 1
activewindow/src/com/dmdirc/addons/activewindow/ActiveCommand.java View File

@@ -23,7 +23,6 @@
23 23
 package com.dmdirc.addons.activewindow;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26
-import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
27 26
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
28 27
 import com.dmdirc.commandparser.BaseCommandInfo;
29 28
 import com.dmdirc.commandparser.CommandArguments;

+ 89
- 0
activewindow/test/com/dmdirc/addons/activewindow/ActiveCommandTest.java View File

@@ -0,0 +1,89 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
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.addons.activewindow;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
27
+import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
28
+import com.dmdirc.commandparser.CommandArguments;
29
+import com.dmdirc.commandparser.commands.IntelligentCommand.IntelligentCommandContext;
30
+import com.dmdirc.commandparser.commands.context.CommandContext;
31
+import com.dmdirc.commandparser.parsers.CommandParser;
32
+import com.dmdirc.interfaces.CommandController;
33
+import com.dmdirc.ui.input.TabCompleterUtils;
34
+
35
+import java.util.Optional;
36
+
37
+import org.junit.Before;
38
+import org.junit.Test;
39
+import org.junit.runner.RunWith;
40
+import org.mockito.Mock;
41
+import org.mockito.runners.MockitoJUnitRunner;
42
+
43
+import static org.mockito.Mockito.never;
44
+import static org.mockito.Mockito.verify;
45
+import static org.mockito.Mockito.when;
46
+
47
+@RunWith(MockitoJUnitRunner.class)
48
+public class ActiveCommandTest {
49
+
50
+    @Mock private IntelligentCommandContext intelligentCommandContext;
51
+    @Mock private CommandParser commandParser;
52
+    @Mock private CommandController commandController;
53
+    @Mock private ActiveFrameManager activeFrameManager;
54
+    @Mock private TabCompleterUtils tabCompleterUtils;
55
+    @Mock private FrameContainer frameContainer;
56
+    @Mock private TextFrame textFrame;
57
+    @Mock private CommandArguments commandArguments;
58
+    @Mock private CommandContext commandContext;
59
+    private ActiveCommand activeCommand;
60
+
61
+    @Before
62
+    public void setUp() throws Exception {
63
+        when(textFrame.getContainer()).thenReturn(frameContainer);
64
+        when(frameContainer.getCommandParser()).thenReturn(commandParser);
65
+        when(commandArguments.getArgumentsAsString()).thenReturn("some arguments");
66
+        activeCommand = new ActiveCommand(commandController, activeFrameManager, tabCompleterUtils);
67
+    }
68
+
69
+    @Test
70
+    public void testExecute_NoActive() throws Exception {
71
+        when(activeFrameManager.getActiveFrame()).thenReturn(Optional.empty());
72
+        activeCommand.execute(frameContainer, commandArguments, commandContext);
73
+        verify(commandParser, never())
74
+                .parseCommand(frameContainer, commandArguments.getArgumentsAsString());
75
+    }
76
+
77
+    @Test
78
+    public void testExecute_Active() throws Exception {
79
+        when(activeFrameManager.getActiveFrame()).thenReturn(Optional.of(textFrame));
80
+        activeCommand.execute(frameContainer, commandArguments, commandContext);
81
+        verify(commandParser).parseCommand(frameContainer, commandArguments.getArgumentsAsString());
82
+    }
83
+
84
+    @Test
85
+    public void testGetSuggestions() throws Exception {
86
+        activeCommand.getSuggestions(1, intelligentCommandContext);
87
+        verify(tabCompleterUtils).getIntelligentResults(1, intelligentCommandContext, 0);
88
+    }
89
+}

Loading…
Cancel
Save