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 java.io.IOException; |
23 |
|
|
24 |
|
import org.easymock.internal.ReplayState; |
25 |
|
import org.junit.Before; |
26 |
|
import org.junit.Test; |
27 |
|
|
28 |
|
|
29 |
|
@author |
30 |
|
|
|
|
| 81,4% |
Uncovered Elements: 11 (59) |
Complexity: 14 |
Complexity Density: 0,26 |
|
31 |
|
public class UsageVerifyTest { |
32 |
|
|
33 |
|
private IMethods mock; |
34 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
35 |
6
|
@Before... |
36 |
|
public void setup() { |
37 |
6
|
mock = createMock(IMethods.class); |
38 |
|
} |
39 |
|
|
|
|
| 78,9% |
Uncovered Elements: 4 (19) |
Complexity: 4 |
Complexity Density: 0,24 |
1
PASS
|
|
40 |
2
|
@Test... |
41 |
|
public void twoReturns() { |
42 |
2
|
expect(mock.throwsNothing(true)).andReturn("Test").andReturn("Test2"); |
43 |
|
|
44 |
2
|
replay(mock); |
45 |
|
|
46 |
2
|
assertEquals("Test", mock.throwsNothing(true)); |
47 |
|
|
48 |
2
|
boolean failed = true; |
49 |
|
|
50 |
2
|
try { |
51 |
2
|
verify(mock); |
52 |
0
|
failed = false; |
53 |
|
} catch (final AssertionError expected) { |
54 |
2
|
assertEquals("\n Expectation failure on verify:" |
55 |
|
+ "\n throwsNothing(true): expected: 2, actual: 1", expected.getMessage()); |
56 |
2
|
assertTrue("stack trace must be filled in", Util.getStackTrace(expected).indexOf( |
57 |
|
ReplayState.class.getName()) == -1); |
58 |
|
} |
59 |
|
|
60 |
2
|
if (!failed) |
61 |
0
|
fail("AssertionError expected"); |
62 |
|
|
63 |
2
|
assertEquals("Test2", mock.throwsNothing(true)); |
64 |
|
|
65 |
2
|
verify(mock); |
66 |
|
|
67 |
2
|
try { |
68 |
2
|
mock.throwsNothing(true); |
69 |
0
|
fail("AssertionError expected"); |
70 |
|
} catch (final AssertionError expected) { |
71 |
2
|
assertEquals("\n Unexpected method call throwsNothing(true):" |
72 |
|
+ "\n throwsNothing(true): expected: 2, actual: 3", expected.getMessage()); |
73 |
|
} |
74 |
|
} |
75 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 2 |
Complexity Density: 0,2 |
1
PASS
|
|
76 |
2
|
@Test... |
77 |
|
public void atLeastTwoReturns() { |
78 |
2
|
expect(mock.throwsNothing(true)).andReturn("Test").andReturn("Test2").atLeastOnce(); |
79 |
|
|
80 |
2
|
replay(mock); |
81 |
|
|
82 |
2
|
assertEquals("Test", mock.throwsNothing(true)); |
83 |
|
|
84 |
2
|
try { |
85 |
2
|
verify(mock); |
86 |
0
|
fail("AssertionError expected"); |
87 |
|
} catch (final AssertionError expected) { |
88 |
|
|
89 |
2
|
assertEquals("\n Expectation failure on verify:" |
90 |
|
+ "\n throwsNothing(true): expected: at least 2, actual: 1", expected.getMessage()); |
91 |
|
} |
92 |
|
|
93 |
2
|
assertEquals("Test2", mock.throwsNothing(true)); |
94 |
2
|
assertEquals("Test2", mock.throwsNothing(true)); |
95 |
|
|
96 |
2
|
verify(mock); |
97 |
|
} |
98 |
|
|
|
|
| 76% |
Uncovered Elements: 6 (25) |
Complexity: 7 |
Complexity Density: 0,28 |
1
PASS
|
|
99 |
2
|
@Test... |
100 |
|
public void twoThrows() throws IOException { |
101 |
2
|
expect(mock.throwsIOException(0)).andThrow(new IOException()).andThrow(new IOException()); |
102 |
2
|
expect(mock.throwsIOException(1)).andThrow(new IOException()); |
103 |
|
|
104 |
2
|
replay(mock); |
105 |
|
|
106 |
2
|
try { |
107 |
2
|
mock.throwsIOException(0); |
108 |
0
|
fail("IOException expected"); |
109 |
|
} catch (final IOException expected) { |
110 |
|
} |
111 |
|
|
112 |
2
|
try { |
113 |
2
|
verify(mock); |
114 |
0
|
fail("AssertionError expected"); |
115 |
|
} catch (final AssertionError expected) { |
116 |
2
|
assertEquals("\n Expectation failure on verify:" |
117 |
|
+ "\n throwsIOException(0): expected: 2, actual: 1" |
118 |
|
+ "\n throwsIOException(1): expected: 1, actual: 0", expected.getMessage()); |
119 |
|
} |
120 |
|
|
121 |
2
|
try { |
122 |
2
|
mock.throwsIOException(0); |
123 |
0
|
fail("IOException expected"); |
124 |
|
} catch (final IOException expected) { |
125 |
|
} |
126 |
|
|
127 |
2
|
try { |
128 |
2
|
verify(mock); |
129 |
0
|
fail("AssertionError expected"); |
130 |
|
} catch (final AssertionError expected) { |
131 |
2
|
assertEquals("\n Expectation failure on verify:" |
132 |
|
+ "\n throwsIOException(1): expected: 1, actual: 0", expected.getMessage()); |
133 |
|
} |
134 |
|
|
135 |
2
|
try { |
136 |
2
|
mock.throwsIOException(1); |
137 |
0
|
fail("IOException expected"); |
138 |
|
} catch (final IOException expected) { |
139 |
|
} |
140 |
|
|
141 |
2
|
verify(mock); |
142 |
|
|
143 |
2
|
try { |
144 |
2
|
mock.throwsIOException(0); |
145 |
0
|
fail("AssertionError expected"); |
146 |
|
} catch (final AssertionError expected) { |
147 |
2
|
assertEquals("\n Unexpected method call throwsIOException(0):" |
148 |
|
+ "\n throwsIOException(0): expected: 2, actual: 3", expected.getMessage()); |
149 |
|
} |
150 |
|
} |
151 |
|
} |