|
@@ -0,0 +1,89 @@
|
|
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
|
+
|
|
24
|
+import java.awt.Color;
|
|
25
|
+import org.junit.Test;
|
|
26
|
+import static org.junit.Assert.*;
|
|
27
|
+
|
|
28
|
+public class ConfigSourceTest extends junit.framework.TestCase {
|
|
29
|
+
|
|
30
|
+ private final MySource s = new MySource();
|
|
31
|
+
|
|
32
|
+ @Test
|
|
33
|
+ public void testGetOption() {
|
|
34
|
+ assertEquals("moo", s.getOption("false", "bar", "moo"));
|
|
35
|
+ assertEquals("bar", s.getOption("true", "bar", "moo"));
|
|
36
|
+ }
|
|
37
|
+
|
|
38
|
+ @Test
|
|
39
|
+ public void testGetColour() {
|
|
40
|
+ assertEquals(Color.RED, s.getOptionColour("false", "moo", Color.RED));
|
|
41
|
+ assertEquals(Color.WHITE, s.getOptionColour("true", "0", Color.RED));
|
|
42
|
+ }
|
|
43
|
+
|
|
44
|
+ @Test
|
|
45
|
+ public void testGetBoolean() {
|
|
46
|
+ assertTrue(s.getOptionBool("true", "true"));
|
|
47
|
+ assertFalse(s.getOptionBool("true", "false"));
|
|
48
|
+ assertTrue(s.getOptionBool("true", "true", false));
|
|
49
|
+ assertTrue(s.getOptionBool("false", "true", true));
|
|
50
|
+ assertFalse(s.getOptionBool("false", "true", false));
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+ @Test
|
|
54
|
+ public void testGetInt() {
|
|
55
|
+ assertEquals(42, s.getOptionInt("false", "moo", 42));
|
|
56
|
+ assertEquals(42, s.getOptionInt("true", "42", 0));
|
|
57
|
+ assertEquals(42, s.getOptionInt("true", "moo", 42));
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ @Test
|
|
61
|
+ public void testGetList() {
|
|
62
|
+ assertTrue(s.getOptionList("false", "moo").isEmpty());
|
|
63
|
+ assertTrue(s.getOptionList("true", "").isEmpty());
|
|
64
|
+ assertTrue(s.getOptionList("true", "\n\n\n").isEmpty());
|
|
65
|
+ assertEquals(4, s.getOptionList("true", "\n\n\na", false).size());
|
|
66
|
+ assertEquals(4, s.getOptionList("true", "a\nb\nc\nd", true).size());
|
|
67
|
+ assertEquals("c", s.getOptionList("true", "a\nb\nc\nd", true).get(2));
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ private class MySource extends ConfigSource {
|
|
71
|
+
|
|
72
|
+ @Override
|
|
73
|
+ public String getOption(String domain, String option) {
|
|
74
|
+ if (Boolean.parseBoolean(domain)) {
|
|
75
|
+ return option;
|
|
76
|
+ } else {
|
|
77
|
+ assertTrue("Requested non-existant option", false);
|
|
78
|
+ return null;
|
|
79
|
+ }
|
|
80
|
+ }
|
|
81
|
+
|
|
82
|
+ @Override
|
|
83
|
+ public boolean hasOption(String domain, String option) {
|
|
84
|
+ return Boolean.parseBoolean(domain);
|
|
85
|
+ }
|
|
86
|
+
|
|
87
|
+ }
|
|
88
|
+
|
|
89
|
+}
|