Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

BanTest.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
  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.parser.interfaces.ClientInfo;
  24. import com.dmdirc.Channel;
  25. import com.dmdirc.FrameContainer;
  26. import com.dmdirc.config.IdentityManager;
  27. import com.dmdirc.commandparser.CommandArguments;
  28. import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
  29. import com.dmdirc.parser.interfaces.ChannelClientInfo;
  30. import com.dmdirc.parser.interfaces.ChannelInfo;
  31. import org.junit.BeforeClass;
  32. import org.junit.Test;
  33. import static org.mockito.Mockito.*;
  34. public class BanTest {
  35. @BeforeClass
  36. public static void setUpClass() throws Exception {
  37. IdentityManager.load();
  38. }
  39. private final Ban command = new Ban();
  40. @Test
  41. public void testUsage() {
  42. final FrameContainer tiw = mock(FrameContainer.class);
  43. final Channel channel = mock(Channel.class);
  44. command.execute(tiw, new CommandArguments("/ban"),
  45. new ChannelCommandContext(null, Ban.INFO, channel));
  46. verify(tiw).addLine(eq("commandUsage"), anyChar(), anyString(), anyString());
  47. }
  48. /** Tests that the ban command uses the correct hostname if given a user. */
  49. @Test
  50. public void testKnownUser() {
  51. final FrameContainer container = mock(FrameContainer.class);
  52. final ChannelInfo channelInfo = mock(ChannelInfo.class);
  53. final ChannelClientInfo ccInfo = mock(ChannelClientInfo.class);
  54. final ClientInfo clientInfo = mock(ClientInfo.class);
  55. final Channel channel = mock(Channel.class);
  56. when(channel.getChannelInfo()).thenReturn(channelInfo);
  57. when(channelInfo.getChannelClient("user")).thenReturn(ccInfo);
  58. when(ccInfo.getClient()).thenReturn(clientInfo);
  59. when(clientInfo.getHostname()).thenReturn("my.host.name");
  60. command.execute(container, new CommandArguments("/ban user"),
  61. new ChannelCommandContext(null, Ban.INFO, channel));
  62. verify(channelInfo).alterMode(true, 'b', "*!*@my.host.name");
  63. verify(channelInfo).flushModes();
  64. }
  65. /** Tests that the ban command works if given a mask not a username. */
  66. @Test
  67. public void testHostmask() {
  68. final FrameContainer container = mock(FrameContainer.class);
  69. final ChannelInfo channelInfo = mock(ChannelInfo.class);
  70. final Channel channel = mock(Channel.class);
  71. when(channel.getChannelInfo()).thenReturn(channelInfo);
  72. command.execute(container, new CommandArguments("/ban *!*@my.host.name"),
  73. new ChannelCommandContext(null, Ban.INFO, channel));
  74. verify(channelInfo).alterMode(true, 'b', "*!*@my.host.name");
  75. verify(channelInfo).flushModes();
  76. }
  77. }