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ů.

ChannelInfoTest.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (c) 2006-2008 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;
  23. import java.util.Arrays;
  24. import java.util.HashMap;
  25. import java.util.Map;
  26. import org.junit.Test;
  27. import static org.junit.Assert.*;
  28. public class ChannelInfoTest extends junit.framework.TestCase {
  29. final ChannelInfo ci = new ChannelInfo(null, "name");
  30. @Test
  31. public void testGetName() {
  32. assertEquals("name", ci.getName());
  33. }
  34. @Test
  35. public void testAddingNames() {
  36. assertTrue(ci.getAddingNames());
  37. ci.setAddingNames(false);
  38. assertFalse(ci.getAddingNames());
  39. }
  40. @Test
  41. public void testMap() {
  42. final Map map = new HashMap();
  43. ci.setMap(map);
  44. assertEquals(map, ci.getMap());
  45. }
  46. @Test
  47. public void testCreateTime() {
  48. ci.setCreateTime(12345l);
  49. assertEquals(12345l, ci.getCreateTime());
  50. }
  51. @Test
  52. public void testTopicTime() {
  53. ci.setTopicTime(12345l);
  54. assertEquals(12345l, ci.getTopicTime());
  55. }
  56. @Test
  57. public void testTopic() {
  58. ci.setTopic("abcdef");
  59. assertEquals("abcdef", ci.getTopic());
  60. }
  61. @Test
  62. public void testSendMessage() {
  63. final TestParser parser = new TestParser();
  64. getChannelInfo(parser).sendMessage("hello");
  65. assertEquals("PRIVMSG #DMDirc_testing :hello", parser.sentLines.get(0));
  66. }
  67. @Test
  68. public void testSendNotice() {
  69. final TestParser parser = new TestParser();
  70. getChannelInfo(parser).sendNotice("hello");
  71. assertEquals("NOTICE #DMDirc_testing :hello", parser.sentLines.get(0));
  72. }
  73. @Test
  74. public void testSendCTCP() {
  75. final TestParser parser = new TestParser();
  76. getChannelInfo(parser).sendCTCP("type", "hello");
  77. assertEquals("PRIVMSG #DMDirc_testing :" + ((char) 1) + "TYPE hello" + ((char) 1),
  78. parser.sentLines.get(0));
  79. }
  80. @Test
  81. public void testSendCTCPEmpty() {
  82. final TestParser parser = new TestParser();
  83. getChannelInfo(parser).sendCTCP("type", "");
  84. assertEquals("PRIVMSG #DMDirc_testing :" + ((char) 1) + "TYPE" + ((char) 1),
  85. parser.sentLines.get(0));
  86. }
  87. @Test
  88. public void testSendAction() {
  89. final TestParser parser = new TestParser();
  90. getChannelInfo(parser).sendAction("moo");
  91. assertEquals("PRIVMSG #DMDirc_testing :" + ((char) 1) + "ACTION moo" + ((char) 1),
  92. parser.sentLines.get(0));
  93. }
  94. @Test
  95. public void testSendCTCPReply() {
  96. final TestParser parser = new TestParser();
  97. getChannelInfo(parser).sendCTCPReply("type", "moo");
  98. assertEquals("NOTICE #DMDirc_testing :" + ((char) 1) + "TYPE moo" + ((char) 1),
  99. parser.sentLines.get(0));
  100. }
  101. @Test
  102. public void testSendCTCPReplyEmpty() {
  103. final TestParser parser = new TestParser();
  104. getChannelInfo(parser).sendCTCPReply("type", "");
  105. assertEquals("NOTICE #DMDirc_testing :" + ((char) 1) + "TYPE" + ((char) 1),
  106. parser.sentLines.get(0));
  107. }
  108. @Test
  109. public void testSendEmptyMessages() {
  110. final TestParser parser = new TestParser();
  111. final ChannelInfo info = getChannelInfo(parser);
  112. info.sendAction("");
  113. info.sendCTCP("", "");
  114. info.sendCTCPReply("", "");
  115. info.sendMessage("");
  116. info.sendNotice("");
  117. assertEquals(0, parser.sentLines.size());
  118. }
  119. private ChannelInfo getChannelInfo(final TestParser parser) {
  120. parser.injectConnectionStrings();
  121. parser.injectLine(":nick JOIN #DMDirc_testing");
  122. parser.sentLines.clear();
  123. return parser.getChannels().iterator().next();
  124. }
  125. }