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.

ProcessQuitTest.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (c) 2006-2009 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.parser.irc;
  23. import com.dmdirc.harness.parser.TestParser;
  24. import com.dmdirc.harness.parser.TestIQuit;
  25. import com.dmdirc.parser.interfaces.callbacks.ChannelQuitListener;
  26. import com.dmdirc.parser.interfaces.callbacks.QuitListener;
  27. import com.dmdirc.parser.common.CallbackNotFoundException;
  28. import org.junit.Test;
  29. import static org.junit.Assert.*;
  30. public class ProcessQuitTest {
  31. @Test
  32. public void testChannelQuit() throws CallbackNotFoundException {
  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. parser.injectLine(":nick JOIN #DMDirc_testing2");
  39. parser.injectLine(":server 353 nick = #DMDirc_testing2 :@nick +luser2");
  40. parser.injectLine(":server 366 nick #DMDirc_testing2 :End of /NAMES list.");
  41. final TestIQuit test = new TestIQuit();
  42. parser.getCallbackManager().addCallback(ChannelQuitListener.class, test);
  43. assertEquals(2, parser.getChannel("#DMDirc_testing").getChannelClients().size());
  44. parser.injectLine(":luser!foo@barsville QUIT :Bye bye, cruel world");
  45. assertEquals(1, parser.getChannel("#DMDirc_testing").getChannelClients().size());
  46. assertEquals(2, parser.getChannel("#DMDirc_testing2").getChannelClients().size());
  47. assertNotNull(test.channel);
  48. assertNotNull(test.cclient);
  49. assertNotNull(test.reason);
  50. assertEquals(1, test.count);
  51. assertEquals("#DMDirc_testing", test.channel.getName());
  52. assertEquals("luser", test.cclient.getClient().getNickname());
  53. assertEquals("Bye bye, cruel world", test.reason);
  54. }
  55. @Test
  56. public void testGlobalQuit() throws CallbackNotFoundException {
  57. final TestParser parser = new TestParser();
  58. parser.injectConnectionStrings();
  59. parser.injectLine(":nick JOIN #DMDirc_testing");
  60. parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser");
  61. parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list.");
  62. parser.injectLine(":nick JOIN #DMDirc_testing2");
  63. parser.injectLine(":server 353 nick = #DMDirc_testing2 :@nick +luser2");
  64. parser.injectLine(":server 366 nick #DMDirc_testing2 :End of /NAMES list.");
  65. final TestIQuit test = new TestIQuit();
  66. parser.getCallbackManager().addCallback(QuitListener.class, test);
  67. assertEquals(2, parser.getChannel("#DMDirc_testing").getChannelClients().size());
  68. parser.injectLine(":luser!foo@barsville QUIT :Bye bye, cruel world");
  69. assertEquals(1, parser.getChannel("#DMDirc_testing").getChannelClients().size());
  70. assertEquals(2, parser.getChannel("#DMDirc_testing2").getChannelClients().size());
  71. assertNotNull(test.client);
  72. assertNotNull(test.reason);
  73. assertEquals(1, test.count);
  74. assertEquals("luser", test.client.getNickname());
  75. assertEquals("Bye bye, cruel world", test.reason);
  76. }
  77. @Test
  78. public void testEmptyQuit() throws CallbackNotFoundException {
  79. final TestParser parser = new TestParser();
  80. parser.injectConnectionStrings();
  81. parser.injectLine(":nick JOIN #DMDirc_testing");
  82. parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser");
  83. parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list.");
  84. final TestIQuit test = new TestIQuit();
  85. parser.getCallbackManager().addCallback(QuitListener.class, test);
  86. assertEquals(2, parser.getChannel("#DMDirc_testing").getChannelClients().size());
  87. parser.injectLine(":luser!foo@barsville QUIT");
  88. assertEquals(1, parser.getChannel("#DMDirc_testing").getChannelClients().size());
  89. assertNotNull(test.client);
  90. assertNotNull(test.reason);
  91. assertEquals(1, test.count);
  92. assertEquals("luser", test.client.getNickname());
  93. assertEquals("", test.reason);
  94. }
  95. }