|
@@ -22,42 +22,64 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.addons.redirect;
|
24
|
24
|
|
25
|
|
-import com.dmdirc.TestMain;
|
|
25
|
+import com.dmdirc.FrameContainer;
|
26
|
26
|
import com.dmdirc.MessageTarget;
|
|
27
|
+import com.dmdirc.WritableFrameContainer;
|
27
|
28
|
import com.dmdirc.commandparser.CommandArguments;
|
28
|
|
-import com.dmdirc.commandparser.CommandManager;
|
29
|
29
|
import com.dmdirc.commandparser.commands.context.ChatCommandContext;
|
30
|
30
|
import com.dmdirc.commandparser.commands.global.Echo;
|
31
|
|
-import com.dmdirc.config.IdentityManager;
|
32
|
|
-import com.dmdirc.config.InvalidIdentityFileException;
|
|
31
|
+import com.dmdirc.commandparser.parsers.CommandParser;
|
|
32
|
+import com.dmdirc.config.ConfigManager;
|
|
33
|
+import com.dmdirc.interfaces.CommandController;
|
33
|
34
|
import com.dmdirc.interfaces.ui.InputWindow;
|
34
|
35
|
|
35
|
|
-import org.junit.BeforeClass;
|
36
|
|
-import org.junit.Ignore;
|
|
36
|
+import org.junit.Before;
|
37
|
37
|
import org.junit.Test;
|
|
38
|
+import org.junit.runner.RunWith;
|
|
39
|
+import org.mockito.Mock;
|
|
40
|
+import org.mockito.invocation.InvocationOnMock;
|
|
41
|
+import org.mockito.runners.MockitoJUnitRunner;
|
|
42
|
+import org.mockito.stubbing.Answer;
|
38
|
43
|
|
39
|
44
|
import static org.mockito.Mockito.*;
|
40
|
45
|
|
|
46
|
+@RunWith(MockitoJUnitRunner.class)
|
41
|
47
|
public class RedirectCommandTest {
|
42
|
48
|
|
43
|
|
- @BeforeClass
|
44
|
|
- public static void setupClass() throws InvalidIdentityFileException {
|
45
|
|
- TestMain.getTestMain();
|
46
|
|
- CommandManager.getCommandManager().registerCommand(new Echo(), Echo.INFO);
|
|
49
|
+ @Mock private MessageTarget target;
|
|
50
|
+ @Mock private InputWindow inputWindow;
|
|
51
|
+ @Mock private CommandController commandController;
|
|
52
|
+ @Mock private WritableFrameContainer frameContainer;
|
|
53
|
+ @Mock private ConfigManager configManager;
|
|
54
|
+ @Mock private CommandParser commandParser;
|
|
55
|
+
|
|
56
|
+ @Before
|
|
57
|
+ public void setup() {
|
|
58
|
+ when(commandController.getCommandChar()).thenReturn('/');
|
|
59
|
+ when(commandController.getSilenceChar()).thenReturn('.');
|
|
60
|
+ when(inputWindow.getContainer()).thenReturn(frameContainer);
|
|
61
|
+ when(target.getConfigManager()).thenReturn(configManager);
|
|
62
|
+ when(target.getCommandParser()).thenReturn(commandParser);
|
|
63
|
+ when(configManager.hasOptionString("formatter", "commandOutput")).thenReturn(true);
|
|
64
|
+ when(configManager.getOption("formatter", "commandOutput")).thenReturn("%1$s");
|
|
65
|
+ doAnswer(new Answer<Void>() {
|
|
66
|
+ @Override
|
|
67
|
+ public Void answer(final InvocationOnMock invocation) throws Throwable {
|
|
68
|
+ new Echo(commandController).execute(
|
|
69
|
+ ((FrameContainer) invocation.getArguments()[0]),
|
|
70
|
+ new CommandArguments(commandController, "/echo test"),
|
|
71
|
+ null);
|
|
72
|
+ return null;
|
|
73
|
+ }
|
|
74
|
+ }).when(commandParser).parseCommand(any(FrameContainer.class), eq("/echo test"));
|
47
|
75
|
}
|
48
|
76
|
|
49
|
|
- @Ignore
|
50
|
77
|
@Test
|
51
|
78
|
public void testExecute() {
|
52
|
79
|
final RedirectCommand command = new RedirectCommand();
|
53
|
|
- final MessageTarget target = mock(MessageTarget.class);
|
54
|
|
- final InputWindow window = mock(InputWindow.class);
|
55
|
|
- //when(window.getCommandParser()).thenReturn(parser);
|
56
|
|
- when(window.getContainer().getConfigManager()).thenReturn(
|
57
|
|
- IdentityManager.getIdentityManager().getGlobalConfiguration());
|
58
|
80
|
|
59
|
|
- command.execute(target, new CommandArguments("/redirect /echo test"),
|
60
|
|
- new ChatCommandContext(window.getContainer(), RedirectCommand.INFO, target));
|
|
81
|
+ command.execute(target, new CommandArguments(commandController, "/redirect /echo test"),
|
|
82
|
+ new ChatCommandContext(frameContainer, RedirectCommand.INFO, target));
|
61
|
83
|
|
62
|
84
|
verify(target).sendLine("test");
|
63
|
85
|
}
|