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.junit.Test; |
23 |
|
|
24 |
|
|
25 |
|
@author |
26 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (41) |
Complexity: 8 |
Complexity Density: 0,22 |
|
27 |
|
public class MockedExceptionTest { |
28 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0,25 |
1
PASS
|
|
29 |
2
|
@Test... |
30 |
|
public void testMockedException() { |
31 |
2
|
final RuntimeException expected = createNiceMock(RuntimeException.class); |
32 |
2
|
final CharSequence c = createMock(CharSequence.class); |
33 |
2
|
expect(c.length()).andStubThrow(expected); |
34 |
2
|
replay(c, expected); |
35 |
|
|
36 |
2
|
try { |
37 |
2
|
c.length(); |
38 |
|
} catch (final RuntimeException actual) { |
39 |
2
|
assertSame(expected, actual); |
40 |
|
} |
41 |
|
|
42 |
2
|
verify(c, expected); |
43 |
|
} |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 2 |
Complexity Density: 0,18 |
1
PASS
|
|
45 |
2
|
@Test... |
46 |
|
public void testExplicitFillInStackTrace() { |
47 |
|
|
48 |
2
|
final RuntimeException expected = createNiceMock(RuntimeException.class); |
49 |
2
|
final RuntimeException myException = new RuntimeException(); |
50 |
2
|
expect(expected.fillInStackTrace()).andReturn(myException); |
51 |
|
|
52 |
2
|
final CharSequence c = createMock(CharSequence.class); |
53 |
2
|
expect(c.length()).andStubThrow(expected); |
54 |
|
|
55 |
2
|
replay(c, expected); |
56 |
|
|
57 |
2
|
try { |
58 |
2
|
c.length(); |
59 |
|
} catch (final RuntimeException actual) { |
60 |
2
|
assertSame(myException, actual.fillInStackTrace()); |
61 |
2
|
assertSame(expected, actual); |
62 |
|
} |
63 |
|
|
64 |
2
|
verify(c, expected); |
65 |
|
} |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0,22 |
1
PASS
|
|
67 |
2
|
@Test... |
68 |
|
public void testNotMockedFillInStackTrace() { |
69 |
|
|
70 |
2
|
final RuntimeException expected = createMockBuilder(RuntimeException.class).createNiceMock(); |
71 |
|
|
72 |
2
|
final CharSequence c = createMock(CharSequence.class); |
73 |
2
|
expect(c.length()).andStubThrow(expected); |
74 |
|
|
75 |
2
|
replay(c, expected); |
76 |
|
|
77 |
2
|
try { |
78 |
2
|
c.length(); |
79 |
|
} catch (final RuntimeException actual) { |
80 |
2
|
assertSame(expected, actual); |
81 |
2
|
assertEquals("fillInStackTrace should have been called normally", actual.getClass().getName(), |
82 |
|
actual.getStackTrace()[0].getClassName()); |
83 |
|
} |
84 |
|
|
85 |
2
|
verify(c, expected); |
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0,22 |
1
PASS
|
|
88 |
2
|
@Test... |
89 |
|
public void testRealException() { |
90 |
|
|
91 |
2
|
final RuntimeException expected = new RuntimeException(); |
92 |
|
|
93 |
2
|
final CharSequence c = createMock(CharSequence.class); |
94 |
2
|
expect(c.length()).andStubThrow(expected); |
95 |
|
|
96 |
2
|
replay(c); |
97 |
|
|
98 |
2
|
try { |
99 |
2
|
c.length(); |
100 |
|
} catch (final RuntimeException actual) { |
101 |
2
|
assertSame(expected, actual); |
102 |
2
|
assertEquals("fillInStackTrace should have been called normally", |
103 |
|
"org.easymock.internal.MockInvocationHandler", actual.getStackTrace()[0].getClassName()); |
104 |
|
} |
105 |
|
|
106 |
2
|
verify(c); |
107 |
|
} |
108 |
|
} |