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.2KB

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