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.IAnswer; |
23 |
|
import org.easymock.tests.IMethods; |
24 |
|
import org.junit.Before; |
25 |
|
import org.junit.Test; |
26 |
|
|
27 |
|
|
28 |
|
@author |
29 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (36) |
Complexity: 7 |
Complexity Density: 0,24 |
|
30 |
|
public class CallbackAndArgumentsTest { |
31 |
|
|
32 |
|
private IMethods mock; |
33 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
34 |
6
|
@Before... |
35 |
|
public void setUp() { |
36 |
6
|
mock = createStrictMock(IMethods.class); |
37 |
|
} |
38 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
1
PASS
|
|
39 |
2
|
@Test... |
40 |
|
public void callbackGetsArguments() { |
41 |
|
|
42 |
2
|
final StringBuilder buffer = new StringBuilder(); |
43 |
|
|
44 |
2
|
mock.simpleMethodWithArgument((String) notNull()); |
45 |
2
|
expectLastCall().andAnswer(new IAnswer<Object>() { |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
46 |
4
|
public Object answer() {... |
47 |
4
|
buffer.append((String) getCurrentArguments()[0]); |
48 |
4
|
return null; |
49 |
|
} |
50 |
|
}).times(2); |
51 |
|
|
52 |
2
|
replay(mock); |
53 |
|
|
54 |
2
|
mock.simpleMethodWithArgument("1"); |
55 |
2
|
mock.simpleMethodWithArgument("2"); |
56 |
|
|
57 |
2
|
verify(mock); |
58 |
|
|
59 |
2
|
assertEquals("12", buffer.toString()); |
60 |
|
} |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
62 |
2
|
@Test(expected = IllegalStateException.class)... |
63 |
|
public void currentArgumentsFailsOutsideCallbacks() { |
64 |
2
|
getCurrentArguments(); |
65 |
|
} |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0,08 |
1
PASS
|
|
67 |
2
|
@Test... |
68 |
|
public void callbackGetsArgumentsEvenIfAMockCallsAnother() { |
69 |
|
|
70 |
2
|
final StringBuilder buffer = new StringBuilder(); |
71 |
|
|
72 |
2
|
final IMethods mock2 = createStrictMock(IMethods.class); |
73 |
2
|
mock2.simpleMethod(); |
74 |
2
|
expectLastCall().andAnswer(new IAnswer<Object>() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
75 |
4
|
public Object answer() {... |
76 |
|
|
77 |
4
|
return null; |
78 |
|
} |
79 |
|
}).times(2); |
80 |
|
|
81 |
2
|
mock.simpleMethodWithArgument((String) notNull()); |
82 |
2
|
expectLastCall().andAnswer(new IAnswer<Object>() { |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
83 |
4
|
public Object answer() {... |
84 |
4
|
mock2.simpleMethod(); |
85 |
4
|
buffer.append((String) getCurrentArguments()[0]); |
86 |
4
|
return null; |
87 |
|
} |
88 |
|
}).times(2); |
89 |
|
|
90 |
2
|
replay(mock); |
91 |
2
|
replay(mock2); |
92 |
|
|
93 |
2
|
mock.simpleMethodWithArgument("1"); |
94 |
2
|
mock.simpleMethodWithArgument("2"); |
95 |
|
|
96 |
2
|
verify(mock); |
97 |
2
|
verify(mock2); |
98 |
|
|
99 |
2
|
assertEquals("12", buffer.toString()); |
100 |
|
} |
101 |
|
} |