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.

PluginPreferencesCategoryTest.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (c) 2006-2011 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.plugins.PluginInfo;
  24. import org.junit.BeforeClass;
  25. import org.junit.Test;
  26. import static org.junit.Assert.*;
  27. import static org.mockito.Mockito.*;
  28. public class PluginPreferencesCategoryTest {
  29. private static PluginInfo loaded, unloaded;
  30. private static PreferencesInterface obj;
  31. @BeforeClass
  32. public static void setupClass() {
  33. loaded = mock(PluginInfo.class);
  34. when(loaded.isLoaded()).thenReturn(true);
  35. unloaded = mock(PluginInfo.class);
  36. when(unloaded.isLoaded()).thenReturn(false);
  37. when(unloaded.getNiceName()).thenReturn("nice name");
  38. obj = mock(PreferencesInterface.class);
  39. }
  40. @Test
  41. public void testCtor1() {
  42. final PreferencesCategory category = new PluginPreferencesCategory(loaded,
  43. "unit", "This is a desc.", "icon");
  44. assertEquals("icon", category.getIcon());
  45. assertEquals("This is a desc.", category.getDescription());
  46. assertEquals("unit", category.getTitle());
  47. }
  48. @Test
  49. public void testCtor2() {
  50. final PreferencesCategory category = new PluginPreferencesCategory(loaded,
  51. "unit", "This is a desc.");
  52. assertEquals("This is a desc.", category.getDescription());
  53. assertEquals("unit", category.getTitle());
  54. }
  55. @Test
  56. public void testCtor3() {
  57. final PreferencesCategory category = new PluginPreferencesCategory(loaded,
  58. "unit", "This is a desc.", "icon", obj);
  59. assertEquals("icon", category.getIcon());
  60. assertEquals("This is a desc.", category.getDescription());
  61. assertEquals("unit", category.getTitle());
  62. assertSame(obj, category.getObject());
  63. }
  64. @Test
  65. public void testCtor4() {
  66. final PreferencesCategory category = new PluginPreferencesCategory(loaded,
  67. "unit", "This is a desc.", obj);
  68. assertEquals("This is a desc.", category.getDescription());
  69. assertEquals("unit", category.getTitle());
  70. assertSame(obj, category.getObject());
  71. }
  72. @Test
  73. public void testLoadedWarning() {
  74. final PreferencesCategory category = new PluginPreferencesCategory(loaded, "unit",
  75. "This is a desc.");
  76. assertNull(category.getWarning());
  77. }
  78. @Test
  79. public void testUnloadedWarning() {
  80. final PreferencesCategory category = new PluginPreferencesCategory(unloaded, "unit",
  81. "This is a desc.");
  82. assertTrue(category.getWarning().contains("'nice name'"));
  83. assertTrue(category.getWarning().contains("not currently loaded"));
  84. }
  85. }