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.

ChannelClientInfoTest.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (c) 2006-2015 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.parser.irc;
  23. import com.dmdirc.harness.parser.TestParser;
  24. import com.dmdirc.parser.interfaces.ChannelClientInfo;
  25. import java.util.HashMap;
  26. import java.util.Map;
  27. import org.junit.Test;
  28. import static org.junit.Assert.assertEquals;
  29. import static org.junit.Assert.assertSame;
  30. public class ChannelClientInfoTest {
  31. @Test
  32. public void testImportantMode() {
  33. final TestParser parser = new TestParser();
  34. parser.injectConnectionStrings();
  35. parser.injectLine(":nick JOIN #DMDirc_testing");
  36. parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser");
  37. parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list");
  38. final IRCChannelClientInfo cci = (IRCChannelClientInfo) parser.getClient("luser")
  39. .getChannelClients().get(0);
  40. assertEquals("v", cci.getImportantMode());
  41. assertEquals("+", cci.getImportantModePrefix());
  42. assertEquals("+luser", cci.toString());
  43. assertEquals("+luser", cci.toFullString());
  44. parser.injectLine(":server MODE #DMDirc_testing +o luser");
  45. assertEquals("o", cci.getImportantMode());
  46. assertEquals("@", cci.getImportantModePrefix());
  47. assertEquals("@luser", cci.toString());
  48. assertEquals("@+luser", cci.toFullString());
  49. parser.injectLine(":server MODE #DMDirc_testing -ov luser luser");
  50. assertEquals("", cci.getImportantMode());
  51. assertEquals("", cci.getImportantModePrefix());
  52. assertEquals("luser", cci.toString());
  53. assertEquals("luser", cci.toFullString());
  54. }
  55. @Test
  56. public void testMap() {
  57. final TestParser parser = new TestParser();
  58. parser.injectConnectionStrings();
  59. parser.injectLine(":nick JOIN #DMDirc_testing");
  60. final Map<Object, Object> map1 = new HashMap<>();
  61. final Map<Object, Object> map2 = new HashMap<>();
  62. final IRCChannelClientInfo cci = (IRCChannelClientInfo) parser.getClient("nick")
  63. .getChannelClients().get(0);
  64. cci.setMap(map1);
  65. assertSame(map1, cci.getMap());
  66. cci.setMap(map2);
  67. assertSame(map2, cci.getMap());
  68. }
  69. @Test
  70. public void testKick() {
  71. final TestParser parser = new TestParser();
  72. parser.injectConnectionStrings();
  73. parser.injectLine(":nick JOIN #DMDirc_testing");
  74. parser.sentLines.clear();
  75. parser.getClient("nick").getChannelClients().get(0).kick("");
  76. assertEquals(1, parser.sentLines.size());
  77. assertEquals("KICK #DMDirc_testing nick", parser.sentLines.get(0));
  78. parser.sentLines.clear();
  79. parser.getClient("nick").getChannelClients().get(0).kick("booya");
  80. assertEquals(1, parser.sentLines.size());
  81. assertEquals("KICK #DMDirc_testing nick :booya", parser.sentLines.get(0));
  82. }
  83. }