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.

ProcessNickTest.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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.TestIErrorInfo;
  25. import com.dmdirc.harness.parser.TestINickChanged;
  26. import com.dmdirc.parser.interfaces.callbacks.ErrorInfoListener;
  27. import com.dmdirc.parser.interfaces.callbacks.NickChangeListener;
  28. import com.dmdirc.parser.common.CallbackNotFoundException;
  29. import org.junit.Test;
  30. import static org.junit.Assert.*;
  31. public class ProcessNickTest {
  32. @Test
  33. public void testNickSameName() {
  34. final TestParser parser = new TestParser();
  35. final TestINickChanged tinc = new TestINickChanged();
  36. parser.getCallbackManager().addCallback(NickChangeListener.class, tinc);
  37. parser.injectConnectionStrings();
  38. parser.injectLine(":nick JOIN #DMDirc_testing");
  39. parser.injectLine(":nick JOIN #DMDirc_testing2");
  40. parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser @+nick2 nick3");
  41. parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list");
  42. parser.injectLine(":luser!lu@ser.com NICK LUSER");
  43. assertNotNull(parser.getClient("LUSER"));
  44. assertEquals(1, parser.getClient("LUSER").getChannelClients().size());
  45. IRCChannelClientInfo cci = parser.getClient("LUSER").getChannelClients().get(0);
  46. assertEquals(parser.getChannel("#DMDirc_testing"), cci.getChannel());
  47. assertEquals("+", cci.getChanModeStr(true));
  48. assertSame(cci.getClient(), tinc.client);
  49. assertEquals("luser", tinc.oldNick);
  50. }
  51. @Test
  52. public void testNickDifferent() {
  53. final TestParser parser = new TestParser();
  54. parser.injectConnectionStrings();
  55. parser.injectLine(":nick JOIN #DMDirc_testing");
  56. parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser @+nick2 nick3");
  57. parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list");
  58. parser.injectLine(":luser!lu@ser.com NICK foobar");
  59. assertNotNull(parser.getClient("foobar"));
  60. assertFalse(parser.isKnownClient("luser"));
  61. assertEquals(1, parser.getClient("foobar").getChannelClients().size());
  62. IRCChannelClientInfo cci = parser.getClient("foobar").getChannelClients().get(0);
  63. assertEquals(parser.getChannel("#DMDirc_testing"), cci.getChannel());
  64. assertEquals("+", cci.getChanModeStr(true));
  65. }
  66. @Test
  67. public void testOverrideNick() throws CallbackNotFoundException {
  68. final TestParser parser = new TestParser();
  69. final TestIErrorInfo info = new TestIErrorInfo();
  70. parser.getCallbackManager().addCallback(ErrorInfoListener.class, info);
  71. parser.injectConnectionStrings();
  72. parser.injectLine(":nick JOIN #DMDirc_testing");
  73. parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser @+nick2 nick3");
  74. parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list");
  75. parser.injectLine(":luser!lu@ser.com NICK nick3");
  76. assertTrue("Parser should raise an error if a nick change overrides an "
  77. + "existing client", info.error);
  78. }
  79. @Test
  80. public void testUnknownNick() {
  81. final TestParser parser = new TestParser();
  82. final TestINickChanged tinc = new TestINickChanged();
  83. parser.getCallbackManager().addCallback(NickChangeListener.class, tinc);
  84. parser.injectConnectionStrings();
  85. parser.injectLine(":random!lu@ser NICK rand");
  86. assertNull(tinc.client);
  87. assertNull(tinc.oldNick);
  88. }
  89. }