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.

ClientInfoTest.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 java.util.HashMap;
  24. import java.util.Map;
  25. import org.junit.Test;
  26. import static org.junit.Assert.*;
  27. public class ClientInfoTest {
  28. @Test
  29. public void testMap() {
  30. final IRCClientInfo ci = new IRCClientInfo(new IRCParser(), "nick!ident@host");
  31. final Map<Object, Object> map = new HashMap<Object, Object>();
  32. ci.setMap(map);
  33. assertEquals(map, ci.getMap());
  34. }
  35. @Test
  36. public void testFake() {
  37. final IRCClientInfo ci = new IRCClientInfo(new IRCParser(), "nick!ident@host");
  38. assertFalse(ci.isFake());
  39. ci.setFake(true);
  40. assertTrue(ci.isFake());
  41. ci.setFake(false);
  42. assertFalse(ci.isFake());
  43. }
  44. @Test
  45. public void testParseHost() {
  46. final String string1 = ":nick!ident@host";
  47. final String string2 = "nick";
  48. final String string3 = ":nick@host";
  49. assertEquals("nick", IRCClientInfo.parseHost(string1));
  50. assertEquals("nick", IRCClientInfo.parseHost(string2));
  51. assertEquals("nick", IRCClientInfo.parseHost(string3));
  52. }
  53. @Test
  54. public void testParseHostFull() {
  55. final String string1 = ":nick!ident@host";
  56. final String string2 = "nick";
  57. final String string3 = ":nick@host";
  58. assertEquals("nick", IRCClientInfo.parseHostFull(string1)[0]);
  59. assertEquals("ident", IRCClientInfo.parseHostFull(string1)[1]);
  60. assertEquals("host", IRCClientInfo.parseHostFull(string1)[2]);
  61. assertEquals("nick", IRCClientInfo.parseHostFull(string2)[0]);
  62. assertEquals("nick", IRCClientInfo.parseHostFull(string3)[0]);
  63. assertEquals("host", IRCClientInfo.parseHostFull(string3)[2]);
  64. }
  65. @Test
  66. public void testSetUserBits() {
  67. final IRCClientInfo ci = new IRCClientInfo(new IRCParser(), "nick!ident@host");
  68. ci.setUserBits("nick2!ident2@host2", false);
  69. assertEquals("nick", ci.getNickname());
  70. assertEquals("ident2", ci.getUsername());
  71. assertEquals("host2", ci.getHostname());
  72. ci.setUserBits(":nick3@host3", true);
  73. assertEquals("nick3", ci.getNickname());
  74. assertEquals("ident2", ci.getUsername());
  75. assertEquals("host3", ci.getHostname());
  76. }
  77. @Test
  78. public void testToString() {
  79. final IRCClientInfo ci = new IRCClientInfo(new IRCParser(), "nick!ident@host");
  80. assertEquals("nick!ident@host", ci.toString());
  81. }
  82. @Test
  83. public void testAwayState() {
  84. final IRCClientInfo ci = new IRCClientInfo(new IRCParser(), "nick!ident@host");
  85. assertFalse(ci.getAwayState());
  86. ci.setAwayState(true);
  87. assertTrue(ci.getAwayState());
  88. }
  89. @Test
  90. public void testAwayReason() {
  91. final IRCClientInfo ci = new IRCClientInfo(new IRCParser(), "nick!ident@host");
  92. ci.setAwayState(true);
  93. ci.setAwayReason("away reason");
  94. assertEquals("away reason", ci.getAwayReason());
  95. ci.setAwayState(false);
  96. assertEquals("", ci.getAwayReason());
  97. }
  98. @Test
  99. public void testRealName() {
  100. final IRCClientInfo ci = new IRCClientInfo(new IRCParser(), "nick!ident@host");
  101. ci.setRealName("abc def");
  102. assertEquals("abc def", ci.getRealname());
  103. ci.setRealName("abc 123 def");
  104. assertEquals("abc 123 def", ci.getRealname());
  105. }
  106. }