123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- /*
- * Copyright (c) 2006-2014 DMDirc Developers
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
- package com.dmdirc.addons.redirect;
-
- import com.dmdirc.FrameContainer;
- import com.dmdirc.MessageTarget;
- import com.dmdirc.commandparser.CommandArguments;
- import com.dmdirc.commandparser.commands.context.ChatCommandContext;
- import com.dmdirc.commandparser.commands.global.Echo;
- import com.dmdirc.commandparser.parsers.CommandParser;
- import com.dmdirc.interfaces.CommandController;
- import com.dmdirc.interfaces.config.AggregateConfigProvider;
- import com.dmdirc.interfaces.ui.InputWindow;
- import com.dmdirc.messages.MessageSinkManager;
- import com.dmdirc.ui.WindowManager;
- import com.dmdirc.ui.input.TabCompleter;
- import com.dmdirc.util.URLBuilder;
-
- import com.google.common.eventbus.EventBus;
-
- import org.junit.Before;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.mockito.Mock;
- import org.mockito.invocation.InvocationOnMock;
- import org.mockito.runners.MockitoJUnitRunner;
- import org.mockito.stubbing.Answer;
-
- import static org.mockito.Matchers.any;
- import static org.mockito.Matchers.eq;
- import static org.mockito.Mockito.doAnswer;
- import static org.mockito.Mockito.verify;
- import static org.mockito.Mockito.when;
-
- @RunWith(MockitoJUnitRunner.class)
- public class RedirectCommandTest {
-
- @Mock private MessageTarget target;
- @Mock private InputWindow inputWindow;
- @Mock private CommandController commandController;
- @Mock private FrameContainer frameContainer;
- @Mock private AggregateConfigProvider configProvider;
- @Mock private CommandParser commandParser;
- @Mock private TabCompleter tabCompleter;
- @Mock private MessageSinkManager messageSinkManager;
- @Mock private WindowManager windowManager;
- @Mock private URLBuilder urlBuilder;
- @Mock private EventBus eventBus;
-
- @Before
- public void setup() {
- when(commandController.getCommandChar()).thenReturn('/');
- when(commandController.getSilenceChar()).thenReturn('.');
- when(inputWindow.getContainer()).thenReturn(frameContainer);
- when(target.getConfigManager()).thenReturn(configProvider);
- when(target.getCommandParser()).thenReturn(commandParser);
- when(target.getTabCompleter()).thenReturn(tabCompleter);
- when(configProvider.hasOptionString("formatter", "commandOutput")).thenReturn(true);
- when(configProvider.getOption("formatter", "commandOutput")).thenReturn("%1$s");
- doAnswer(new Answer<Void>() {
- @Override
- public Void answer(final InvocationOnMock invocation) throws Throwable {
- new Echo(commandController, windowManager).execute(
- ((FrameContainer) invocation.getArguments()[0]),
- new CommandArguments(commandController, "/echo test"),
- null);
- return null;
- }
- }).when(commandParser).parseCommand(any(FrameContainer.class), eq("/echo test"));
- }
-
- @Test
- public void testExecute() {
- final RedirectCommand command = new RedirectCommand(commandController, messageSinkManager,
- urlBuilder, eventBus);
-
- command.execute(target, new CommandArguments(commandController, "/redirect /echo test"),
- new ChatCommandContext(frameContainer, RedirectCommand.INFO, target));
-
- verify(target).sendLine("test");
- }
-
- }
|