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.

IdentityTest.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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.config;
  23. import java.util.Properties;
  24. import org.junit.After;
  25. import org.junit.Before;
  26. import org.junit.Test;
  27. import static org.junit.Assert.*;
  28. public class IdentityTest extends junit.framework.TestCase {
  29. private Identity myIdent;
  30. private ConfigTarget target;
  31. @Before
  32. public void setUp() throws Exception {
  33. target = new ConfigTarget();
  34. target.setChannel("#unittest@unittest");
  35. myIdent = Identity.buildIdentity(target);
  36. }
  37. @After
  38. public void tearDown() throws Exception {
  39. myIdent = null;
  40. }
  41. @Test
  42. public void testGetProperties() {
  43. myIdent.setOption("domain", "option", "value");
  44. final Properties props = myIdent.getProperties();
  45. assertEquals(props.getProperty("domain.option"), "value");
  46. myIdent.unsetOption("domain", "option");
  47. }
  48. @Test
  49. public void testGetName() {
  50. final Properties props = myIdent.getProperties();
  51. assertEquals(props.getProperty("identity.name"), myIdent.getName());
  52. }
  53. @Test
  54. public void testIsProfile() {
  55. assertFalse(myIdent.isProfile());
  56. myIdent.setOption("profile", "nickname", "foo");
  57. myIdent.setOption("profile", "realname", "foo");
  58. assertTrue(myIdent.isProfile());
  59. myIdent.unsetOption("profile", "nickname");
  60. myIdent.unsetOption("profile", "realname");
  61. }
  62. @Test
  63. public void testHasOption() {
  64. assertFalse(myIdent.hasOption("has", "option"));
  65. myIdent.setOption("has", "option", "");
  66. assertTrue(myIdent.hasOption("has", "option"));
  67. myIdent.unsetOption("has", "option");
  68. }
  69. @Test
  70. public void testGetOption() {
  71. myIdent.setOption("domain", "option", "value");
  72. final Properties props = myIdent.getProperties();
  73. assertEquals(props.getProperty("domain.option"), myIdent.getOption("domain", "option"));
  74. myIdent.unsetOption("domain", "option");
  75. }
  76. @Test
  77. public void testSetOption() {
  78. final int count = myIdent.getProperties().size();
  79. myIdent.setOption("foo", "bar", "baz");
  80. assertEquals(count + 1, myIdent.getProperties().size());
  81. myIdent.unsetOption("foo", "bar");
  82. }
  83. @Test
  84. public void testRemoveOption() {
  85. final Properties props = myIdent.getProperties();
  86. final int count = props.size();
  87. myIdent.setOption("foo", "bar", "baz");
  88. myIdent.unsetOption("foo", "bar");
  89. assertEquals(count, props.size());
  90. }
  91. @Test
  92. public void testSave() {
  93. myIdent.setOption("foo", "bar", "baz!");
  94. myIdent.save();
  95. myIdent = null;
  96. myIdent = Identity.buildIdentity(target);
  97. assertEquals("baz!", myIdent.getOption("foo", "bar"));
  98. myIdent.unsetOption("foo", "bar");
  99. myIdent.save();
  100. }
  101. @Test
  102. public void testGetTarget() {
  103. assertEquals(target.getData(), myIdent.getTarget().getData());
  104. assertEquals(target.getType(), myIdent.getTarget().getType());
  105. }
  106. @Test
  107. public void testToString() {
  108. assertEquals(myIdent.getOption("identity", "name"), myIdent.getName());
  109. }
  110. }