1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.easymock.tests2; |
18 |
|
|
19 |
|
import static org.easymock.EasyMock.*; |
20 |
|
import static org.junit.Assert.*; |
21 |
|
|
22 |
|
import org.easymock.tests.IMethods; |
23 |
|
import org.junit.Before; |
24 |
|
import org.junit.Test; |
25 |
|
|
26 |
|
|
27 |
|
@author |
28 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (33) |
Complexity: 6 |
Complexity Density: 0,2 |
|
29 |
|
public class StubTest { |
30 |
|
private IMethods mock; |
31 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
32 |
4
|
@Before... |
33 |
|
public void setup() { |
34 |
4
|
mock = createStrictMock(IMethods.class); |
35 |
|
} |
36 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0,07 |
1
PASS
|
|
37 |
2
|
@Test... |
38 |
|
public void stub() { |
39 |
2
|
mock.simpleMethodWithArgument("1"); |
40 |
2
|
expectLastCall().anyTimes(); |
41 |
2
|
mock.simpleMethodWithArgument("2"); |
42 |
2
|
expectLastCall().anyTimes(); |
43 |
2
|
mock.simpleMethodWithArgument("3"); |
44 |
2
|
expectLastCall().asStub(); |
45 |
|
|
46 |
2
|
replay(mock); |
47 |
|
|
48 |
2
|
mock.simpleMethodWithArgument("3"); |
49 |
2
|
mock.simpleMethodWithArgument("3"); |
50 |
2
|
mock.simpleMethodWithArgument("1"); |
51 |
2
|
mock.simpleMethodWithArgument("2"); |
52 |
2
|
mock.simpleMethodWithArgument("3"); |
53 |
2
|
mock.simpleMethodWithArgument("3"); |
54 |
|
|
55 |
2
|
verify(mock); |
56 |
|
|
57 |
|
} |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 4 |
Complexity Density: 0,27 |
1
PASS
|
|
59 |
2
|
@Test... |
60 |
|
public void stubWithReturnValue() { |
61 |
2
|
expect(mock.oneArg("1")).andReturn("A").andStubReturn("B"); |
62 |
2
|
expect(mock.oneArg("2")).andThrow(new IllegalArgumentException()).andStubThrow( |
63 |
|
new IllegalStateException()); |
64 |
|
|
65 |
2
|
replay(mock); |
66 |
|
|
67 |
2
|
assertEquals("A", mock.oneArg("1")); |
68 |
2
|
assertEquals("B", mock.oneArg("1")); |
69 |
2
|
assertEquals("B", mock.oneArg("1")); |
70 |
2
|
try { |
71 |
2
|
mock.oneArg("2"); |
72 |
|
} catch (final IllegalArgumentException ignored) { |
73 |
|
} |
74 |
2
|
assertEquals("B", mock.oneArg("1")); |
75 |
2
|
try { |
76 |
2
|
mock.oneArg("2"); |
77 |
|
} catch (final IllegalStateException ignored) { |
78 |
|
} |
79 |
2
|
assertEquals("B", mock.oneArg("1")); |
80 |
2
|
try { |
81 |
2
|
mock.oneArg("2"); |
82 |
|
} catch (final IllegalStateException ignored) { |
83 |
|
} |
84 |
2
|
verify(mock); |
85 |
|
} |
86 |
|
|
87 |
|
} |