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.junit.Before; |
23 |
|
import org.junit.Test; |
24 |
|
|
25 |
|
|
26 |
|
@author |
27 |
|
|
|
|
| 83,3% |
Uncovered Elements: 3 (18) |
Complexity: 7 |
Complexity Density: 0,5 |
|
28 |
|
public class RecordStateInvalidReturnValueTest { |
29 |
|
|
30 |
|
private IMethods mock; |
31 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
32 |
6
|
@Before... |
33 |
|
public void setup() { |
34 |
6
|
mock = createMock(IMethods.class); |
35 |
|
} |
36 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
37 |
2
|
@Test... |
38 |
|
public void setInvalidBooleanReturnValue() { |
39 |
2
|
try { |
40 |
2
|
expect((Object) mock.oneArg(false)).andReturn(false); |
41 |
0
|
fail("IllegalStateException expected"); |
42 |
|
} catch (final IllegalStateException e) { |
43 |
2
|
assertEquals("incompatible return value type", e.getMessage()); |
44 |
|
} |
45 |
|
|
46 |
|
} |
47 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
48 |
2
|
@Test... |
49 |
|
public void setReturnValueForVoidMethod() { |
50 |
2
|
mock.simpleMethod(); |
51 |
2
|
try { |
52 |
2
|
expectLastCall().andReturn(null); |
53 |
0
|
fail("IllegalStateException expected"); |
54 |
|
} catch (final IllegalStateException e) { |
55 |
2
|
assertEquals("void method cannot return a value", e.getMessage()); |
56 |
|
} |
57 |
|
} |
58 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
59 |
2
|
@Test... |
60 |
|
public void nullForPrimitive() { |
61 |
2
|
try { |
62 |
2
|
expect(mock.longReturningMethod(4)).andReturn(null); |
63 |
0
|
fail("null not allowed"); |
64 |
|
} catch (final IllegalStateException e) { |
65 |
2
|
assertEquals("can't return null for a method returning a primitive type", e.getMessage()); |
66 |
|
} |
67 |
|
} |
68 |
|
} |