Pārlūkot izejas kodu

Unit tests

Change-Id: Ia72aa10c40198291b09fefb2b04a6529ccabba44
Reviewed-on: http://gerrit.dmdirc.com/1493
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Shane Mc Cormack <shane@dmdirc.com>
tags/0.6.5b1
Chris Smith 13 gadus atpakaļ
vecāks
revīzija
fae12fe3a0

+ 1
- 0
src/com/dmdirc/ServerStatus.java Parādīt failu

@@ -67,6 +67,7 @@ public class ServerStatus {
67 67
      * Transitions the status of this object to the specified state.
68 68
      *
69 69
      * @param newState The state to transition to
70
+     * @throws IllegalArgumentException If the specified transition is invalid
70 71
      */
71 72
     public synchronized void transition(final ServerState newState) {
72 73
         addHistoryEntry(state, newState);

+ 10
- 10
test/com/dmdirc/InviteTest.java Parādīt failu

@@ -22,9 +22,6 @@
22 22
 
23 23
 package com.dmdirc;
24 24
 
25
-import com.dmdirc.config.IdentityManager;
26
-import com.dmdirc.addons.ui_dummy.DummyController;
27
-
28 25
 import java.util.Date;
29 26
 
30 27
 import org.junit.BeforeClass;
@@ -41,21 +38,18 @@ public class InviteTest {
41 38
     
42 39
     @BeforeClass
43 40
     public static void setUp() throws Exception {
44
-        Main.setUI(new DummyController());
45
-        IdentityManager.load();
46
-        
47 41
         server = mock(Server.class);
48 42
 
49 43
         when(server.parseHostmask("nick!ident@host"))
50
-                .thenReturn(new String[] { "nick", "ident", "host"});
44
+                .thenReturn(new String[] {"nick", "ident", "host"});
51 45
 
52 46
         test = new Invite(server, "#channel", "nick!ident@host");
53 47
         ts = new Date().getTime();
54
-    }    
48
+    }
55 49
 
56 50
     @Test
57 51
     public void testGetServer() {
58
-        assertEquals(server, test.getServer());
52
+        assertSame(server, test.getServer());
59 53
     }
60 54
 
61 55
     @Test
@@ -80,7 +74,13 @@ public class InviteTest {
80 74
     @Test
81 75
     public void testAccept() {
82 76
         test.accept();
83
-        assertEquals(0, server.getInvites().size());
77
+        verify(server).acceptInvites(test);
78
+    }
79
+
80
+    @Test
81
+    public void testDecline() {
82
+        test.decline();
83
+        verify(server).removeInvite(test);
84 84
     }
85 85
 
86 86
 }

+ 63
- 0
test/com/dmdirc/ServerStatusTest.java Parādīt failu

@@ -0,0 +1,63 @@
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;
24
+
25
+import com.dmdirc.parser.interfaces.Parser;
26
+import org.junit.Test;
27
+import static org.junit.Assert.*;
28
+
29
+import static org.mockito.Mockito.*;
30
+
31
+public class ServerStatusTest {
32
+
33
+    @Test(expected=IllegalArgumentException.class)
34
+    public void testIllegalTransition() {
35
+        final ServerStatus status = new ServerStatus(mock(Server.class), mock(Object.class));
36
+        status.transition(ServerState.CONNECTED);
37
+    }
38
+
39
+    @Test
40
+    public void testGetParserIdSame() {
41
+        final ServerStatus status = new ServerStatus(mock(Server.class), mock(Object.class));
42
+        final Parser parser = mock(Parser.class);
43
+
44
+        assertEquals(status.getParserID(parser), status.getParserID(parser));
45
+    }
46
+
47
+    @Test
48
+    public void testGetParserIdDifferent() {
49
+        final ServerStatus status = new ServerStatus(mock(Server.class), mock(Object.class));
50
+        final Parser parser1 = mock(Parser.class);
51
+        final Parser parser2 = mock(Parser.class);
52
+
53
+        assertTrue(status.getParserID(parser1) != status.getParserID(parser2));
54
+    }
55
+
56
+    @Test
57
+    public void testGetParserIdNull() {
58
+        final ServerStatus status = new ServerStatus(mock(Server.class), mock(Object.class));
59
+
60
+        assertEquals(0, status.getParserID(null));
61
+    }
62
+
63
+}

+ 0
- 9
test/com/dmdirc/TopicTest.java Parādīt failu

@@ -22,19 +22,10 @@
22 22
 
23 23
 package com.dmdirc;
24 24
 
25
-import com.dmdirc.config.IdentityManager;
26
-import com.dmdirc.addons.ui_dummy.DummyController;
27
-import org.junit.BeforeClass;
28 25
 import org.junit.Test;
29 26
 import static org.junit.Assert.*;
30 27
 
31 28
 public class TopicTest {
32
-    
33
-    @BeforeClass
34
-    public static void setUp() throws Exception {
35
-        Main.setUI(new DummyController());
36
-        IdentityManager.load();
37
-    }
38 29
 
39 30
     @Test
40 31
     public void testGetClient() {

Notiek ielāde…
Atcelt
Saglabāt