1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.easymock.tests; |
18 |
|
|
19 |
|
import static org.easymock.EasyMock.*; |
20 |
|
import static org.junit.Assert.*; |
21 |
|
|
22 |
|
import org.easymock.IAnswer; |
23 |
|
import org.easymock.internal.MocksControl; |
24 |
|
import org.junit.Before; |
25 |
|
import org.junit.Test; |
26 |
|
|
27 |
|
|
28 |
|
@author |
29 |
|
|
|
|
| 78,6% |
Uncovered Elements: 28 (131) |
Complexity: 52 |
Complexity Density: 0,5 |
|
30 |
|
public class RecordStateMethodCallMissingTest { |
31 |
|
|
32 |
|
private static final String METHOD_CALL_NEEDED = "method call on the mock needed before setting "; |
33 |
|
|
34 |
|
IMethods mock; |
35 |
|
|
36 |
|
MocksControl control; |
37 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
38 |
48
|
@Before... |
39 |
|
public void setup() { |
40 |
48
|
control = (MocksControl) createControl(); |
41 |
48
|
mock = control.createMock(IMethods.class); |
42 |
|
} |
43 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
44 |
44
|
private void assertMessage(final String suffix, final IllegalStateException expected) {... |
45 |
44
|
assertEquals(METHOD_CALL_NEEDED + suffix, expected.getMessage()); |
46 |
|
} |
47 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
48 |
2
|
@Test... |
49 |
|
public void setBooleanReturnValueWithoutMethodCall() { |
50 |
2
|
try { |
51 |
2
|
control.andReturn(false); |
52 |
0
|
fail("IllegalStateException expected"); |
53 |
|
} catch (final IllegalStateException expected) { |
54 |
2
|
assertMessage("return value", expected); |
55 |
|
} |
56 |
|
} |
57 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
58 |
2
|
@Test... |
59 |
|
public void setLongReturnValueWithoutMethodCall() { |
60 |
2
|
try { |
61 |
2
|
control.andReturn(0L); |
62 |
0
|
fail("IllegalStateException expected"); |
63 |
|
} catch (final IllegalStateException expected) { |
64 |
2
|
assertMessage("return value", expected); |
65 |
|
} |
66 |
|
} |
67 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
68 |
2
|
@Test... |
69 |
|
public void setFloatReturnValueWithoutMethodCall() { |
70 |
2
|
try { |
71 |
2
|
control.andReturn(0.0f); |
72 |
0
|
fail("IllegalStateException expected"); |
73 |
|
} catch (final IllegalStateException expected) { |
74 |
2
|
assertMessage("return value", expected); |
75 |
|
} |
76 |
|
} |
77 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
78 |
2
|
@Test... |
79 |
|
public void setDoubleReturnValueWithoutMethodCall() { |
80 |
2
|
try { |
81 |
2
|
control.andReturn(0.0); |
82 |
0
|
fail("IllegalStateException expected"); |
83 |
|
} catch (final IllegalStateException expected) { |
84 |
2
|
assertMessage("return value", expected); |
85 |
|
} |
86 |
|
} |
87 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
88 |
2
|
@Test... |
89 |
|
public void setObjectReturnValueWithoutMethodCall() { |
90 |
2
|
try { |
91 |
2
|
control.andReturn(null); |
92 |
0
|
fail("IllegalStateException expected"); |
93 |
|
} catch (final IllegalStateException expected) { |
94 |
2
|
assertMessage("return value", expected); |
95 |
|
} |
96 |
|
} |
97 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
98 |
2
|
@Test... |
99 |
|
public void setThrowableWithoutMethodCall() { |
100 |
2
|
try { |
101 |
2
|
control.andThrow(new RuntimeException()); |
102 |
0
|
fail("IllegalStateException expected"); |
103 |
|
} catch (final IllegalStateException expected) { |
104 |
2
|
assertMessage("Throwable", expected); |
105 |
|
} |
106 |
|
} |
107 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
108 |
2
|
@Test... |
109 |
|
public void setAnswerWithoutMethodCall() { |
110 |
2
|
try { |
111 |
2
|
control.andAnswer(new IAnswer<Object>() { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
112 |
0
|
public Object answer() throws Throwable {... |
113 |
0
|
return null; |
114 |
|
} |
115 |
|
|
116 |
|
}); |
117 |
0
|
fail("IllegalStateException expected"); |
118 |
|
} catch (final IllegalStateException expected) { |
119 |
2
|
assertMessage("answer", expected); |
120 |
|
} |
121 |
|
} |
122 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
123 |
2
|
@Test... |
124 |
|
public void setDelegateToWithoutMethodCall() { |
125 |
2
|
try { |
126 |
2
|
control.andDelegateTo(null); |
127 |
0
|
fail("IllegalStateException expected"); |
128 |
|
} catch (final IllegalStateException expected) { |
129 |
2
|
assertMessage("delegate", expected); |
130 |
|
} |
131 |
|
} |
132 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
133 |
2
|
@Test... |
134 |
|
public void setAnyTimesWithoutMethodCall() { |
135 |
2
|
try { |
136 |
2
|
control.anyTimes(); |
137 |
0
|
fail("IllegalStateException expected"); |
138 |
|
} catch (final IllegalStateException expected) { |
139 |
2
|
assertMessage("times", expected); |
140 |
|
} |
141 |
|
} |
142 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
143 |
2
|
@Test... |
144 |
|
public void setAtLeastOnceWithoutMethodCall() { |
145 |
2
|
try { |
146 |
2
|
control.atLeastOnce(); |
147 |
0
|
fail("IllegalStateException expected"); |
148 |
|
} catch (final IllegalStateException expected) { |
149 |
2
|
assertMessage("times", expected); |
150 |
|
} |
151 |
|
} |
152 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
153 |
2
|
@Test... |
154 |
|
public void setTimesWithoutMethodCall() { |
155 |
2
|
try { |
156 |
2
|
control.times(3); |
157 |
0
|
fail("IllegalStateException expected"); |
158 |
|
} catch (final IllegalStateException expected) { |
159 |
2
|
assertMessage("times", expected); |
160 |
|
} |
161 |
|
} |
162 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
163 |
2
|
@Test... |
164 |
|
public void setTimesMinMaxWithoutMethodCall() { |
165 |
2
|
try { |
166 |
2
|
control.times(1, 3); |
167 |
0
|
fail("IllegalStateException expected"); |
168 |
|
} catch (final IllegalStateException expected) { |
169 |
2
|
assertMessage("times", expected); |
170 |
|
} |
171 |
|
} |
172 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
173 |
2
|
@Test... |
174 |
|
public void setOnceWithoutMethodCall() { |
175 |
2
|
try { |
176 |
2
|
control.once(); |
177 |
0
|
fail("IllegalStateException expected"); |
178 |
|
} catch (final IllegalStateException expected) { |
179 |
2
|
assertMessage("times", expected); |
180 |
|
} |
181 |
|
} |
182 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
183 |
2
|
@Test... |
184 |
|
public void setBooleanDefaultReturnValueWithoutMethodCall() { |
185 |
2
|
try { |
186 |
2
|
control.andStubReturn(false); |
187 |
0
|
fail("IllegalStateException expected"); |
188 |
|
} catch (final IllegalStateException expected) { |
189 |
2
|
assertMessage("stub return value", expected); |
190 |
|
} |
191 |
|
} |
192 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
193 |
2
|
@Test... |
194 |
|
public void setLongDefaultReturnValueWithoutMethodCall() { |
195 |
2
|
try { |
196 |
2
|
control.andStubReturn(0L); |
197 |
0
|
fail("IllegalStateException expected"); |
198 |
|
} catch (final IllegalStateException expected) { |
199 |
2
|
assertMessage("stub return value", expected); |
200 |
|
} |
201 |
|
} |
202 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
203 |
2
|
@Test... |
204 |
|
public void setFloatDefaultReturnValueWithoutMethodCall() { |
205 |
2
|
try { |
206 |
2
|
control.andStubReturn(0.0f); |
207 |
0
|
fail("IllegalStateException expected"); |
208 |
|
} catch (final IllegalStateException expected) { |
209 |
2
|
assertMessage("stub return value", expected); |
210 |
|
} |
211 |
|
} |
212 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
213 |
2
|
@Test... |
214 |
|
public void setDoubleDefaultReturnValueWithoutMethodCall() { |
215 |
2
|
try { |
216 |
2
|
control.andStubReturn(0.0); |
217 |
0
|
fail("IllegalStateException expected"); |
218 |
|
} catch (final IllegalStateException expected) { |
219 |
2
|
assertMessage("stub return value", expected); |
220 |
|
} |
221 |
|
} |
222 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
223 |
2
|
@Test... |
224 |
|
public void setObjectDefaultReturnValueWithoutMethodCall() { |
225 |
2
|
try { |
226 |
2
|
control.andStubReturn(null); |
227 |
0
|
fail("IllegalStateException expected"); |
228 |
|
} catch (final IllegalStateException expected) { |
229 |
2
|
assertMessage("stub return value", expected); |
230 |
|
} |
231 |
|
} |
232 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
233 |
2
|
@Test... |
234 |
|
public void setDefaultVoidCallableWithoutMethodCall() { |
235 |
2
|
try { |
236 |
2
|
control.asStub(); |
237 |
0
|
fail("IllegalStateException expected"); |
238 |
|
} catch (final IllegalStateException expected) { |
239 |
2
|
assertMessage("stub behavior", expected); |
240 |
|
} |
241 |
|
} |
242 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
243 |
2
|
@Test... |
244 |
|
public void setDefaultThrowableWithoutMethodCall() { |
245 |
2
|
try { |
246 |
2
|
control.andStubThrow(new RuntimeException()); |
247 |
0
|
fail("IllegalStateException expected"); |
248 |
|
} catch (final IllegalStateException expected) { |
249 |
2
|
assertMessage("stub Throwable", expected); |
250 |
|
} |
251 |
|
} |
252 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
253 |
2
|
@Test... |
254 |
|
public void setStubAnswerWithoutMethodCall() { |
255 |
2
|
try { |
256 |
2
|
control.andStubAnswer(new IAnswer<Object>() { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
257 |
0
|
public Object answer() throws Throwable {... |
258 |
0
|
return null; |
259 |
|
} |
260 |
|
|
261 |
|
}); |
262 |
0
|
fail("IllegalStateException expected"); |
263 |
|
} catch (final IllegalStateException expected) { |
264 |
2
|
assertMessage("stub answer", expected); |
265 |
|
} |
266 |
|
} |
267 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
268 |
2
|
@Test... |
269 |
|
public void setStubDelegateToWithoutMethodCall() { |
270 |
2
|
try { |
271 |
2
|
control.andStubDelegateTo(null); |
272 |
0
|
fail("IllegalStateException expected"); |
273 |
|
} catch (final IllegalStateException expected) { |
274 |
2
|
assertMessage("stub delegate", expected); |
275 |
|
} |
276 |
|
} |
277 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
278 |
2
|
@Test... |
279 |
|
public void timesWithoutReturnValue() { |
280 |
2
|
mock.booleanReturningMethod(1); |
281 |
2
|
try { |
282 |
2
|
expectLastCall().times(3); |
283 |
0
|
fail(); |
284 |
|
} catch (final IllegalStateException expected) { |
285 |
2
|
assertEquals("last method called on mock is not a void method", expected.getMessage()); |
286 |
|
} |
287 |
|
} |
288 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
289 |
2
|
@Test... |
290 |
|
public void asStubWithNonVoidMethod() { |
291 |
2
|
mock.booleanReturningMethod(1); |
292 |
2
|
try { |
293 |
2
|
expectLastCall().asStub(); |
294 |
0
|
fail(); |
295 |
|
} catch (final IllegalStateException expected) { |
296 |
2
|
assertEquals("last method called on mock is not a void method", expected.getMessage()); |
297 |
|
} |
298 |
|
} |
299 |
|
|
300 |
|
} |