Quellcode durchsuchen

Added unit test for parser topic processing

git-svn-id: http://svn.dmdirc.com/trunk@3829 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Chris Smith vor 16 Jahren
Ursprung
Commit
71bddf4451
1 geänderte Dateien mit 89 neuen und 0 gelöschten Zeilen
  1. 89
    0
      test/com/dmdirc/parser/ProcessTopicTest.java

+ 89
- 0
test/com/dmdirc/parser/ProcessTopicTest.java Datei anzeigen

@@ -0,0 +1,89 @@
1
+/*
2
+ * Copyright (c) 2006-2008 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;
24
+
25
+import com.dmdirc.parser.callbacks.CallbackNotFoundException;
26
+import com.dmdirc.parser.callbacks.interfaces.IChannelTopic;
27
+import org.junit.Test;
28
+import static org.junit.Assert.*;
29
+
30
+public class ProcessTopicTest extends junit.framework.TestCase {
31
+    
32
+    @Test
33
+    public void testBasicTopic() throws CallbackNotFoundException {
34
+        final TestParser parser = new TestParser();
35
+        final ICTTest test = new ICTTest();
36
+        parser.injectConnectionStrings();
37
+        parser.getCallbackManager().addCallback("OnChannelTopic", test);
38
+        
39
+        parser.injectLine(":nick JOIN #DMDirc_testing");
40
+        parser.injectLine(":server 332 nick #DMDirc_testing :This be a topic");
41
+        parser.injectLine(":server 333 nick #DMDirc_testing Q 1207350306");
42
+        
43
+        assertTrue(test.triggered);
44
+        assertTrue(test.isJoin);
45
+        assertEquals("#DMDirc_testing", test.channel.getName());
46
+        assertEquals("This be a topic", test.channel.getTopic());
47
+        assertEquals("Q", test.channel.getTopicUser());
48
+        assertEquals(1207350306l, test.channel.getTopicTime());
49
+    }
50
+    
51
+    @Test
52
+    public void testTopicChange() throws CallbackNotFoundException {
53
+        final TestParser parser = new TestParser();
54
+        final ICTTest test = new ICTTest();
55
+        parser.injectConnectionStrings();
56
+        
57
+        parser.injectLine(":nick JOIN #DMDirc_testing");
58
+        parser.injectLine(":server 332 nick #DMDirc_testing :This be a topic");
59
+        parser.injectLine(":server 333 nick #DMDirc_testing Q 1207350306");
60
+        
61
+        parser.getCallbackManager().addCallback("OnChannelTopic", test);
62
+        
63
+        parser.injectLine(":foobar TOPIC #DMDirc_testing :New topic here");
64
+        
65
+        assertTrue(test.triggered);
66
+        assertFalse(test.isJoin);
67
+        assertEquals("#DMDirc_testing", test.channel.getName());
68
+        assertEquals("New topic here", test.channel.getTopic());
69
+        assertEquals("foobar", test.channel.getTopicUser());
70
+        assertTrue(1207350306l < test.channel.getTopicTime());
71
+    }    
72
+    
73
+    private class ICTTest implements IChannelTopic {
74
+        
75
+        public boolean triggered;
76
+        public boolean isJoin;
77
+        public ChannelInfo channel;
78
+
79
+        public void onChannelTopic(IRCParser tParser, ChannelInfo cChannel,
80
+                                   boolean bIsJoinTopic) {
81
+            triggered = true;
82
+            isJoin = bIsJoinTopic;
83
+            channel = cChannel;
84
+        }
85
+        
86
+        
87
+    }
88
+
89
+}

Laden…
Abbrechen
Speichern