Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ActiveCommandTest.java 3.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) 2006-2015 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.activewindow;
  23. import com.dmdirc.FrameContainer;
  24. import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
  25. import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
  26. import com.dmdirc.commandparser.CommandArguments;
  27. import com.dmdirc.commandparser.commands.IntelligentCommand.IntelligentCommandContext;
  28. import com.dmdirc.commandparser.commands.context.CommandContext;
  29. import com.dmdirc.commandparser.parsers.CommandParser;
  30. import com.dmdirc.interfaces.CommandController;
  31. import com.dmdirc.ui.input.TabCompleterUtils;
  32. import java.util.Optional;
  33. import org.junit.Before;
  34. import org.junit.Test;
  35. import org.junit.runner.RunWith;
  36. import org.mockito.Mock;
  37. import org.mockito.runners.MockitoJUnitRunner;
  38. import static org.mockito.Mockito.never;
  39. import static org.mockito.Mockito.verify;
  40. import static org.mockito.Mockito.when;
  41. @RunWith(MockitoJUnitRunner.class)
  42. public class ActiveCommandTest {
  43. @Mock private IntelligentCommandContext intelligentCommandContext;
  44. @Mock private CommandParser commandParser;
  45. @Mock private CommandController commandController;
  46. @Mock private ActiveFrameManager activeFrameManager;
  47. @Mock private TabCompleterUtils tabCompleterUtils;
  48. @Mock private FrameContainer frameContainer;
  49. @Mock private TextFrame textFrame;
  50. @Mock private CommandArguments commandArguments;
  51. @Mock private CommandContext commandContext;
  52. private ActiveCommand activeCommand;
  53. @Before
  54. public void setUp() throws Exception {
  55. when(textFrame.getContainer()).thenReturn(frameContainer);
  56. when(frameContainer.getCommandParser()).thenReturn(commandParser);
  57. when(commandArguments.getArgumentsAsString()).thenReturn("some arguments");
  58. activeCommand = new ActiveCommand(commandController, activeFrameManager, tabCompleterUtils);
  59. }
  60. @Test
  61. public void testExecute_NoActive() throws Exception {
  62. when(activeFrameManager.getActiveFrame()).thenReturn(Optional.empty());
  63. activeCommand.execute(frameContainer, commandArguments, commandContext);
  64. verify(commandParser, never())
  65. .parseCommand(frameContainer, commandArguments.getArgumentsAsString());
  66. }
  67. @Test
  68. public void testExecute_Active() throws Exception {
  69. when(activeFrameManager.getActiveFrame()).thenReturn(Optional.of(textFrame));
  70. activeCommand.execute(frameContainer, commandArguments, commandContext);
  71. verify(commandParser).parseCommand(frameContainer, commandArguments.getArgumentsAsString());
  72. }
  73. @Test
  74. public void testGetSuggestions() throws Exception {
  75. activeCommand.getSuggestions(1, intelligentCommandContext);
  76. verify(tabCompleterUtils).getIntelligentResults(1, intelligentCommandContext, 0);
  77. }
  78. }