Переглянути джерело

Use a mocked IdentdPlugin to fix broken unit tests

tags/0.6.3m1rc1
Chris Smith 15 роки тому
джерело
коміт
6879b0e0f3
1 змінених файлів з 19 додано та 10 видалено
  1. 19
    10
      test/com/dmdirc/addons/identd/IdentClientTest.java

+ 19
- 10
test/com/dmdirc/addons/identd/IdentClientTest.java Переглянути файл

28
 import org.junit.BeforeClass;
28
 import org.junit.BeforeClass;
29
 import org.junit.Test;
29
 import org.junit.Test;
30
 import static org.junit.Assert.*;
30
 import static org.junit.Assert.*;
31
+import static org.mockito.Mockito.*;
31
 
32
 
32
 public class IdentClientTest {
33
 public class IdentClientTest {
33
 
34
 
36
         IdentityManager.load();
37
         IdentityManager.load();
37
     }
38
     }
38
 
39
 
40
+    protected IdentClient getClient() {
41
+        IdentdPlugin plugin = mock(IdentdPlugin.class);
42
+        
43
+        when(plugin.getDomain()).thenReturn("plugin-Identd");
44
+        
45
+        return new IdentClient(null, null, plugin);
46
+    }
47
+
39
     @Test
48
     @Test
40
     public void testInvalidIdent() {
49
     public void testInvalidIdent() {
41
-        final String response = IdentClient.getIdentResponse("invalid request!",
50
+        final String response = getClient().getIdentResponse("invalid request!",
42
                 IdentityManager.getGlobalConfig());
51
                 IdentityManager.getGlobalConfig());
43
         
52
         
44
         assertContains("Illegal requests must result in an ERROR response",
53
         assertContains("Illegal requests must result in an ERROR response",
47
     
56
     
48
     @Test
57
     @Test
49
     public void testQuoting() {
58
     public void testQuoting() {
50
-        final String response = IdentClient.getIdentResponse("in\\valid:invalid",
59
+        final String response = getClient().getIdentResponse("in\\valid:invalid",
51
                 IdentityManager.getGlobalConfig());
60
                 IdentityManager.getGlobalConfig());
52
         
61
         
53
         assertStartsWith("Special chars in illegal requests must be quoted",
62
         assertStartsWith("Special chars in illegal requests must be quoted",
56
     
65
     
57
     @Test
66
     @Test
58
     public void testQuoting2() {
67
     public void testQuoting2() {
59
-        final String response = IdentClient.getIdentResponse("in\\\\valid\\ inv\\:alid",
68
+        final String response = getClient().getIdentResponse("in\\\\valid\\ inv\\:alid",
60
                 IdentityManager.getGlobalConfig());
69
                 IdentityManager.getGlobalConfig());
61
         
70
         
62
         assertStartsWith("Escaped characters in illegal requests shouldn't be doubly-escaped",
71
         assertStartsWith("Escaped characters in illegal requests shouldn't be doubly-escaped",
65
     
74
     
66
     @Test
75
     @Test
67
     public void testNonNumericPort() {
76
     public void testNonNumericPort() {
68
-        final String response = IdentClient.getIdentResponse("abc, def",
77
+        final String response = getClient().getIdentResponse("abc, def",
69
                 IdentityManager.getGlobalConfig());
78
                 IdentityManager.getGlobalConfig());
70
         
79
         
71
         assertContains("Non-numeric ports must result in an ERROR response",
80
         assertContains("Non-numeric ports must result in an ERROR response",
75
     }
84
     }
76
     
85
     
77
     private void doPortTest(final String ports) {
86
     private void doPortTest(final String ports) {
78
-        final String response = IdentClient.getIdentResponse(ports,
87
+        final String response = getClient().getIdentResponse(ports,
79
                 IdentityManager.getGlobalConfig());
88
                 IdentityManager.getGlobalConfig());
80
         
89
         
81
         assertContains("Illegal ports must result in an ERROR response",
90
         assertContains("Illegal ports must result in an ERROR response",
99
         final TestConfigManagerMap tcm = new TestConfigManagerMap();
108
         final TestConfigManagerMap tcm = new TestConfigManagerMap();
100
         tcm.settings.put("plugin-Identd.advanced.alwaysOn", "false");
109
         tcm.settings.put("plugin-Identd.advanced.alwaysOn", "false");
101
         
110
         
102
-        final String response = IdentClient.getIdentResponse("50, 50", tcm);
111
+        final String response = getClient().getIdentResponse("50, 50", tcm);
103
         assertContains("Unknown port requests must return an ERROR response",
112
         assertContains("Unknown port requests must return an ERROR response",
104
                 response, "ERROR");
113
                 response, "ERROR");
105
         assertContains("Unknown port requests must return a NO-USER response",
114
         assertContains("Unknown port requests must return a NO-USER response",
112
         tcm.settings.put("plugin-Identd.advanced.alwaysOn", "true");
121
         tcm.settings.put("plugin-Identd.advanced.alwaysOn", "true");
113
         tcm.settings.put("plugin-Identd.advanced.isHiddenUser", "true");
122
         tcm.settings.put("plugin-Identd.advanced.isHiddenUser", "true");
114
         
123
         
115
-        final String response = IdentClient.getIdentResponse("50, 50", tcm);
124
+        final String response = getClient().getIdentResponse("50, 50", tcm);
116
         assertContains("Hidden requests must return an ERROR response",
125
         assertContains("Hidden requests must return an ERROR response",
117
                 response, "ERROR");
126
                 response, "ERROR");
118
         assertContains("Hidden requests must return a HIDDEN-USER response",
127
         assertContains("Hidden requests must return a HIDDEN-USER response",
129
         tcm.settings.put("plugin-Identd.general.useCustomName", "false");
138
         tcm.settings.put("plugin-Identd.general.useCustomName", "false");
130
         tcm.settings.put("plugin-Identd.general.customName", "");
139
         tcm.settings.put("plugin-Identd.general.customName", "");
131
         
140
         
132
-        final String response = IdentClient.getIdentResponse("50, 50", tcm);
141
+        final String response = getClient().getIdentResponse("50, 50", tcm);
133
         assertContains("Special characters must be quoted in system names",
142
         assertContains("Special characters must be quoted in system names",
134
                 response, "a\\:b\\\\c\\,d");        
143
                 response, "a\\:b\\\\c\\,d");        
135
     }
144
     }
144
         tcm.settings.put("plugin-Identd.general.useCustomName", "true");
153
         tcm.settings.put("plugin-Identd.general.useCustomName", "true");
145
         tcm.settings.put("plugin-Identd.general.customName", "a:b\\c,d");
154
         tcm.settings.put("plugin-Identd.general.customName", "a:b\\c,d");
146
         
155
         
147
-        final String response = IdentClient.getIdentResponse("50, 50", tcm);
156
+        final String response = getClient().getIdentResponse("50, 50", tcm);
148
         assertContains("Special characters must be quoted in custom names",
157
         assertContains("Special characters must be quoted in custom names",
149
                 response, "a\\:b\\\\c\\,d");        
158
                 response, "a\\:b\\\\c\\,d");        
150
     }
159
     }
159
         tcm.settings.put("plugin-Identd.general.useCustomName", "true");
168
         tcm.settings.put("plugin-Identd.general.useCustomName", "true");
160
         tcm.settings.put("plugin-Identd.general.customName", "name");
169
         tcm.settings.put("plugin-Identd.general.customName", "name");
161
         
170
         
162
-        final String response = IdentClient.getIdentResponse("50, 60", tcm);
171
+        final String response = getClient().getIdentResponse("50, 60", tcm);
163
         final String[] bits = response.split(":");
172
         final String[] bits = response.split(":");
164
         
173
         
165
         assertTrue("Responses must include port pair",
174
         assertTrue("Responses must include port pair",

Завантаження…
Відмінити
Зберегти