|
@@ -22,38 +22,42 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.addons.debug;
|
24
|
24
|
|
25
|
|
-import com.dmdirc.TestMain;
|
26
|
25
|
import com.dmdirc.FrameContainer;
|
27
|
26
|
import com.dmdirc.commandparser.CommandArguments;
|
28
|
27
|
import com.dmdirc.commandparser.commands.context.CommandContext;
|
29
|
|
-import com.dmdirc.config.InvalidIdentityFileException;
|
|
28
|
+import com.dmdirc.interfaces.CommandController;
|
30
|
29
|
|
31
|
|
-import org.junit.BeforeClass;
|
|
30
|
+import org.junit.Before;
|
32
|
31
|
import org.junit.Test;
|
|
32
|
+import org.junit.runner.RunWith;
|
|
33
|
+import org.mockito.Mock;
|
|
34
|
+import org.mockito.runners.MockitoJUnitRunner;
|
33
|
35
|
|
34
|
36
|
import static com.dmdirc.harness.CommandArgsMatcher.*;
|
35
|
37
|
import static org.mockito.Mockito.*;
|
36
|
38
|
|
|
39
|
+@RunWith(MockitoJUnitRunner.class)
|
37
|
40
|
public class DebugTest {
|
38
|
41
|
|
39
|
|
- @BeforeClass
|
40
|
|
- public static void setUp() throws InvalidIdentityFileException {
|
41
|
|
- // Command has a dependency on CommandManager (to get the command char)
|
42
|
|
- // And CommandManager has a dependency on IdentityManager for the same
|
43
|
|
- TestMain.getTestMain();
|
|
42
|
+ @Mock private CommandArguments arguments;
|
|
43
|
+ @Mock private FrameContainer container;
|
|
44
|
+ @Mock private DebugPlugin plugin;
|
|
45
|
+ @Mock private CommandController controller;
|
|
46
|
+ @Mock private DebugCommand debugCommand;
|
|
47
|
+ @Mock private CommandContext commandContext;
|
|
48
|
+ private Debug debug;
|
|
49
|
+
|
|
50
|
+ @Before
|
|
51
|
+ public void setup() {
|
|
52
|
+ when(controller.getCommandChar()).thenReturn('/');
|
|
53
|
+ debug = new Debug(plugin, controller);
|
44
|
54
|
}
|
45
|
55
|
|
46
|
56
|
/** Checks the debug command with no arguments shows usage. */
|
47
|
57
|
@Test
|
48
|
58
|
public void testNoArgs() {
|
49
|
|
- final CommandArguments arguments = mock(CommandArguments.class);
|
50
|
|
- final FrameContainer container = mock(FrameContainer.class);
|
51
|
|
-
|
52
|
59
|
when(arguments.isCommand()).thenReturn(true);
|
53
|
60
|
when(arguments.getArguments()).thenReturn(new String[0]);
|
54
|
|
-
|
55
|
|
- final Debug debug = new Debug(null);
|
56
|
|
-
|
57
|
61
|
debug.execute(container, arguments, null);
|
58
|
62
|
verify(container).addLine(eq("commandUsage"), anyObject(),
|
59
|
63
|
eq("debug"), anyObject());
|
|
@@ -62,16 +66,10 @@ public class DebugTest {
|
62
|
66
|
/** Checks the debug command with an invalid subcommand shows an error. */
|
63
|
67
|
@Test
|
64
|
68
|
public void testInvalidArg() {
|
65
|
|
- final DebugPlugin plugin = mock(DebugPlugin.class);
|
66
|
|
- final CommandArguments arguments = mock(CommandArguments.class);
|
67
|
|
- final FrameContainer container = mock(FrameContainer.class);
|
68
|
|
-
|
69
|
69
|
when(plugin.getCommand("test")).thenReturn(null);
|
70
|
70
|
when(arguments.isCommand()).thenReturn(true);
|
71
|
71
|
when(arguments.getArguments()).thenReturn(new String[]{"test"});
|
72
|
72
|
|
73
|
|
- final Debug debug = new Debug(plugin);
|
74
|
|
-
|
75
|
73
|
debug.execute(container, arguments, null);
|
76
|
74
|
verify(container).addLine(eq("commandError"), anyObject());
|
77
|
75
|
}
|
|
@@ -79,47 +77,31 @@ public class DebugTest {
|
79
|
77
|
/** Checks the debug command executes a subcommand with no args. */
|
80
|
78
|
@Test
|
81
|
79
|
public void testCommandNoArgs() {
|
82
|
|
- final DebugPlugin plugin = mock(DebugPlugin.class);
|
83
|
|
- final CommandArguments arguments = mock(CommandArguments.class);
|
84
|
|
- final FrameContainer container = mock(FrameContainer.class);
|
85
|
|
- final DebugCommand command = mock(DebugCommand.class);
|
86
|
|
- final CommandContext context = mock(CommandContext.class);
|
87
|
|
-
|
88
|
|
- when(plugin.getCommand("test")).thenReturn(command);
|
|
80
|
+ when(plugin.getCommand("test")).thenReturn(debugCommand);
|
89
|
81
|
when(arguments.isCommand()).thenReturn(true);
|
90
|
82
|
when(arguments.getArguments()).thenReturn(new String[]{"test"});
|
91
|
83
|
when(arguments.getArgumentsAsString(1)).thenReturn("");
|
92
|
|
- when(command.getName()).thenReturn("test");
|
93
|
|
-
|
94
|
|
- final Debug debug = new Debug(plugin);
|
|
84
|
+ when(debugCommand.getName()).thenReturn("test");
|
95
|
85
|
|
96
|
|
- debug.execute(container, arguments, context);
|
|
86
|
+ debug.execute(container, arguments, commandContext);
|
97
|
87
|
|
98
|
88
|
verify(container, never()).addLine(anyString(), anyObject());
|
99
|
|
- verify(command).execute(same(container), eqLine("/test"), same(context));
|
|
89
|
+ verify(debugCommand).execute(same(container), eqLine("/test"), same(commandContext));
|
100
|
90
|
}
|
101
|
91
|
|
102
|
92
|
/** Checks the debug command executes a subcommand with args. */
|
103
|
93
|
@Test
|
104
|
94
|
public void testCommandWithArgs() {
|
105
|
|
- final DebugPlugin plugin = mock(DebugPlugin.class);
|
106
|
|
- final CommandArguments arguments = mock(CommandArguments.class);
|
107
|
|
- final FrameContainer container = mock(FrameContainer.class);
|
108
|
|
- final DebugCommand command = mock(DebugCommand.class);
|
109
|
|
- final CommandContext context = mock(CommandContext.class);
|
110
|
|
-
|
111
|
|
- when(plugin.getCommand("test")).thenReturn(command);
|
|
95
|
+ when(plugin.getCommand("test")).thenReturn(debugCommand);
|
112
|
96
|
when(arguments.isCommand()).thenReturn(true);
|
113
|
97
|
when(arguments.getArguments()).thenReturn(new String[]{"test", "1", "2", "3"});
|
114
|
98
|
when(arguments.getArgumentsAsString(1)).thenReturn("1 2 3");
|
115
|
|
- when(command.getName()).thenReturn("test");
|
116
|
|
-
|
117
|
|
- final Debug debug = new Debug(plugin);
|
|
99
|
+ when(debugCommand.getName()).thenReturn("test");
|
118
|
100
|
|
119
|
|
- debug.execute(container, arguments, context);
|
|
101
|
+ debug.execute(container, arguments, commandContext);
|
120
|
102
|
|
121
|
103
|
verify(container, never()).addLine(anyString(), anyObject());
|
122
|
|
- verify(command).execute(same(container), eqLine("/test 1 2 3"), same(context));
|
|
104
|
+ verify(debugCommand).execute(same(container), eqLine("/test 1 2 3"), same(commandContext));
|
123
|
105
|
}
|
124
|
106
|
|
125
|
107
|
}
|