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

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,6 +28,7 @@ import com.dmdirc.config.IdentityManager;
28 28
 import org.junit.BeforeClass;
29 29
 import org.junit.Test;
30 30
 import static org.junit.Assert.*;
31
+import static org.mockito.Mockito.*;
31 32
 
32 33
 public class IdentClientTest {
33 34
 
@@ -36,9 +37,17 @@ public class IdentClientTest {
36 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 48
     @Test
40 49
     public void testInvalidIdent() {
41
-        final String response = IdentClient.getIdentResponse("invalid request!",
50
+        final String response = getClient().getIdentResponse("invalid request!",
42 51
                 IdentityManager.getGlobalConfig());
43 52
         
44 53
         assertContains("Illegal requests must result in an ERROR response",
@@ -47,7 +56,7 @@ public class IdentClientTest {
47 56
     
48 57
     @Test
49 58
     public void testQuoting() {
50
-        final String response = IdentClient.getIdentResponse("in\\valid:invalid",
59
+        final String response = getClient().getIdentResponse("in\\valid:invalid",
51 60
                 IdentityManager.getGlobalConfig());
52 61
         
53 62
         assertStartsWith("Special chars in illegal requests must be quoted",
@@ -56,7 +65,7 @@ public class IdentClientTest {
56 65
     
57 66
     @Test
58 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 69
                 IdentityManager.getGlobalConfig());
61 70
         
62 71
         assertStartsWith("Escaped characters in illegal requests shouldn't be doubly-escaped",
@@ -65,7 +74,7 @@ public class IdentClientTest {
65 74
     
66 75
     @Test
67 76
     public void testNonNumericPort() {
68
-        final String response = IdentClient.getIdentResponse("abc, def",
77
+        final String response = getClient().getIdentResponse("abc, def",
69 78
                 IdentityManager.getGlobalConfig());
70 79
         
71 80
         assertContains("Non-numeric ports must result in an ERROR response",
@@ -75,7 +84,7 @@ public class IdentClientTest {
75 84
     }
76 85
     
77 86
     private void doPortTest(final String ports) {
78
-        final String response = IdentClient.getIdentResponse(ports,
87
+        final String response = getClient().getIdentResponse(ports,
79 88
                 IdentityManager.getGlobalConfig());
80 89
         
81 90
         assertContains("Illegal ports must result in an ERROR response",
@@ -99,7 +108,7 @@ public class IdentClientTest {
99 108
         final TestConfigManagerMap tcm = new TestConfigManagerMap();
100 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 112
         assertContains("Unknown port requests must return an ERROR response",
104 113
                 response, "ERROR");
105 114
         assertContains("Unknown port requests must return a NO-USER response",
@@ -112,7 +121,7 @@ public class IdentClientTest {
112 121
         tcm.settings.put("plugin-Identd.advanced.alwaysOn", "true");
113 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 125
         assertContains("Hidden requests must return an ERROR response",
117 126
                 response, "ERROR");
118 127
         assertContains("Hidden requests must return a HIDDEN-USER response",
@@ -129,7 +138,7 @@ public class IdentClientTest {
129 138
         tcm.settings.put("plugin-Identd.general.useCustomName", "false");
130 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 142
         assertContains("Special characters must be quoted in system names",
134 143
                 response, "a\\:b\\\\c\\,d");        
135 144
     }
@@ -144,7 +153,7 @@ public class IdentClientTest {
144 153
         tcm.settings.put("plugin-Identd.general.useCustomName", "true");
145 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 157
         assertContains("Special characters must be quoted in custom names",
149 158
                 response, "a\\:b\\\\c\\,d");        
150 159
     }
@@ -159,7 +168,7 @@ public class IdentClientTest {
159 168
         tcm.settings.put("plugin-Identd.general.useCustomName", "true");
160 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 172
         final String[] bits = response.split(":");
164 173
         
165 174
         assertTrue("Responses must include port pair",

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