Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

KickReasonTest.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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.commandparser.commands.channel;
  23. import com.dmdirc.Channel;
  24. import com.dmdirc.FrameContainer;
  25. import com.dmdirc.commandparser.CommandArguments;
  26. import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
  27. import com.dmdirc.interfaces.CommandController;
  28. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  29. import com.dmdirc.parser.interfaces.ChannelClientInfo;
  30. import com.dmdirc.parser.interfaces.ChannelInfo;
  31. import org.junit.Before;
  32. import org.junit.Test;
  33. import org.junit.runner.RunWith;
  34. import org.mockito.Mock;
  35. import org.mockito.runners.MockitoJUnitRunner;
  36. import static org.mockito.Mockito.anyChar;
  37. import static org.mockito.Mockito.anyString;
  38. import static org.mockito.Mockito.eq;
  39. import static org.mockito.Mockito.matches;
  40. import static org.mockito.Mockito.mock;
  41. import static org.mockito.Mockito.verify;
  42. import static org.mockito.Mockito.when;
  43. @RunWith(MockitoJUnitRunner.class)
  44. public class KickReasonTest {
  45. private KickReason command;
  46. @Mock private CommandController controller;
  47. @Before
  48. public void setup() {
  49. when(controller.getCommandChar()).thenReturn('/');
  50. when(controller.getSilenceChar()).thenReturn('.');
  51. command = new KickReason(controller);
  52. }
  53. @Test
  54. public void testUsage() {
  55. final FrameContainer tiw = mock(FrameContainer.class);
  56. final Channel channel = mock(Channel.class);
  57. command.execute(tiw, new CommandArguments(controller, "/kick"),
  58. new ChannelCommandContext(null, KickReason.INFO, channel));
  59. verify(tiw).addLine(eq("commandUsage"), anyChar(), anyString(), anyString());
  60. }
  61. @Test
  62. public void testUnknown() {
  63. final FrameContainer tiw = mock(FrameContainer.class);
  64. final ChannelInfo channelInfo = mock(ChannelInfo.class);
  65. final Channel channel = mock(Channel.class);
  66. when(channel.getChannelInfo()).thenReturn(channelInfo);
  67. when(channelInfo.getChannelClient(anyString())).thenReturn(null);
  68. command.execute(tiw, new CommandArguments(controller, "/kick user1"),
  69. new ChannelCommandContext(null, KickReason.INFO, channel));
  70. verify(tiw).addLine(eq("commandError"), matches(".*user1"));
  71. }
  72. @Test
  73. public void testWithReason() {
  74. final FrameContainer tiw = mock(FrameContainer.class);
  75. final ChannelInfo channelInfo = mock(ChannelInfo.class);
  76. final Channel channel = mock(Channel.class);
  77. final ChannelClientInfo cci = mock(ChannelClientInfo.class);
  78. when(channel.getChannelInfo()).thenReturn(channelInfo);
  79. when(channelInfo.getChannelClient("user1")).thenReturn(cci);
  80. command.execute(tiw, new CommandArguments(controller, "/kick user1 reason here"),
  81. new ChannelCommandContext(null, KickReason.INFO, channel));
  82. verify(cci).kick("reason here");
  83. }
  84. @Test
  85. public void testWithoutReason() {
  86. final FrameContainer tiw = mock(FrameContainer.class);
  87. final AggregateConfigProvider manager = mock(AggregateConfigProvider.class);
  88. final ChannelInfo channelInfo = mock(ChannelInfo.class);
  89. final Channel channel = mock(Channel.class);
  90. final ChannelClientInfo cci = mock(ChannelClientInfo.class);
  91. when(tiw.getConfigManager()).thenReturn(manager);
  92. when(channel.getChannelInfo()).thenReturn(channelInfo);
  93. when(channelInfo.getChannelClient("user1")).thenReturn(cci);
  94. when(manager.getOption("general", "kickmessage")).thenReturn("reason here");
  95. command.execute(tiw, new CommandArguments(controller, "/kick user1"),
  96. new ChannelCommandContext(null, KickReason.INFO, channel));
  97. verify(cci).kick("reason here");
  98. }
  99. }