Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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