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.

RedirectCommandTest.java 4.3KB

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