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.

RedirectCommandTest.java 4.7KB

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.redirect;
  23. import com.dmdirc.DMDircMBassador;
  24. import com.dmdirc.FrameContainer;
  25. import com.dmdirc.MessageTarget;
  26. import com.dmdirc.commandparser.CommandArguments;
  27. import com.dmdirc.commandparser.commands.context.ChatCommandContext;
  28. import com.dmdirc.commandparser.commands.global.Echo;
  29. import com.dmdirc.commandparser.parsers.CommandParser;
  30. import com.dmdirc.interfaces.CommandController;
  31. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  32. import com.dmdirc.interfaces.ui.InputWindow;
  33. import com.dmdirc.ui.WindowManager;
  34. import com.dmdirc.ui.messages.BackBufferFactory;
  35. import com.dmdirc.ui.input.TabCompleter;
  36. import com.dmdirc.ui.input.TabCompleterUtils;
  37. import com.dmdirc.ui.messages.sink.MessageSinkManager;
  38. import com.dmdirc.util.URLBuilder;
  39. import java.util.Optional;
  40. import org.junit.Before;
  41. import org.junit.Test;
  42. import org.junit.runner.RunWith;
  43. import org.mockito.Mock;
  44. import org.mockito.invocation.InvocationOnMock;
  45. import org.mockito.runners.MockitoJUnitRunner;
  46. import org.mockito.stubbing.Answer;
  47. import static org.mockito.Matchers.any;
  48. import static org.mockito.Matchers.eq;
  49. import static org.mockito.Mockito.doAnswer;
  50. import static org.mockito.Mockito.verify;
  51. import static org.mockito.Mockito.when;
  52. @RunWith(MockitoJUnitRunner.class)
  53. public class RedirectCommandTest {
  54. @Mock private MessageTarget target;
  55. @Mock private InputWindow inputWindow;
  56. @Mock private CommandController commandController;
  57. @Mock private FrameContainer frameContainer;
  58. @Mock private AggregateConfigProvider configProvider;
  59. @Mock private CommandParser commandParser;
  60. @Mock private TabCompleter tabCompleter;
  61. @Mock private MessageSinkManager messageSinkManager;
  62. @Mock private WindowManager windowManager;
  63. @Mock private URLBuilder urlBuilder;
  64. @Mock private DMDircMBassador eventBus;
  65. @Mock private BackBufferFactory backBufferFactory;
  66. @Mock private TabCompleterUtils tabCompleterUtils;
  67. @Before
  68. public void setup() {
  69. when(frameContainer.getOptionalConnection()).thenReturn(Optional.empty());
  70. when(commandController.getCommandChar()).thenReturn('/');
  71. when(commandController.getSilenceChar()).thenReturn('.');
  72. when(inputWindow.getContainer()).thenReturn(frameContainer);
  73. when(target.getConfigManager()).thenReturn(configProvider);
  74. when(target.getCommandParser()).thenReturn(commandParser);
  75. when(target.getTabCompleter()).thenReturn(tabCompleter);
  76. when(configProvider.hasOptionString("formatter", "commandOutput")).thenReturn(true);
  77. when(configProvider.getOption("formatter", "commandOutput")).thenReturn("%1$s");
  78. doAnswer(new Answer<Void>() {
  79. @Override
  80. public Void answer(final InvocationOnMock invocation) throws Throwable {
  81. new Echo(commandController, windowManager).execute(
  82. (FrameContainer) invocation.getArguments()[0],
  83. new CommandArguments(commandController, "/echo test"),
  84. null);
  85. return null;
  86. }
  87. }).when(commandParser).parseCommand(any(FrameContainer.class), eq("/echo test"));
  88. }
  89. @Test
  90. public void testExecute() {
  91. final RedirectCommand command = new RedirectCommand(commandController, messageSinkManager,
  92. urlBuilder, eventBus, backBufferFactory, tabCompleterUtils);
  93. command.execute(target, new CommandArguments(commandController, "/redirect /echo test"),
  94. new ChatCommandContext(frameContainer, RedirectCommand.INFO, target));
  95. verify(target).sendLine("test");
  96. }
  97. }