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.

ProcessListModeTest.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.processors;
  23. import com.dmdirc.harness.parser.TestParser;
  24. import com.dmdirc.parser.common.ChannelListModeItem;
  25. import java.util.Collection;
  26. import org.junit.Test;
  27. import static org.junit.Assert.*;
  28. public class ProcessListModeTest {
  29. private void testListModes(final String numeric1, final String numeric2, final char mode) {
  30. final TestParser parser = new TestParser();
  31. parser.injectConnectionStrings();
  32. parser.injectLine(":nick JOIN #D");
  33. parser.injectLine(":server " + numeric1 + " nick #D ban1!ident@.host bansetter1 1001");
  34. parser.injectLine(":server " + numeric1 + " nick #D ban2!*@.host bansetter2 1002");
  35. parser.injectLine(":server " + numeric1 + " nick #D ban3!ident@* bansetter3 1003");
  36. parser.injectLine(":server " + numeric2 + " nick #D :End of Channel Something List");
  37. final Collection<ChannelListModeItem> items
  38. = parser.getChannel("#D").getListMode(mode);
  39. assertEquals(3, items.size());
  40. boolean gotOne = false, gotTwo = false, gotThree = false;
  41. for (ChannelListModeItem item : items) {
  42. if (item.getItem().equals("ban1!ident@.host")) {
  43. assertEquals("bansetter1", item.getOwner());
  44. assertEquals(1001L, item.getTime());
  45. assertFalse(gotOne);
  46. gotOne = true;
  47. } else if (item.getItem().equals("ban2!*@.host")) {
  48. assertEquals("bansetter2", item.getOwner());
  49. assertEquals(1002L, item.getTime());
  50. assertFalse(gotTwo);
  51. gotTwo = true;
  52. } else if (item.toString().equals("ban3!ident@*")) {
  53. assertEquals("bansetter3", item.getOwner());
  54. assertEquals(1003L, item.getTime());
  55. assertFalse(gotThree);
  56. gotThree = true;
  57. }
  58. }
  59. assertTrue(gotOne);
  60. assertTrue(gotTwo);
  61. assertTrue(gotThree);
  62. }
  63. @Test
  64. public void testNormalBans() {
  65. testListModes("367", "368", 'b');
  66. }
  67. @Test
  68. public void testInvexList() {
  69. testListModes("346", "347", 'I');
  70. }
  71. @Test
  72. public void testExemptList() {
  73. testListModes("348", "349", 'e');
  74. }
  75. @Test
  76. public void testReopList() {
  77. testListModes("344", "345", 'R');
  78. }
  79. }