You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DebugTest.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (c) 2006-2013 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. package com.dmdirc.addons.debug;
  23. import com.dmdirc.FrameContainer;
  24. import com.dmdirc.commandparser.CommandArguments;
  25. import com.dmdirc.commandparser.commands.context.CommandContext;
  26. import com.dmdirc.interfaces.CommandController;
  27. import org.junit.Before;
  28. import org.junit.Test;
  29. import org.junit.runner.RunWith;
  30. import org.mockito.Mock;
  31. import org.mockito.runners.MockitoJUnitRunner;
  32. import static com.dmdirc.harness.CommandArgsMatcher.*;
  33. import static org.mockito.Mockito.*;
  34. @RunWith(MockitoJUnitRunner.class)
  35. public class DebugTest {
  36. @Mock private CommandArguments arguments;
  37. @Mock private FrameContainer container;
  38. @Mock private DebugPlugin plugin;
  39. @Mock private CommandController controller;
  40. @Mock private DebugCommand debugCommand;
  41. @Mock private CommandContext commandContext;
  42. private Debug debug;
  43. @Before
  44. public void setup() {
  45. when(controller.getCommandChar()).thenReturn('/');
  46. debug = new Debug(plugin, controller);
  47. }
  48. /** Checks the debug command with no arguments shows usage. */
  49. @Test
  50. public void testNoArgs() {
  51. when(arguments.isCommand()).thenReturn(true);
  52. when(arguments.getArguments()).thenReturn(new String[0]);
  53. debug.execute(container, arguments, null);
  54. verify(container).addLine(eq("commandUsage"), anyObject(),
  55. eq("debug"), anyObject());
  56. }
  57. /** Checks the debug command with an invalid subcommand shows an error. */
  58. @Test
  59. public void testInvalidArg() {
  60. when(plugin.getCommand("test")).thenReturn(null);
  61. when(arguments.isCommand()).thenReturn(true);
  62. when(arguments.getArguments()).thenReturn(new String[]{"test"});
  63. debug.execute(container, arguments, null);
  64. verify(container).addLine(eq("commandError"), anyObject());
  65. }
  66. /** Checks the debug command executes a subcommand with no args. */
  67. @Test
  68. public void testCommandNoArgs() {
  69. when(plugin.getCommand("test")).thenReturn(debugCommand);
  70. when(arguments.isCommand()).thenReturn(true);
  71. when(arguments.getArguments()).thenReturn(new String[]{"test"});
  72. when(arguments.getArgumentsAsString(1)).thenReturn("");
  73. when(debugCommand.getName()).thenReturn("test");
  74. debug.execute(container, arguments, commandContext);
  75. verify(container, never()).addLine(anyString(), anyObject());
  76. verify(debugCommand).execute(same(container), eqLine("/test"), same(commandContext));
  77. }
  78. /** Checks the debug command executes a subcommand with args. */
  79. @Test
  80. public void testCommandWithArgs() {
  81. when(plugin.getCommand("test")).thenReturn(debugCommand);
  82. when(arguments.isCommand()).thenReturn(true);
  83. when(arguments.getArguments()).thenReturn(new String[]{"test", "1", "2", "3"});
  84. when(arguments.getArgumentsAsString(1)).thenReturn("1 2 3");
  85. when(debugCommand.getName()).thenReturn("test");
  86. debug.execute(container, arguments, commandContext);
  87. verify(container, never()).addLine(anyString(), anyObject());
  88. verify(debugCommand).execute(same(container), eqLine("/test 1 2 3"), same(commandContext));
  89. }
  90. }