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.

PreferencesCategoryTest.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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.config.prefs;
  23. import com.dmdirc.harness.TestChangeListener;
  24. import java.util.List;
  25. import org.junit.Test;
  26. import static org.junit.Assert.*;
  27. public class PreferencesCategoryTest {
  28. @Test
  29. public void testInline() {
  30. final PreferencesCategory category = new PreferencesCategory("unit", "test");
  31. assertFalse(category.isInline());
  32. assertSame(category, category.setInline());
  33. assertTrue(category.isInline());
  34. }
  35. @Test
  36. public void testInlineBefore() {
  37. final PreferencesCategory category = new PreferencesCategory("unit", "test");
  38. assertTrue(category.isInlineBefore());
  39. assertSame(category, category.setInlineAfter());
  40. assertFalse(category.isInlineBefore());
  41. }
  42. @Test(expected=IllegalArgumentException.class)
  43. public void testAddWithObject() {
  44. final PreferencesCategory category = new PreferencesCategory("unit", "test",
  45. new PreferencesInterface() {
  46. public void save() {
  47. // Do nothing
  48. }
  49. });
  50. category.addSetting(null);
  51. }
  52. @Test(expected=IllegalArgumentException.class)
  53. public void testInlineAdding() {
  54. final PreferencesCategory category1 = new PreferencesCategory("unit", "test");
  55. final PreferencesCategory category2 = new PreferencesCategory("unit", "test");
  56. category1.setInline();
  57. category1.addSubCategory(category2);
  58. }
  59. @Test
  60. public void testDescription() {
  61. final PreferencesCategory category = new PreferencesCategory("unit", "This is a desc.");
  62. assertEquals("This is a desc.", category.getDescription());
  63. }
  64. @Test
  65. public void testGetSettings() {
  66. final PreferencesCategory category = new PreferencesCategory("unit", "test");
  67. final List<PreferencesSetting> settings1 = category.getSettings();
  68. final List<PreferencesSetting> settings2 = category.getSettings();
  69. assertSame(settings1, settings2);
  70. }
  71. @Test
  72. public void testSelectionListener() {
  73. final PreferencesCategory category = new PreferencesCategory("unit", "test");
  74. final TestChangeListener test = new TestChangeListener();
  75. category.addChangeListener(test);
  76. category.fireCategorySelected();
  77. category.removeChangeListener(test);
  78. category.fireCategorySelected();
  79. assertEquals(1, test.selected);
  80. assertEquals(0, test.deselected);
  81. assertSame(category, test.cat);
  82. }
  83. @Test
  84. public void testDeSelectionListener() {
  85. final PreferencesCategory category = new PreferencesCategory("unit", "test");
  86. final TestChangeListener test = new TestChangeListener();
  87. category.addChangeListener(test);
  88. category.fireCategoryDeselected();
  89. category.removeChangeListener(test);
  90. category.fireCategoryDeselected();
  91. assertEquals(0, test.selected);
  92. assertEquals(1, test.deselected);
  93. assertSame(category, test.cat);
  94. }
  95. }