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 |
|
|
|
|
| 96,7% |
Uncovered Elements: 2 (60) |
Complexity: 8 |
Complexity Density: 0,15 |
|
28 |
|
public class UsageDefaultReturnValueTest { |
29 |
|
|
30 |
|
private IMethods mock; |
31 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
32 |
10
|
@Before... |
33 |
|
public void setup() { |
34 |
10
|
mock = createMock(IMethods.class); |
35 |
|
} |
36 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0,08 |
1
PASS
|
|
37 |
2
|
@Test... |
38 |
|
public void defaultReturnValue() { |
39 |
2
|
expect(mock.threeArgumentMethod(7, "", "test")).andReturn("test"); |
40 |
|
|
41 |
2
|
expect(mock.threeArgumentMethod(8, null, "test2")).andReturn("test2"); |
42 |
|
|
43 |
2
|
final Object defaultValue = new Object(); |
44 |
2
|
expect(mock.threeArgumentMethod(anyInt(), anyObject(), (String) anyObject())).andStubReturn( |
45 |
|
defaultValue); |
46 |
|
|
47 |
2
|
replay(mock); |
48 |
2
|
assertEquals("test", mock.threeArgumentMethod(7, "", "test")); |
49 |
2
|
assertEquals("test2", mock.threeArgumentMethod(8, null, "test2")); |
50 |
2
|
assertSame(defaultValue, mock.threeArgumentMethod(7, new Object(), "test")); |
51 |
2
|
assertSame(defaultValue, mock.threeArgumentMethod(7, "", "test")); |
52 |
2
|
assertSame(defaultValue, mock.threeArgumentMethod(8, null, "test")); |
53 |
2
|
assertSame(defaultValue, mock.threeArgumentMethod(9, null, "test")); |
54 |
|
|
55 |
2
|
verify(mock); |
56 |
|
} |
57 |
|
|
|
|
| 92,3% |
Uncovered Elements: 1 (13) |
Complexity: 2 |
Complexity Density: 0,15 |
1
PASS
|
|
58 |
2
|
@Test... |
59 |
|
public void defaultVoidCallable() { |
60 |
2
|
mock.twoArgumentMethod(anyInt(), anyInt()); |
61 |
2
|
expectLastCall().asStub(); |
62 |
|
|
63 |
2
|
mock.twoArgumentMethod(1, 1); |
64 |
2
|
final RuntimeException expected = new RuntimeException(); |
65 |
2
|
expectLastCall().andThrow(expected); |
66 |
|
|
67 |
2
|
replay(mock); |
68 |
2
|
mock.twoArgumentMethod(2, 1); |
69 |
2
|
mock.twoArgumentMethod(1, 2); |
70 |
2
|
mock.twoArgumentMethod(3, 7); |
71 |
|
|
72 |
2
|
try { |
73 |
2
|
mock.twoArgumentMethod(1, 1); |
74 |
0
|
fail("RuntimeException expected"); |
75 |
|
} catch (final RuntimeException actual) { |
76 |
2
|
assertSame(expected, actual); |
77 |
|
} |
78 |
|
} |
79 |
|
|
|
|
| 92,9% |
Uncovered Elements: 1 (14) |
Complexity: 2 |
Complexity Density: 0,14 |
1
PASS
|
|
80 |
2
|
@Test... |
81 |
|
public void defaultThrowable() { |
82 |
2
|
mock.twoArgumentMethod(1, 2); |
83 |
2
|
expectLastCall(); |
84 |
2
|
mock.twoArgumentMethod(1, 1); |
85 |
2
|
expectLastCall(); |
86 |
|
|
87 |
2
|
final RuntimeException expected = new RuntimeException(); |
88 |
2
|
mock.twoArgumentMethod(anyInt(), anyInt()); |
89 |
2
|
expectLastCall().andStubThrow(expected); |
90 |
|
|
91 |
2
|
replay(mock); |
92 |
|
|
93 |
2
|
mock.twoArgumentMethod(1, 2); |
94 |
2
|
mock.twoArgumentMethod(1, 1); |
95 |
2
|
try { |
96 |
2
|
mock.twoArgumentMethod(2, 1); |
97 |
0
|
fail("RuntimeException expected"); |
98 |
|
} catch (final RuntimeException actual) { |
99 |
2
|
assertSame(expected, actual); |
100 |
|
} |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0,14 |
1
PASS
|
|
103 |
2
|
@Test... |
104 |
|
public void defaultReturnValueBoolean() { |
105 |
2
|
expect(mock.booleanReturningMethod(12)).andReturn(true); |
106 |
2
|
expect(mock.booleanReturningMethod(anyInt())).andStubReturn(false); |
107 |
|
|
108 |
2
|
replay(mock); |
109 |
|
|
110 |
2
|
assertFalse(mock.booleanReturningMethod(11)); |
111 |
2
|
assertTrue(mock.booleanReturningMethod(12)); |
112 |
2
|
assertFalse(mock.booleanReturningMethod(13)); |
113 |
|
|
114 |
2
|
verify(mock); |
115 |
|
} |
116 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0,14 |
1
PASS
|
|
117 |
2
|
@Test... |
118 |
|
public void returnValueAndDefaultReturnValue() throws Exception { |
119 |
|
|
120 |
2
|
expect(mock.oneArg("")).andReturn("1"); |
121 |
2
|
expect(mock.oneArg((String) anyObject())).andStubReturn("2"); |
122 |
|
|
123 |
2
|
replay(mock); |
124 |
|
|
125 |
2
|
assertEquals("1", mock.oneArg("")); |
126 |
2
|
assertEquals("2", mock.oneArg("")); |
127 |
2
|
assertEquals("2", mock.oneArg("X")); |
128 |
|
|
129 |
2
|
verify(mock); |
130 |
|
} |
131 |
|
} |