Browse Source

Added ChannelClientInfo unit test

git-svn-id: http://svn.dmdirc.com/trunk@4336 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Chris Smith 16 years ago
parent
commit
ebc1e5722c
1 changed files with 102 additions and 0 deletions
  1. 102
    0
      test/com/dmdirc/parser/ChannelClientInfoTest.java

+ 102
- 0
test/com/dmdirc/parser/ChannelClientInfoTest.java View File

@@ -0,0 +1,102 @@
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.harness.parser.TestParser;
26
+
27
+import java.util.HashMap;
28
+import java.util.Map;
29
+import org.junit.Test;
30
+import static org.junit.Assert.*;
31
+
32
+public class ChannelClientInfoTest extends junit.framework.TestCase {
33
+        
34
+    @Test
35
+    public void testImportantMode() {
36
+        final TestParser parser = new TestParser();
37
+
38
+        parser.injectConnectionStrings();
39
+        parser.injectLine(":nick JOIN #DMDirc_testing");
40
+        parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser");
41
+        parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list");
42
+
43
+        final ChannelClientInfo cci = parser.getClientInfo("luser").getChannelClients().get(0);
44
+
45
+        assertEquals("v", cci.getImportantMode());
46
+        assertEquals("+", cci.getImportantModePrefix());
47
+        assertEquals("+luser", cci.toString());
48
+        assertEquals("+luser", cci.toFullString());
49
+        final long value = cci.getImportantModeValue();
50
+
51
+        parser.injectLine(":server MODE #DMDirc_testing +o luser");
52
+        assertEquals("o", cci.getImportantMode());
53
+        assertEquals("@", cci.getImportantModePrefix());
54
+        assertEquals("@luser", cci.toString());
55
+        assertEquals("@+luser", cci.toFullString());
56
+        assertTrue(cci.getImportantModeValue() > value);
57
+
58
+        parser.injectLine(":server MODE #DMDirc_testing -ov luser luser");
59
+        assertEquals("", cci.getImportantMode());
60
+        assertEquals("", cci.getImportantModePrefix());
61
+        assertEquals("luser", cci.toString());
62
+        assertEquals("luser", cci.toFullString());
63
+        assertEquals(0, cci.getImportantModeValue());
64
+    }
65
+    
66
+    @Test
67
+    public void testMap() {
68
+        final TestParser parser = new TestParser();
69
+
70
+        parser.injectConnectionStrings();
71
+        parser.injectLine(":nick JOIN #DMDirc_testing");
72
+        final Map<String, Integer> map1 = new HashMap<String, Integer>();
73
+        final Map<String, Integer> map2 = new HashMap<String, Integer>();
74
+        
75
+        final ChannelClientInfo cci = parser.getClientInfo("nick").getChannelClients().get(0);
76
+        
77
+        cci.setMap(map1);
78
+        assertSame(map1, cci.getMap());
79
+        
80
+        cci.setMap(map2);
81
+        assertSame(map2, cci.getMap());
82
+    }
83
+    
84
+    @Test
85
+    public void testKick() {
86
+        final TestParser parser = new TestParser();
87
+
88
+        parser.injectConnectionStrings();
89
+        parser.injectLine(":nick JOIN #DMDirc_testing");
90
+        parser.sentLines.clear();
91
+        
92
+        parser.getClientInfo("nick").getChannelClients().get(0).kick("");
93
+        assertEquals(1, parser.sentLines.size());
94
+        assertEquals("KICK #DMDirc_testing nick", parser.sentLines.get(0));
95
+        parser.sentLines.clear();
96
+        
97
+        parser.getClientInfo("nick").getChannelClients().get(0).kick("booya");
98
+        assertEquals(1, parser.sentLines.size());
99
+        assertEquals("KICK #DMDirc_testing nick :booya", parser.sentLines.get(0));
100
+    }
101
+
102
+}

Loading…
Cancel
Save