瀏覽代碼

Added unit test for some PreferencesSetting stuff

git-svn-id: http://svn.dmdirc.com/trunk@3499 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Chris Smith 16 年之前
父節點
當前提交
2755b0f75d
共有 1 個文件被更改,包括 84 次插入0 次删除
  1. 84
    0
      test/com/dmdirc/config/prefs/PreferencesSettingTest.java

+ 84
- 0
test/com/dmdirc/config/prefs/PreferencesSettingTest.java 查看文件

@@ -0,0 +1,84 @@
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.prefs;
23
+
24
+import com.dmdirc.config.prefs.validator.NotEmptyValidator;
25
+import com.dmdirc.config.prefs.validator.PermissiveValidator;
26
+import org.junit.Test;
27
+import static org.junit.Assert.*;
28
+
29
+public class PreferencesSettingTest {
30
+    
31
+    @Test(expected=IllegalArgumentException.class)
32
+    public void testIllegalMultichoice1() {
33
+        new PreferencesSetting(PreferencesType.MULTICHOICE, "domain", 
34
+                "option", "fallback", "title", "helptext");
35
+    }
36
+    
37
+    @Test(expected=IllegalArgumentException.class)
38
+    public void testIllegalMultichoice2() {
39
+        new PreferencesSetting(PreferencesType.MULTICHOICE,
40
+                new PermissiveValidator<String>(), "domain", 
41
+                "option", "fallback", "title", "helptext");
42
+    }
43
+    
44
+    @Test
45
+    public void testNormalConstructor() {
46
+        final PreferencesSetting ps = new PreferencesSetting(PreferencesType.TEXT, "domain", 
47
+                "option", "fallback", "title", "helptext");
48
+        
49
+        assertEquals(PreferencesType.TEXT, ps.getType());
50
+        assertEquals("fallback", ps.getValue());
51
+        assertEquals("title", ps.getTitle());
52
+        assertEquals("helptext", ps.getHelptext());
53
+        assertFalse(ps.isRestartNeeded());
54
+        assertTrue(ps.getValidator() instanceof PermissiveValidator);
55
+    }
56
+    
57
+    @Test
58
+    public void testValidatorConstructor() {
59
+        final PreferencesSetting ps = new PreferencesSetting(PreferencesType.TEXT,
60
+                new NotEmptyValidator(), "domain", 
61
+                "option", "fallback", "title", "helptext");
62
+        
63
+        assertEquals(PreferencesType.TEXT, ps.getType());
64
+        assertEquals("fallback", ps.getValue());
65
+        assertEquals("title", ps.getTitle());
66
+        assertEquals("helptext", ps.getHelptext());
67
+        assertFalse(ps.isRestartNeeded());
68
+        assertTrue(ps.getValidator() instanceof NotEmptyValidator);
69
+    }    
70
+    
71
+    @Test
72
+    public void testRestartNeeded() {
73
+        final PreferencesSetting ps = new PreferencesSetting(PreferencesType.TEXT, "domain", 
74
+                "option", "fallback", "title", "helptext");
75
+        
76
+        assertFalse(ps.isRestartNeeded());
77
+        assertSame(ps, ps.setRestartNeeded());
78
+        assertTrue(ps.isRestartNeeded());
79
+    }
80
+
81
+    public static junit.framework.Test suite() {
82
+        return new junit.framework.JUnit4TestAdapter(PreferencesSettingTest.class);
83
+    }
84
+}

Loading…
取消
儲存