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.0KB

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