Browse Source

Remove dependency on real ActionManager from test.

ActionComponentChain can be passed a simple mocked ActionManager,
instead of using a real ActionManager which requires half the
client to be initialised (via TestMain).

Change-Id: I294285d170e8facfa00e49683dd61068725d4f3e
Reviewed-on: http://gerrit.dmdirc.com/2657
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
tags/0.8rc1
Chris Smith 10 years ago
parent
commit
67936bd5de
1 changed files with 41 additions and 20 deletions
  1. 41
    20
      test/com/dmdirc/actions/ActionComponentChainTest.java

+ 41
- 20
test/com/dmdirc/actions/ActionComponentChainTest.java View File

@@ -22,24 +22,45 @@
22 22
 
23 23
 package com.dmdirc.actions;
24 24
 
25
-import com.dmdirc.TestMain;
26 25
 import com.dmdirc.Server;
27 26
 
28
-import org.junit.BeforeClass;
27
+import org.junit.Before;
29 28
 import org.junit.Test;
29
+import org.mockito.Mock;
30
+import org.mockito.MockitoAnnotations;
30 31
 
31 32
 import static org.junit.Assert.*;
33
+import static org.mockito.Mockito.*;
32 34
 
33 35
 public class ActionComponentChainTest {
34 36
 
35
-    @BeforeClass
36
-    public static void setUp() throws Exception {
37
-        TestMain.getTestMain();
37
+    @Mock private ActionManager actionManager;
38
+
39
+    @Before
40
+    public void setUp() throws Exception {
41
+        MockitoAnnotations.initMocks(this);
42
+
43
+        when(actionManager.getComponent("SERVER_NAME"))
44
+                .thenReturn(CoreActionComponent.SERVER_NAME);
45
+        when(actionManager.getComponent("SERVER_NETWORK"))
46
+                .thenReturn(CoreActionComponent.SERVER_NETWORK);
47
+        when(actionManager.getComponent("STRING_LENGTH"))
48
+                .thenReturn(CoreActionComponent.STRING_LENGTH);
49
+        when(actionManager.getComponent("STRING_STRING"))
50
+                .thenReturn(CoreActionComponent.STRING_STRING);
51
+        when(actionManager.getComponent("USER_MODES"))
52
+                .thenReturn(CoreActionComponent.USER_MODES);
53
+
54
+        // TODO: Testing for this behaviour here is odd - ActionComponentChain
55
+        //       should probably do its own validation and throw a more
56
+        //       appropriate exception.
57
+        when(actionManager.getComponent(""))
58
+                .thenThrow(new AssertionError());
38 59
     }
39 60
 
40 61
     @Test
41 62
     public void testSingle() {
42
-        final ActionComponentChain chain = new ActionComponentChain(String.class, "STRING_STRING");
63
+        final ActionComponentChain chain = new ActionComponentChain(String.class, "STRING_STRING", actionManager);
43 64
         assertEquals(chain.get("foo bar baz"), "foo bar baz");
44 65
         assertEquals("STRING_STRING", chain.toString());
45 66
     }
@@ -47,44 +68,44 @@ public class ActionComponentChainTest {
47 68
     @Test
48 69
     public void testDouble() {
49 70
         final ActionComponentChain chain = new ActionComponentChain(String.class,
50
-                "STRING_STRING.STRING_STRING");
71
+                "STRING_STRING.STRING_STRING", actionManager);
51 72
         assertEquals(chain.get("foo bar baz"), "foo bar baz");
52 73
         assertEquals("STRING_STRING.STRING_STRING", chain.toString());
53 74
     }
54 75
 
55 76
     @Test(expected=IllegalArgumentException.class)
56 77
     public void testInvalidName() {
57
-        new ActionComponentChain(String.class, "STRONG_STRING");
78
+        new ActionComponentChain(String.class, "STRONG_STRING", actionManager);
58 79
     }
59 80
 
60 81
     @Test(expected=IllegalArgumentException.class)
61 82
     public void testInvalidType() {
62
-        new ActionComponentChain(String.class, "USER_MODES.STRING_STRING");
83
+        new ActionComponentChain(String.class, "USER_MODES.STRING_STRING", actionManager);
63 84
     }
64 85
 
65 86
     @Test(expected=IllegalArgumentException.class)
66 87
     public void testInvalidLink() {
67
-        new ActionComponentChain(String.class, "STRING_STRING.USER_MODES");
88
+        new ActionComponentChain(String.class, "STRING_STRING.USER_MODES", actionManager);
68 89
     }
69 90
 
70 91
     @Test
71 92
     public void testAppliesTo() {
72 93
         final ActionComponentChain chain = new ActionComponentChain(String.class,
73
-                "STRING_STRING.STRING_STRING.STRING_LENGTH");
94
+                "STRING_STRING.STRING_STRING.STRING_LENGTH", actionManager);
74 95
         assertEquals(String.class, chain.appliesTo());
75 96
     }
76 97
 
77 98
     @Test
78 99
     public void testGetType() {
79 100
         final ActionComponentChain chain = new ActionComponentChain(String.class,
80
-                "STRING_STRING.STRING_STRING.STRING_LENGTH");
101
+                "STRING_STRING.STRING_STRING.STRING_LENGTH", actionManager);
81 102
         assertEquals(Integer.class, chain.getType());
82 103
     }
83 104
 
84 105
     @Test
85 106
     public void testGetName() {
86 107
         final ActionComponentChain chain = new ActionComponentChain(String.class,
87
-                "STRING_STRING.STRING_STRING.STRING_LENGTH");
108
+                "STRING_STRING.STRING_STRING.STRING_LENGTH", actionManager);
88 109
 
89 110
         assertTrue(chain.getName().indexOf(CoreActionComponent.STRING_STRING.getName()) > -1);
90 111
         assertTrue(chain.getName().indexOf(CoreActionComponent.STRING_LENGTH.getName()) > -1);
@@ -92,46 +113,46 @@ public class ActionComponentChainTest {
92 113
 
93 114
     @Test(expected=AssertionError.class)
94 115
     public void testEmptyAppliesTo() {
95
-        final ActionComponentChain chain = new ActionComponentChain(String.class, "");
116
+        final ActionComponentChain chain = new ActionComponentChain(String.class, "", actionManager);
96 117
         chain.appliesTo();
97 118
     }
98 119
 
99 120
     @Test(expected=AssertionError.class)
100 121
     public void testEmptyGetType() {
101
-        final ActionComponentChain chain = new ActionComponentChain(String.class, "");
122
+        final ActionComponentChain chain = new ActionComponentChain(String.class, "", actionManager);
102 123
         chain.getType();
103 124
     }
104 125
 
105 126
     @Test(expected=AssertionError.class)
106 127
     public void testEmptyGetName() {
107
-        final ActionComponentChain chain = new ActionComponentChain(String.class, "");
128
+        final ActionComponentChain chain = new ActionComponentChain(String.class, "", actionManager);
108 129
         chain.getName();
109 130
     }
110 131
 
111 132
     @Test(expected=AssertionError.class)
112 133
     public void testEmptyToString() {
113
-        final ActionComponentChain chain = new ActionComponentChain(String.class, "");
134
+        final ActionComponentChain chain = new ActionComponentChain(String.class, "", actionManager);
114 135
         chain.toString();
115 136
     }
116 137
 
117 138
     @Test()
118 139
     public void testRequiresConnection1() {
119 140
         final ActionComponentChain chain = new ActionComponentChain(Server.class,
120
-                "SERVER_NETWORK");
141
+                "SERVER_NETWORK", actionManager);
121 142
         assertTrue(chain.requiresConnection());
122 143
     }
123 144
 
124 145
     @Test()
125 146
     public void testRequiresConnection2() {
126 147
         final ActionComponentChain chain = new ActionComponentChain(Server.class,
127
-                "SERVER_NETWORK.STRING_LENGTH");
148
+                "SERVER_NETWORK.STRING_LENGTH", actionManager);
128 149
         assertTrue(chain.requiresConnection());
129 150
     }
130 151
 
131 152
     @Test()
132 153
     public void testRequiresConnection3() {
133 154
         final ActionComponentChain chain = new ActionComponentChain(Server.class,
134
-                "SERVER_NAME.STRING_LENGTH");
155
+                "SERVER_NAME.STRING_LENGTH", actionManager);
135 156
         assertFalse(chain.requiresConnection());
136 157
     }
137 158
 

Loading…
Cancel
Save