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.junit.Before; |
25 |
|
import org.junit.Test; |
26 |
|
|
27 |
|
|
28 |
|
@author |
29 |
|
|
|
|
| 85% |
Uncovered Elements: 3 (20) |
Complexity: 7 |
Complexity Density: 0,44 |
|
30 |
|
public class RecordStateInvalidThrowableTest { |
31 |
|
|
32 |
|
private IMethods mock; |
33 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
34 |
|
private class CheckedException extends Exception { |
35 |
|
private static final long serialVersionUID = 1L; |
36 |
|
} |
37 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
38 |
6
|
@Before... |
39 |
|
public void setup() { |
40 |
6
|
mock = createMock(IMethods.class); |
41 |
|
} |
42 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
43 |
2
|
@Test... |
44 |
|
public void throwNull() { |
45 |
2
|
mock.throwsNothing(false); |
46 |
2
|
try { |
47 |
2
|
expectLastCall().andThrow(null); |
48 |
0
|
fail("NullPointerException expected"); |
49 |
|
} catch (final NullPointerException expected) { |
50 |
2
|
assertEquals("null cannot be thrown", expected.getMessage()); |
51 |
|
} |
52 |
|
|
53 |
|
} |
54 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
55 |
2
|
@Test... |
56 |
|
public void throwCheckedExceptionWhereNoCheckedExceptionIsThrown() { |
57 |
2
|
mock.throwsNothing(false); |
58 |
2
|
try { |
59 |
2
|
expectLastCall().andThrow(new CheckedException()); |
60 |
0
|
fail("IllegalArgumentException expected"); |
61 |
|
} catch (final IllegalArgumentException expected) { |
62 |
2
|
assertEquals("last method called on mock cannot throw " + CheckedException.class.getName(), |
63 |
|
expected.getMessage()); |
64 |
|
} |
65 |
|
} |
66 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
67 |
2
|
@Test... |
68 |
|
public void throwWrongCheckedException() throws IOException { |
69 |
2
|
mock.throwsIOException(0); |
70 |
2
|
try { |
71 |
2
|
expectLastCall().andThrow(new CheckedException()); |
72 |
0
|
fail("IllegalArgumentException expected"); |
73 |
|
} catch (final IllegalArgumentException expected) { |
74 |
2
|
assertEquals("last method called on mock cannot throw " + CheckedException.class.getName(), |
75 |
|
expected.getMessage()); |
76 |
|
} |
77 |
|
} |
78 |
|
} |