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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.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.config.ConfigBinder;
  31. import com.dmdirc.interfaces.CommandController;
  32. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  33. import com.dmdirc.interfaces.ui.InputWindow;
  34. import com.dmdirc.ui.WindowManager;
  35. import com.dmdirc.ui.input.TabCompleter;
  36. import com.dmdirc.ui.input.TabCompleterUtils;
  37. import com.dmdirc.ui.messages.BackBufferFactory;
  38. import com.dmdirc.ui.messages.sink.MessageSinkManager;
  39. import com.dmdirc.util.URLBuilder;
  40. import java.util.Optional;
  41. import org.junit.Before;
  42. import org.junit.Test;
  43. import org.junit.runner.RunWith;
  44. import org.mockito.Mock;
  45. import org.mockito.runners.MockitoJUnitRunner;
  46. import static org.mockito.Matchers.any;
  47. import static org.mockito.Matchers.eq;
  48. import static org.mockito.Mockito.doAnswer;
  49. import static org.mockito.Mockito.verify;
  50. import static org.mockito.Mockito.when;
  51. @RunWith(MockitoJUnitRunner.class)
  52. public class RedirectCommandTest {
  53. @Mock private MessageTarget target;
  54. @Mock private InputWindow inputWindow;
  55. @Mock private CommandController commandController;
  56. @Mock private FrameContainer frameContainer;
  57. @Mock private AggregateConfigProvider configProvider;
  58. @Mock private ConfigBinder configBinder;
  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.getConnection()).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. when(configProvider.getBinder()).thenReturn(configBinder);
  79. doAnswer(invocation -> {
  80. new Echo(commandController, windowManager).execute(
  81. (FrameContainer) invocation.getArguments()[0],
  82. new CommandArguments(commandController, "/echo test"),
  83. null);
  84. return null;
  85. }).when(commandParser).parseCommand(any(FrameContainer.class), eq("/echo test"));
  86. }
  87. @Test
  88. public void testExecute() {
  89. final RedirectCommand command = new RedirectCommand(commandController, messageSinkManager,
  90. urlBuilder, eventBus, backBufferFactory, tabCompleterUtils);
  91. command.execute(target, new CommandArguments(commandController, "/redirect /echo test"),
  92. new ChatCommandContext(frameContainer, RedirectCommand.INFO, target));
  93. verify(target).sendLine("test");
  94. }
  95. }