Преглед на файлове

Make ConfigManager package private.

Change-Id: I751cbc2354ddb3ea9a431d5b85eed72d9764fed9
Reviewed-on: http://gerrit.dmdirc.com/3081
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.8rc1
Chris Smith преди 10 години
родител
ревизия
def43bc05b

+ 4
- 3
src/com/dmdirc/config/ConfigManager.java Целия файл

@@ -43,7 +43,7 @@ import org.slf4j.LoggerFactory;
43 43
 /**
44 44
  * The config manager manages the various config sources for each entity.
45 45
  */
46
-public class ConfigManager extends BaseConfigProvider implements ConfigChangeListener,
46
+class ConfigManager extends BaseConfigProvider implements ConfigChangeListener,
47 47
         ConfigProviderListener, AggregateConfigProvider {
48 48
 
49 49
     private static final org.slf4j.Logger log = LoggerFactory.getLogger(ConfigManager.class);
@@ -83,7 +83,7 @@ public class ConfigManager extends BaseConfigProvider implements ConfigChangeLis
83 83
      * @param server The name of the server for this manager
84 84
      * @since 0.6.3
85 85
      */
86
-    public ConfigManager(final String protocol, final String ircd,
86
+    ConfigManager(final String protocol, final String ircd,
87 87
             final String network, final String server) {
88 88
         this(protocol, ircd, network, server, "<Unknown>");
89 89
     }
@@ -98,7 +98,7 @@ public class ConfigManager extends BaseConfigProvider implements ConfigChangeLis
98 98
      * @param channel The name of the channel for this manager
99 99
      * @since 0.6.3
100 100
      */
101
-    public ConfigManager(final String protocol, final String ircd,
101
+    ConfigManager(final String protocol, final String ircd,
102 102
             final String network, final String server, final String channel) {
103 103
         final String chanName = channel + "@" + network;
104 104
 
@@ -121,6 +121,7 @@ public class ConfigManager extends BaseConfigProvider implements ConfigChangeLis
121 121
         IdentityManager.getIdentityManager().registerIdentityListener(this);
122 122
     }
123 123
 
124
+    @Override
124 125
     public ConfigBinder getBinder() {
125 126
         return binder;
126 127
     }

+ 0
- 57
test/com/dmdirc/harness/TestConfigManagerMap.java Целия файл

@@ -1,57 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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
-
23
-package com.dmdirc.harness;
24
-
25
-import com.dmdirc.config.ConfigManager;
26
-import com.dmdirc.util.validators.Validator;
27
-
28
-import java.util.HashMap;
29
-import java.util.Map;
30
-
31
-public class TestConfigManagerMap extends ConfigManager {
32
-    private static final long serialVersionUID = 3604727894041756961L;
33
-
34
-    public final Map<String, String> settings = new HashMap<>();
35
-
36
-    public TestConfigManagerMap() {
37
-        super("", "", "", "");
38
-    }
39
-
40
-    @Override
41
-    public String getOption(String domain, String option) {
42
-        if (settings.containsKey(domain + "." + option)) {
43
-            return settings.get(domain + "." + option);
44
-        } else {
45
-            return super.getOption(domain, option);
46
-        }
47
-    }
48
-
49
-    @Override
50
-    public boolean hasOption(String domain, String option, Validator<String> validator) {
51
-        if (settings.containsKey(domain + "." + option)) {
52
-            return true;
53
-        } else {
54
-            return super.hasOption(domain, option, validator);
55
-        }
56
-    }
57
-}

+ 0
- 44
test/com/dmdirc/harness/TestConfigManagerOptionToggle.java Целия файл

@@ -1,44 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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
-
23
-package com.dmdirc.harness;
24
-
25
-import com.dmdirc.config.ConfigManager;
26
-import com.dmdirc.util.validators.Validator;
27
-
28
-public class TestConfigManagerOptionToggle extends ConfigManager {
29
-    private static final long serialVersionUID = 8078917248288638755L;
30
-
31
-    public TestConfigManagerOptionToggle() {
32
-        super(null, null, null, null);
33
-    }
34
-
35
-    @Override
36
-    public String getOption(String domain, String option, Validator<String> validator) {
37
-        return option.substring(1);
38
-    }
39
-
40
-    @Override
41
-    public boolean hasOption(String domain, String option, Validator<String> validator) {
42
-        return option.charAt(0) == '1';
43
-    }
44
-}

+ 25
- 27
test/com/dmdirc/ui/messages/FormatterTest.java Целия файл

@@ -21,68 +21,66 @@
21 21
  */
22 22
 package com.dmdirc.ui.messages;
23 23
 
24
-import com.dmdirc.config.ConfigManager;
25
-import com.dmdirc.config.IdentityManager;
26
-import com.dmdirc.harness.TestConfigManagerOptionToggle;
27
-import com.dmdirc.interfaces.config.ConfigProvider;
28
-
29
-import java.util.Collections;
24
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
30 25
 
31 26
 import org.junit.Before;
32 27
 import org.junit.Test;
33 28
 import org.junit.runner.RunWith;
34 29
 import org.mockito.Mock;
30
+import org.mockito.invocation.InvocationOnMock;
35 31
 import org.mockito.runners.MockitoJUnitRunner;
32
+import org.mockito.stubbing.Answer;
36 33
 
37 34
 import static org.junit.Assert.*;
38 35
 import static org.mockito.Matchers.any;
36
+import static org.mockito.Matchers.startsWith;
39 37
 import static org.mockito.Mockito.when;
40 38
 
41 39
 @RunWith(MockitoJUnitRunner.class)
42 40
 public class FormatterTest {
43 41
 
44
-    private TestConfigManagerOptionToggle mcm;
45
-
46
-    @Mock private IdentityManager identityManager;
42
+    @Mock private AggregateConfigProvider configProvider;
47 43
 
48 44
     @Before
49 45
     public void setup() {
50
-        IdentityManager.setIdentityManager(identityManager);
51
-        when(identityManager.getIdentitiesForManager(any(ConfigManager.class)))
52
-                .thenReturn(Collections.<ConfigProvider>emptyList());
53
-
54
-        mcm = new TestConfigManagerOptionToggle();
46
+        when(configProvider.hasOptionString(any(String.class), startsWith("1"))).thenReturn(true);
47
+        when(configProvider.getOption(any(String.class), startsWith("1"))).thenAnswer(new Answer<String> () {
48
+            @Override
49
+            public String answer(final InvocationOnMock invocation) throws Throwable {
50
+                return invocation.getArguments()[1].toString().substring(1);
51
+            }
52
+        });
55 53
     }
56 54
 
57 55
     @Test
58 56
     public void testBasicFormats() {
59
-        assertEquals("Hello!", Formatter.formatMessage(mcm, "1%1$s", "Hello!"));
60
-        assertEquals("Hello!", Formatter.formatMessage(mcm, "1%1$s", "Hello!", "Moo!", "Bar!"));
61
-        assertTrue(Formatter.formatMessage(mcm, "0%1$s", "Hello!")
57
+        assertEquals("Hello!", Formatter.formatMessage(configProvider, "1%1$s", "Hello!"));
58
+        assertEquals("Hello!", Formatter.formatMessage(configProvider, "1%1$s", "Hello!", "Moo!", "Bar!"));
59
+        assertTrue(Formatter.formatMessage(configProvider, "0%1$s", "Hello!")
62 60
                 .toLowerCase().indexOf("no format string") > -1);
63
-        assertTrue(Formatter.formatMessage(mcm, "1%5$s", "Hello!")
61
+        assertTrue(Formatter.formatMessage(configProvider, "1%5$s", "Hello!")
64 62
                 .toLowerCase().indexOf("invalid format string") > -1);
65
-        assertTrue(Formatter.formatMessage(mcm, "1%1$Z", "Hello!")
63
+        assertTrue(Formatter.formatMessage(configProvider, "1%1$Z", "Hello!")
66 64
                 .toLowerCase().indexOf("invalid format string") > -1);
67 65
     }
68 66
 
69 67
     @Test
70 68
     public void testCasting() {
71
-        assertEquals("H", Formatter.formatMessage(mcm, "1%1$c", "Hello!"));
72
-        assertEquals("10", Formatter.formatMessage(mcm, "1%1$d", "10"));
73
-        assertEquals("111999", Formatter.formatMessage(mcm, "1%1$s", "111999"));
69
+        assertEquals("H", Formatter.formatMessage(configProvider, "1%1$c", "Hello!"));
70
+        assertEquals("10", Formatter.formatMessage(configProvider, "1%1$d", "10"));
71
+        assertEquals("111999", Formatter.formatMessage(configProvider, "1%1$s", "111999"));
74 72
     }
75 73
 
76 74
     @Test
77 75
     public void testCaching() {
78
-        assertEquals("H", Formatter.formatMessage(mcm, "1%1$C", "Hello!"));
79
-        assertEquals("H", Formatter.formatMessage(mcm, "1%1$C", "Hello!", 123, null));
80
-        assertEquals("HELLO!", Formatter.formatMessage(mcm, "1%1$S", "Hello!", 123, null));
81
-        assertEquals("HELLO!", Formatter.formatMessage(mcm, "1%1$S", "Hello!"));
76
+        assertEquals("H", Formatter.formatMessage(configProvider, "1%1$C", "Hello!"));
77
+        assertEquals("H", Formatter.formatMessage(configProvider, "1%1$C", "Hello!", 123, null));
78
+        assertEquals("HELLO!", Formatter.formatMessage(configProvider, "1%1$S", "Hello!", 123, null));
79
+        assertEquals("HELLO!", Formatter.formatMessage(configProvider, "1%1$S", "Hello!"));
82 80
     }
83 81
 
84 82
     @Test
85 83
     public void testFormatDuration() {
86
-        assertEquals("1 minute, 1 second", Formatter.formatMessage(mcm, "1%1$u", "61"));
84
+        assertEquals("1 minute, 1 second", Formatter.formatMessage(configProvider, "1%1$u", "61"));
87 85
     }
88 86
 }

Loading…
Отказ
Запис