123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- /*
- * Copyright (c) 2006-2014 DMDirc Developers
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
- package com.dmdirc.addons.debug;
-
- import com.dmdirc.FrameContainer;
- import com.dmdirc.commandparser.CommandArguments;
- import com.dmdirc.commandparser.commands.context.CommandContext;
- import com.dmdirc.interfaces.CommandController;
-
- import java.util.HashSet;
- import org.junit.Before;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.mockito.Mock;
- import org.mockito.runners.MockitoJUnitRunner;
-
- import static com.dmdirc.harness.CommandArgsMatcher.*;
- import static org.mockito.Mockito.*;
-
- @RunWith(MockitoJUnitRunner.class)
- public class DebugTest {
-
- @Mock private CommandArguments arguments;
- @Mock private FrameContainer container;
- @Mock private DebugPlugin plugin;
- @Mock private CommandController controller;
- @Mock private DebugCommand debugCommand;
- @Mock private CommandContext commandContext;
- private Debug debug;
-
- @Before
- public void setup() {
- when(controller.getCommandChar()).thenReturn('/');
- when(debugCommand.getName()).thenReturn("test");
- }
-
- /** Checks the debug command with no arguments shows usage. */
- @Test
- public void testNoArgs() {
- debug = new Debug(controller, new HashSet<DebugCommand>());
- when(arguments.isCommand()).thenReturn(true);
- when(arguments.getArguments()).thenReturn(new String[0]);
- debug.execute(container, arguments, null);
- verify(container).addLine(eq("commandUsage"), anyObject(),
- eq("debug"), anyObject());
- }
-
- /** Checks the debug command with an invalid subcommand shows an error. */
- @Test
- public void testInvalidArg() {
- debug = new Debug(controller, new HashSet<DebugCommand>());
- when(arguments.isCommand()).thenReturn(true);
- when(arguments.getArguments()).thenReturn(new String[]{"test"});
-
- debug.execute(container, arguments, null);
- verify(container).addLine(eq("commandError"), anyObject());
- }
-
- /** Checks the debug command executes a subcommand with no args. */
- @Test
- public void testCommandNoArgs() {
- debug = new Debug(controller, new HashSet<DebugCommand>() {{ add(debugCommand); }});
- when(arguments.isCommand()).thenReturn(true);
- when(arguments.getArguments()).thenReturn(new String[]{"test"});
- when(arguments.getArgumentsAsString(1)).thenReturn("");
- when(debugCommand.getName()).thenReturn("test");
-
- debug.execute(container, arguments, commandContext);
-
- verify(container, never()).addLine(anyString(), anyObject());
- verify(debugCommand).execute(same(container), eqLine("/test"), same(commandContext));
- }
-
- /** Checks the debug command executes a subcommand with args. */
- @Test
- public void testCommandWithArgs() {
- debug = new Debug(controller, new HashSet<DebugCommand>() {{ add(debugCommand); }});
- when(arguments.isCommand()).thenReturn(true);
- when(arguments.getArguments()).thenReturn(new String[]{"test", "1", "2", "3"});
- when(arguments.getArgumentsAsString(1)).thenReturn("1 2 3");
- when(debugCommand.getName()).thenReturn("test");
-
- debug.execute(container, arguments, commandContext);
-
- verify(container, never()).addLine(anyString(), anyObject());
- verify(debugCommand).execute(same(container), eqLine("/test 1 2 3"), same(commandContext));
- }
-
- }
|