Browse Source

Split the parser tests up a bit

Change-Id: I152811c41ad338412a878b2dcb8cbec19e3eb115
Reviewed-on: http://gerrit.dmdirc.com/640
Automatic-Compile: Shane Mc Cormack <shane@dmdirc.com>
Reviewed-by: Shane Mc Cormack <shane@dmdirc.com>
tags/0.6.3
Chris Smith 14 years ago
parent
commit
b86cd763a3

+ 3
- 149
test/com/dmdirc/parser/irc/IRCParserTest.java View File

@@ -23,7 +23,6 @@
23 23
 package com.dmdirc.parser.irc;
24 24
 
25 25
 import com.dmdirc.parser.common.MyInfo;
26
-import com.dmdirc.parser.common.ChannelListModeItem;
27 26
 import com.dmdirc.parser.common.ParserError;
28 27
 import com.dmdirc.harness.parser.TestParser;
29 28
 import com.dmdirc.parser.interfaces.Parser;
@@ -35,15 +34,11 @@ import com.dmdirc.parser.interfaces.callbacks.ConnectErrorListener;
35 34
 import com.dmdirc.parser.interfaces.callbacks.ErrorInfoListener;
36 35
 import com.dmdirc.parser.interfaces.callbacks.NumericListener;
37 36
 import com.dmdirc.parser.interfaces.callbacks.Post005Listener;
38
-import com.dmdirc.parser.interfaces.callbacks.PrivateActionListener;
39
-import com.dmdirc.parser.interfaces.callbacks.PrivateCtcpListener;
40
-import com.dmdirc.parser.interfaces.callbacks.PrivateMessageListener;
41 37
 import com.dmdirc.parser.interfaces.callbacks.ServerErrorListener;
42 38
 
43 39
 import java.net.URI;
44 40
 import java.net.URISyntaxException;
45 41
 import java.util.Arrays;
46
-import java.util.Collection;
47 42
 
48 43
 import javax.net.ssl.TrustManager;
49 44
 
@@ -55,20 +50,11 @@ public class IRCParserTest {
55 50
 
56 51
     private static interface TestCallback extends CallbackInterface { }
57 52
 
58
-    @Test
53
+    @Test(expected=CallbackNotFoundException.class)
59 54
     public void testIssue42() {
60 55
         // Invalid callback names are silently ignored instead of raising exceptions
61
-        
62
-        boolean res = false;
63
-
64
-        try {
65
-            final IRCParser myParser = new IRCParser();
66
-            myParser.getCallbackManager().addCallback(TestCallback.class, mock(TestCallback.class));
67
-        } catch (CallbackNotFoundException ex) {
68
-            res = true;
69
-        }
70
-
71
-        assertTrue("addCallback() should throw exception for non-existant callbacks", res);
56
+        final IRCParser myParser = new IRCParser();
57
+        myParser.getCallbackManager().addCallback(TestCallback.class, mock(TestCallback.class));
72 58
     }
73 59
 
74 60
     @Test
@@ -85,21 +71,6 @@ public class IRCParserTest {
85 71
 
86 72
         verify(error, never()).onErrorInfo(same(myParser), (ParserError) anyObject());
87 73
     }
88
-    
89
-    @Test
90
-    public void testProxyPortWithBindIP() {
91
-        final ConnectErrorListener tice = mock(ConnectErrorListener.class);
92
-        final ServerInfo si = new ServerInfo();
93
-        si.setProxyPort(155555);
94
-        si.setUseSocks(true);
95
-        
96
-        final IRCParser myParser = new IRCParser(si);
97
-        myParser.getCallbackManager().addCallback(ConnectErrorListener.class, tice);
98
-        myParser.setBindIP("0.0.0.0");
99
-        myParser.run();
100
-
101
-        verify(tice).onConnectError(same(myParser), (ParserError) anyObject());
102
-    }
103 74
 
104 75
     @Test
105 76
     public void testTokeniser() {
@@ -350,123 +321,6 @@ public class IRCParserTest {
350 321
         assertTrue(Arrays.equals(new TrustManager[0], parser.getTrustManager()));
351 322
     }
352 323
 
353
-    @Test
354
-    public void testPrivateMessage() throws CallbackNotFoundException {
355
-        final TestParser parser = new TestParser();
356
-        final PrivateMessageListener ipmtest = mock(PrivateMessageListener.class);
357
-        final PrivateActionListener ipatest = mock(PrivateActionListener.class);
358
-        final PrivateCtcpListener ipctest = mock(PrivateCtcpListener.class);
359
-
360
-        parser.injectConnectionStrings();
361
-
362
-        parser.getCallbackManager().addCallback(PrivateMessageListener.class, ipmtest);
363
-        parser.getCallbackManager().addCallback(PrivateActionListener.class, ipatest);
364
-        parser.getCallbackManager().addCallback(PrivateCtcpListener.class, ipctest);
365
-
366
-        parser.injectLine(":a!b@c PRIVMSG nick :Hello!");
367
-        verify(ipmtest).onPrivateMessage(same(parser), eq("Hello!"), eq("a!b@c"));
368
-        verify(ipatest, never()).onPrivateAction((Parser) anyObject(), anyString(), anyString());
369
-        verify(ipctest, never()).onPrivateCTCP((Parser) anyObject(), anyString(), anyString(), anyString());
370
-    }
371
-
372
-    @Test
373
-    public void testPrivateAction() throws CallbackNotFoundException {
374
-        final TestParser parser = new TestParser();
375
-        final PrivateMessageListener ipmtest = mock(PrivateMessageListener.class);
376
-        final PrivateActionListener ipatest = mock(PrivateActionListener.class);
377
-        final PrivateCtcpListener ipctest = mock(PrivateCtcpListener.class);
378
-
379
-        parser.injectConnectionStrings();
380
-
381
-        parser.getCallbackManager().addCallback(PrivateMessageListener.class, ipmtest);
382
-        parser.getCallbackManager().addCallback(PrivateActionListener.class, ipatest);
383
-        parser.getCallbackManager().addCallback(PrivateCtcpListener.class, ipctest);
384
-
385
-        parser.injectLine(":a!b@c PRIVMSG nick :" + ((char) 1) + "ACTION meep" + ((char) 1));
386
-        verify(ipmtest, never()).onPrivateMessage((Parser) anyObject(), anyString(), anyString());
387
-        verify(ipatest).onPrivateAction(same(parser), eq("meep"), eq("a!b@c"));
388
-        verify(ipctest, never()).onPrivateCTCP((Parser) anyObject(), anyString(), anyString(), anyString());
389
-    }
390
-
391
-    @Test
392
-    public void testPrivateCTCP() throws CallbackNotFoundException {
393
-        final TestParser parser = new TestParser();
394
-        final PrivateMessageListener ipmtest = mock(PrivateMessageListener.class);
395
-        final PrivateActionListener ipatest = mock(PrivateActionListener.class);
396
-        final PrivateCtcpListener ipctest = mock(PrivateCtcpListener.class);
397
-
398
-        parser.injectConnectionStrings();
399
-
400
-        parser.getCallbackManager().addCallback(PrivateMessageListener.class, ipmtest);
401
-        parser.getCallbackManager().addCallback(PrivateActionListener.class, ipatest);
402
-        parser.getCallbackManager().addCallback(PrivateCtcpListener.class, ipctest);
403
-
404
-        parser.injectLine(":a!b@c PRIVMSG nick :" + ((char) 1) + "FOO meep" + ((char) 1));
405
-        verify(ipmtest, never()).onPrivateMessage((Parser) anyObject(), anyString(), anyString());
406
-        verify(ipatest, never()).onPrivateAction((Parser) anyObject(), anyString(), anyString());
407
-        verify(ipctest).onPrivateCTCP(same(parser), eq("FOO"), eq("meep"), eq("a!b@c"));
408
-    }
409
-
410
-    private void testListModes(String numeric1, String numeric2, char mode) {
411
-        final TestParser parser = new TestParser();
412
-        parser.injectConnectionStrings();
413
-
414
-        parser.injectLine(":nick JOIN #D");
415
-        parser.injectLine(":server " + numeric1 + " nick #D ban1!ident@.host bansetter1 1001");
416
-        parser.injectLine(":server " + numeric1 + " nick #D ban2!*@.host bansetter2 1002");
417
-        parser.injectLine(":server " + numeric1 + " nick #D ban3!ident@* bansetter3 1003");
418
-        parser.injectLine(":server " + numeric2 + " nick #D :End of Channel Something List");
419
-
420
-        final Collection<ChannelListModeItem> items
421
-                = parser.getChannel("#D").getListMode(mode);
422
-
423
-        assertEquals(3, items.size());
424
-        boolean gotOne = false, gotTwo = false, gotThree = false;
425
-
426
-        for (ChannelListModeItem item : items) {
427
-            if (item.getItem().equals("ban1!ident@.host")) {
428
-                assertEquals("bansetter1", item.getOwner());
429
-                assertEquals(1001l, item.getTime());
430
-                assertFalse(gotOne);
431
-                gotOne = true;
432
-            } else if (item.getItem().equals("ban2!*@.host")) {
433
-                assertEquals("bansetter2", item.getOwner());
434
-                assertEquals(1002l, item.getTime());
435
-                assertFalse(gotTwo);
436
-                gotTwo = true;
437
-            } else if (item.toString().equals("ban3!ident@*")) {
438
-                assertEquals("bansetter3", item.getOwner());
439
-                assertEquals(1003l, item.getTime());
440
-                assertFalse(gotThree);
441
-                gotThree = true;
442
-            }
443
-        }
444
-
445
-        assertTrue(gotOne);
446
-        assertTrue(gotTwo);
447
-        assertTrue(gotThree);
448
-    }
449
-
450
-    @Test
451
-    public void testNormalBans() {
452
-        testListModes("367", "368", 'b');
453
-    }
454
-
455
-    @Test
456
-    public void testInvexList() {
457
-        testListModes("346", "347", 'I');
458
-    }
459
-
460
-    @Test
461
-    public void testExemptList() {
462
-        testListModes("348", "349", 'e');
463
-    }
464
-
465
-    @Test
466
-    public void testReopList() {
467
-        testListModes("344", "345", 'R');
468
-    }
469
-
470 324
     @Test
471 325
     public void testGetParam() {
472 326
         assertEquals("abc def", TestParser.getParam("foo :abc def"));

+ 93
- 0
test/com/dmdirc/parser/irc/ProcessListModeTest.java View File

@@ -0,0 +1,93 @@
1
+/*
2
+ * Copyright (c) 2006-2010 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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import com.dmdirc.harness.parser.TestParser;
26
+import com.dmdirc.parser.common.ChannelListModeItem;
27
+import java.util.Collection;
28
+import org.junit.Test;
29
+import static org.junit.Assert.*;
30
+
31
+public class ProcessListModeTest {
32
+
33
+    private void testListModes(String numeric1, String numeric2, char mode) {
34
+        final TestParser parser = new TestParser();
35
+        parser.injectConnectionStrings();
36
+
37
+        parser.injectLine(":nick JOIN #D");
38
+        parser.injectLine(":server " + numeric1 + " nick #D ban1!ident@.host bansetter1 1001");
39
+        parser.injectLine(":server " + numeric1 + " nick #D ban2!*@.host bansetter2 1002");
40
+        parser.injectLine(":server " + numeric1 + " nick #D ban3!ident@* bansetter3 1003");
41
+        parser.injectLine(":server " + numeric2 + " nick #D :End of Channel Something List");
42
+
43
+        final Collection<ChannelListModeItem> items
44
+                = parser.getChannel("#D").getListMode(mode);
45
+
46
+        assertEquals(3, items.size());
47
+        boolean gotOne = false, gotTwo = false, gotThree = false;
48
+
49
+        for (ChannelListModeItem item : items) {
50
+            if (item.getItem().equals("ban1!ident@.host")) {
51
+                assertEquals("bansetter1", item.getOwner());
52
+                assertEquals(1001l, item.getTime());
53
+                assertFalse(gotOne);
54
+                gotOne = true;
55
+            } else if (item.getItem().equals("ban2!*@.host")) {
56
+                assertEquals("bansetter2", item.getOwner());
57
+                assertEquals(1002l, item.getTime());
58
+                assertFalse(gotTwo);
59
+                gotTwo = true;
60
+            } else if (item.toString().equals("ban3!ident@*")) {
61
+                assertEquals("bansetter3", item.getOwner());
62
+                assertEquals(1003l, item.getTime());
63
+                assertFalse(gotThree);
64
+                gotThree = true;
65
+            }
66
+        }
67
+
68
+        assertTrue(gotOne);
69
+        assertTrue(gotTwo);
70
+        assertTrue(gotThree);
71
+    }
72
+
73
+    @Test
74
+    public void testNormalBans() {
75
+        testListModes("367", "368", 'b');
76
+    }
77
+
78
+    @Test
79
+    public void testInvexList() {
80
+        testListModes("346", "347", 'I');
81
+    }
82
+
83
+    @Test
84
+    public void testExemptList() {
85
+        testListModes("348", "349", 'e');
86
+    }
87
+
88
+    @Test
89
+    public void testReopList() {
90
+        testListModes("344", "345", 'R');
91
+    }
92
+
93
+}

+ 93
- 0
test/com/dmdirc/parser/irc/ProcessMessageTest.java View File

@@ -0,0 +1,93 @@
1
+/*
2
+ * Copyright (c) 2006-2010 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
+
23
+package com.dmdirc.parser.irc;
24
+
25
+import com.dmdirc.harness.parser.TestParser;
26
+import com.dmdirc.parser.common.CallbackNotFoundException;
27
+import com.dmdirc.parser.interfaces.Parser;
28
+import com.dmdirc.parser.interfaces.callbacks.PrivateActionListener;
29
+import com.dmdirc.parser.interfaces.callbacks.PrivateCtcpListener;
30
+import com.dmdirc.parser.interfaces.callbacks.PrivateMessageListener;
31
+import org.junit.Test;
32
+import static org.mockito.Mockito.*;
33
+
34
+public class ProcessMessageTest {
35
+
36
+    @Test
37
+    public void testPrivateMessage() throws CallbackNotFoundException {
38
+        final TestParser parser = new TestParser();
39
+        final PrivateMessageListener ipmtest = mock(PrivateMessageListener.class);
40
+        final PrivateActionListener ipatest = mock(PrivateActionListener.class);
41
+        final PrivateCtcpListener ipctest = mock(PrivateCtcpListener.class);
42
+
43
+        parser.injectConnectionStrings();
44
+
45
+        parser.getCallbackManager().addCallback(PrivateMessageListener.class, ipmtest);
46
+        parser.getCallbackManager().addCallback(PrivateActionListener.class, ipatest);
47
+        parser.getCallbackManager().addCallback(PrivateCtcpListener.class, ipctest);
48
+
49
+        parser.injectLine(":a!b@c PRIVMSG nick :Hello!");
50
+        verify(ipmtest).onPrivateMessage(same(parser), eq("Hello!"), eq("a!b@c"));
51
+        verify(ipatest, never()).onPrivateAction((Parser) anyObject(), anyString(), anyString());
52
+        verify(ipctest, never()).onPrivateCTCP((Parser) anyObject(), anyString(), anyString(), anyString());
53
+    }
54
+
55
+    @Test
56
+    public void testPrivateAction() throws CallbackNotFoundException {
57
+        final TestParser parser = new TestParser();
58
+        final PrivateMessageListener ipmtest = mock(PrivateMessageListener.class);
59
+        final PrivateActionListener ipatest = mock(PrivateActionListener.class);
60
+        final PrivateCtcpListener ipctest = mock(PrivateCtcpListener.class);
61
+
62
+        parser.injectConnectionStrings();
63
+
64
+        parser.getCallbackManager().addCallback(PrivateMessageListener.class, ipmtest);
65
+        parser.getCallbackManager().addCallback(PrivateActionListener.class, ipatest);
66
+        parser.getCallbackManager().addCallback(PrivateCtcpListener.class, ipctest);
67
+
68
+        parser.injectLine(":a!b@c PRIVMSG nick :" + ((char) 1) + "ACTION meep" + ((char) 1));
69
+        verify(ipmtest, never()).onPrivateMessage((Parser) anyObject(), anyString(), anyString());
70
+        verify(ipatest).onPrivateAction(same(parser), eq("meep"), eq("a!b@c"));
71
+        verify(ipctest, never()).onPrivateCTCP((Parser) anyObject(), anyString(), anyString(), anyString());
72
+    }
73
+
74
+    @Test
75
+    public void testPrivateCTCP() throws CallbackNotFoundException {
76
+        final TestParser parser = new TestParser();
77
+        final PrivateMessageListener ipmtest = mock(PrivateMessageListener.class);
78
+        final PrivateActionListener ipatest = mock(PrivateActionListener.class);
79
+        final PrivateCtcpListener ipctest = mock(PrivateCtcpListener.class);
80
+
81
+        parser.injectConnectionStrings();
82
+
83
+        parser.getCallbackManager().addCallback(PrivateMessageListener.class, ipmtest);
84
+        parser.getCallbackManager().addCallback(PrivateActionListener.class, ipatest);
85
+        parser.getCallbackManager().addCallback(PrivateCtcpListener.class, ipctest);
86
+
87
+        parser.injectLine(":a!b@c PRIVMSG nick :" + ((char) 1) + "FOO meep" + ((char) 1));
88
+        verify(ipmtest, never()).onPrivateMessage((Parser) anyObject(), anyString(), anyString());
89
+        verify(ipatest, never()).onPrivateAction((Parser) anyObject(), anyString(), anyString());
90
+        verify(ipctest).onPrivateCTCP(same(parser), eq("FOO"), eq("meep"), eq("a!b@c"));
91
+    }
92
+
93
+}

Loading…
Cancel
Save