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.

ChannelInfoTest.java 4.7KB

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