|
@@ -29,6 +29,7 @@ import com.dmdirc.interfaces.User;
|
29
|
29
|
import com.dmdirc.interfaces.config.AggregateConfigProvider;
|
30
|
30
|
import com.dmdirc.parser.irc.IRCClientInfo;
|
31
|
31
|
import com.dmdirc.parser.irc.IRCParser;
|
|
32
|
+import com.dmdirc.util.SystemInfo;
|
32
|
33
|
|
33
|
34
|
import java.util.ArrayList;
|
34
|
35
|
import java.util.List;
|
|
@@ -54,6 +55,7 @@ public class IdentClientTest {
|
54
|
55
|
@Mock private User user;
|
55
|
56
|
@Mock private AggregateConfigProvider config;
|
56
|
57
|
@Mock private DMDircMBassador eventBus;
|
|
58
|
+ @Mock private SystemInfo systemInfo;
|
57
|
59
|
|
58
|
60
|
protected IdentClient getClient() {
|
59
|
61
|
final List<Connection> servers = new ArrayList<>();
|
|
@@ -69,7 +71,7 @@ public class IdentClientTest {
|
69
|
71
|
when(user.getNickname()).thenReturn("nickname");
|
70
|
72
|
when(user.getUsername()).thenReturn(Optional.of("username"));
|
71
|
73
|
|
72
|
|
- return new IdentClient(eventBus, null, null, sm, config, "plugin-Identd");
|
|
74
|
+ return new IdentClient(eventBus, null, null, sm, config, "plugin-Identd", systemInfo);
|
73
|
75
|
}
|
74
|
76
|
|
75
|
77
|
@Test
|
|
@@ -156,6 +158,8 @@ public class IdentClientTest {
|
156
|
158
|
when(acp.getOption("plugin-Identd", "advanced.customSystem")).thenReturn("a:b\\c,d");
|
157
|
159
|
when(acp.getOptionBool("plugin-Identd", "general.useCustomName")).thenReturn(false);
|
158
|
160
|
when(acp.getOption("plugin-Identd", "general.customName")).thenReturn("");
|
|
161
|
+ when(systemInfo.getProperty("user.name")).thenReturn("test");
|
|
162
|
+ when(systemInfo.getProperty("os.name")).thenReturn("test");
|
159
|
163
|
|
160
|
164
|
final String response = getClient().getIdentResponse("50, 50", acp);
|
161
|
165
|
assertContains("Special characters must be quoted in system names",
|
|
@@ -170,6 +174,8 @@ public class IdentClientTest {
|
170
|
174
|
when(acp.getOption("plugin-Identd", "advanced.customSystem")).thenReturn("");
|
171
|
175
|
when(acp.getOptionBool("plugin-Identd", "general.useCustomName")).thenReturn(true);
|
172
|
176
|
when(acp.getOption("plugin-Identd", "general.customName")).thenReturn("a:b\\c,d");
|
|
177
|
+ when(systemInfo.getProperty("user.name")).thenReturn("test");
|
|
178
|
+ when(systemInfo.getProperty("os.name")).thenReturn("test");
|
173
|
179
|
|
174
|
180
|
final String response = getClient().getIdentResponse("50, 50", acp);
|
175
|
181
|
assertContains("Special characters must be quoted in custom names",
|
|
@@ -184,6 +190,8 @@ public class IdentClientTest {
|
184
|
190
|
when(acp.getOption("plugin-Identd", "advanced.customSystem")).thenReturn("system");
|
185
|
191
|
when(acp.getOptionBool("plugin-Identd", "general.useCustomName")).thenReturn(true);
|
186
|
192
|
when(acp.getOption("plugin-Identd", "general.customName")).thenReturn("name");
|
|
193
|
+ when(systemInfo.getProperty("user.name")).thenReturn("test");
|
|
194
|
+ when(systemInfo.getProperty("os.name")).thenReturn("test");
|
187
|
195
|
|
188
|
196
|
final String response = getClient().getIdentResponse("50, 60", acp);
|
189
|
197
|
final String[] bits = response.split(":");
|
|
@@ -200,8 +208,8 @@ public class IdentClientTest {
|
200
|
208
|
public void testOSWindows() {
|
201
|
209
|
when(acp.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
202
|
210
|
when(acp.getOptionBool("plugin-Identd", "advanced.useCustomSystem")).thenReturn(false);
|
203
|
|
- System.setProperty("user.name", "test");
|
204
|
|
- System.setProperty("os.name", "windows");
|
|
211
|
+ when(systemInfo.getProperty("user.name")).thenReturn("test");
|
|
212
|
+ when(systemInfo.getProperty("os.name")).thenReturn("windows");
|
205
|
213
|
|
206
|
214
|
final String response = getClient().getIdentResponse("50, 50", acp);
|
207
|
215
|
assertEquals("50 , 50 : USERID : WIN32 : test", response);
|
|
@@ -211,8 +219,8 @@ public class IdentClientTest {
|
211
|
219
|
public void testOSMac() {
|
212
|
220
|
when(acp.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
213
|
221
|
when(acp.getOptionBool("plugin-Identd", "advanced.useCustomSystem")).thenReturn(false);
|
214
|
|
- System.setProperty("user.name", "test");
|
215
|
|
- System.setProperty("os.name", "mac");
|
|
222
|
+ when(systemInfo.getProperty("user.name")).thenReturn("test");
|
|
223
|
+ when(systemInfo.getProperty("os.name")).thenReturn("mac");
|
216
|
224
|
|
217
|
225
|
final String response = getClient().getIdentResponse("50, 50", acp);
|
218
|
226
|
assertEquals("50 , 50 : USERID : MACOS : test", response);
|
|
@@ -222,8 +230,8 @@ public class IdentClientTest {
|
222
|
230
|
public void testOSLinux() {
|
223
|
231
|
when(acp.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
224
|
232
|
when(acp.getOptionBool("plugin-Identd", "advanced.useCustomSystem")).thenReturn(false);
|
225
|
|
- System.setProperty("user.name", "test");
|
226
|
|
- System.setProperty("os.name", "linux");
|
|
233
|
+ when(systemInfo.getProperty("user.name")).thenReturn("test");
|
|
234
|
+ when(systemInfo.getProperty("os.name")).thenReturn("linux");
|
227
|
235
|
|
228
|
236
|
final String response = getClient().getIdentResponse("50, 50", acp);
|
229
|
237
|
assertEquals("50 , 50 : USERID : UNIX : test", response);
|
|
@@ -233,8 +241,8 @@ public class IdentClientTest {
|
233
|
241
|
public void testOSBSD() {
|
234
|
242
|
when(acp.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
235
|
243
|
when(acp.getOptionBool("plugin-Identd", "advanced.useCustomSystem")).thenReturn(false);
|
236
|
|
- System.setProperty("user.name", "test");
|
237
|
|
- System.setProperty("os.name", "bsd");
|
|
244
|
+ when(systemInfo.getProperty("user.name")).thenReturn("test");
|
|
245
|
+ when(systemInfo.getProperty("os.name")).thenReturn("bsd");
|
238
|
246
|
|
239
|
247
|
final String response = getClient().getIdentResponse("50, 50", acp);
|
240
|
248
|
assertEquals("50 , 50 : USERID : UNIX-BSD : test", response);
|
|
@@ -244,8 +252,8 @@ public class IdentClientTest {
|
244
|
252
|
public void testOSOS2() {
|
245
|
253
|
when(acp.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
246
|
254
|
when(acp.getOptionBool("plugin-Identd", "advanced.useCustomSystem")).thenReturn(false);
|
247
|
|
- System.setProperty("user.name", "test");
|
248
|
|
- System.setProperty("os.name", "os/2");
|
|
255
|
+ when(systemInfo.getProperty("user.name")).thenReturn("test");
|
|
256
|
+ when(systemInfo.getProperty("os.name")).thenReturn("os/2");
|
249
|
257
|
|
250
|
258
|
final String response = getClient().getIdentResponse("50, 50", acp);
|
251
|
259
|
assertEquals("50 , 50 : USERID : OS/2 : test", response);
|
|
@@ -255,8 +263,8 @@ public class IdentClientTest {
|
255
|
263
|
public void testOSUnix() {
|
256
|
264
|
when(acp.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
257
|
265
|
when(acp.getOptionBool("plugin-Identd", "advanced.useCustomSystem")).thenReturn(false);
|
258
|
|
- System.setProperty("user.name", "test");
|
259
|
|
- System.setProperty("os.name", "unix");
|
|
266
|
+ when(systemInfo.getProperty("user.name")).thenReturn("test");
|
|
267
|
+ when(systemInfo.getProperty("os.name")).thenReturn("unix");
|
260
|
268
|
|
261
|
269
|
final String response = getClient().getIdentResponse("50, 50", acp);
|
262
|
270
|
assertEquals("50 , 50 : USERID : UNIX : test", response);
|
|
@@ -266,8 +274,8 @@ public class IdentClientTest {
|
266
|
274
|
public void testOSIrix() {
|
267
|
275
|
when(acp.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
268
|
276
|
when(acp.getOptionBool("plugin-Identd", "advanced.useCustomSystem")).thenReturn(false);
|
269
|
|
- System.setProperty("user.name", "test");
|
270
|
|
- System.setProperty("os.name", "irix");
|
|
277
|
+ when(systemInfo.getProperty("user.name")).thenReturn("test");
|
|
278
|
+ when(systemInfo.getProperty("os.name")).thenReturn("irix");
|
271
|
279
|
|
272
|
280
|
final String response = getClient().getIdentResponse("50, 50", acp);
|
273
|
281
|
assertEquals("50 , 50 : USERID : IRIX : test", response);
|
|
@@ -277,19 +285,8 @@ public class IdentClientTest {
|
277
|
285
|
public void testOSUnknown() {
|
278
|
286
|
when(acp.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
279
|
287
|
when(acp.getOptionBool("plugin-Identd", "advanced.useCustomSystem")).thenReturn(false);
|
280
|
|
- System.setProperty("user.name", "test");
|
281
|
|
- System.setProperty("os.name", "test");
|
282
|
|
-
|
283
|
|
- final String response = getClient().getIdentResponse("50, 50", acp);
|
284
|
|
- assertEquals("50 , 50 : USERID : UNKNOWN : test", response);
|
285
|
|
- }
|
286
|
|
-
|
287
|
|
- @Test
|
288
|
|
- public void testNameSystem() {
|
289
|
|
- when(acp.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
290
|
|
- when(acp.getOptionBool("plugin-Identd", "advanced.useCustomSystem")).thenReturn(false);
|
291
|
|
- System.setProperty("user.name", "test");
|
292
|
|
- System.setProperty("os.name", "test");
|
|
288
|
+ when(systemInfo.getProperty("user.name")).thenReturn("test");
|
|
289
|
+ when(systemInfo.getProperty("os.name")).thenReturn("test");
|
293
|
290
|
|
294
|
291
|
final String response = getClient().getIdentResponse("50, 50", acp);
|
295
|
292
|
assertEquals("50 , 50 : USERID : UNKNOWN : test", response);
|
|
@@ -300,8 +297,8 @@ public class IdentClientTest {
|
300
|
297
|
when(acp.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
301
|
298
|
when(acp.getOptionBool("plugin-Identd", "general.useCustomName")).thenReturn(true);
|
302
|
299
|
when(acp.getOption("plugin-Identd", "general.customName")).thenReturn("name");
|
303
|
|
- System.setProperty("user.name", "test");
|
304
|
|
- System.setProperty("os.name", "test");
|
|
300
|
+ when(systemInfo.getProperty("user.name")).thenReturn("test");
|
|
301
|
+ when(systemInfo.getProperty("os.name")).thenReturn("test");
|
305
|
302
|
|
306
|
303
|
final String response = getClient().getIdentResponse("50, 50", acp);
|
307
|
304
|
assertEquals("50 , 50 : USERID : UNKNOWN : name", response);
|
|
@@ -310,8 +307,8 @@ public class IdentClientTest {
|
310
|
307
|
@Test
|
311
|
308
|
public void testNameNickname() {
|
312
|
309
|
when(acp.getOptionBool("plugin-Identd", "general.useNickname")).thenReturn(true);
|
313
|
|
- System.setProperty("user.name", "test");
|
314
|
|
- System.setProperty("os.name", "test");
|
|
310
|
+ when(systemInfo.getProperty("user.name")).thenReturn("test");
|
|
311
|
+ when(systemInfo.getProperty("os.name")).thenReturn("test");
|
315
|
312
|
|
316
|
313
|
final String response = getClient().getIdentResponse("60, 50", acp);
|
317
|
314
|
assertEquals("60 , 50 : USERID : UNKNOWN : nickname", response);
|
|
@@ -320,16 +317,16 @@ public class IdentClientTest {
|
320
|
317
|
@Test
|
321
|
318
|
public void testNameUsername() {
|
322
|
319
|
when(acp.getOptionBool("plugin-Identd", "general.useUsername")).thenReturn(true);
|
323
|
|
- System.setProperty("user.name", "test");
|
324
|
|
- System.setProperty("os.name", "test");
|
|
320
|
+ when(systemInfo.getProperty("user.name")).thenReturn("test");
|
|
321
|
+ when(systemInfo.getProperty("os.name")).thenReturn("test");
|
325
|
322
|
|
326
|
323
|
final String response = getClient().getIdentResponse("60, 50", acp);
|
327
|
324
|
assertEquals("60 , 50 : USERID : UNKNOWN : username", response);
|
328
|
325
|
}
|
329
|
326
|
|
330
|
327
|
private static void assertContains(final String msg, final String haystack,
|
331
|
|
- final String needle) {
|
332
|
|
- assertTrue(msg, haystack.indexOf(needle) > -1);
|
|
328
|
+ final CharSequence needle) {
|
|
329
|
+ assertTrue(msg, haystack.contains(needle));
|
333
|
330
|
}
|
334
|
331
|
|
335
|
332
|
private static void assertStartsWith(final String msg, final String haystack,
|