| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
package org.easymock.tests; |
| 6 |
|
|
| 7 |
|
import static org.junit.Assert.*; |
| 8 |
|
|
| 9 |
|
import java.io.IOException; |
| 10 |
|
|
| 11 |
|
import org.easymock.MockControl; |
| 12 |
|
import org.junit.Before; |
| 13 |
|
import org.junit.Test; |
| 14 |
|
|
| 15 |
|
@SuppressWarnings("deprecation") |
|
|
|
| 85,7% |
Uncovered Elements: 4 (28) |
Complexity: 9 |
Complexity Density: 0,39 |
|
| 16 |
|
public class RecordStateInvalidThrowableTest { |
| 17 |
|
|
| 18 |
|
MockControl<IMethods> control; |
| 19 |
|
|
| 20 |
|
IMethods mock; |
| 21 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
| 22 |
|
private class CheckedException extends Exception { |
| 23 |
|
private static final long serialVersionUID = 1L; |
| 24 |
|
} |
| 25 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
| 26 |
4
|
@Before... |
| 27 |
|
public void setup() { |
| 28 |
4
|
control = MockControl.createControl(IMethods.class); |
| 29 |
4
|
mock = control.getMock(); |
| 30 |
|
} |
| 31 |
|
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
| 32 |
1
|
@Test... |
| 33 |
|
public void throwNull() { |
| 34 |
1
|
mock.throwsNothing(false); |
| 35 |
1
|
try { |
| 36 |
1
|
control.setThrowable(null); |
| 37 |
0
|
fail("NullPointerException expected"); |
| 38 |
|
} catch (NullPointerException expected) { |
| 39 |
1
|
assertEquals("null cannot be thrown", expected.getMessage()); |
| 40 |
|
} |
| 41 |
|
|
| 42 |
|
} |
| 43 |
|
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
| 44 |
1
|
@Test... |
| 45 |
|
public void throwCheckedExceptionWhereNoCheckedExceptionIsThrown() { |
| 46 |
1
|
mock.throwsNothing(false); |
| 47 |
1
|
try { |
| 48 |
1
|
control.setThrowable(new CheckedException()); |
| 49 |
0
|
fail("IllegalArgumentException expected"); |
| 50 |
|
} catch (IllegalArgumentException expected) { |
| 51 |
1
|
assertEquals("last method called on mock cannot throw " |
| 52 |
|
+ CheckedException.class.getName(), expected.getMessage()); |
| 53 |
|
} |
| 54 |
|
} |
| 55 |
|
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
| 56 |
1
|
@Test... |
| 57 |
|
public void throwWrongCheckedException() throws IOException { |
| 58 |
1
|
mock.throwsIOException(0); |
| 59 |
1
|
try { |
| 60 |
1
|
control.setThrowable(new CheckedException()); |
| 61 |
0
|
fail("IllegalArgumentException expected"); |
| 62 |
|
} catch (IllegalArgumentException expected) { |
| 63 |
1
|
assertEquals("last method called on mock cannot throw " |
| 64 |
|
+ CheckedException.class.getName(), expected.getMessage()); |
| 65 |
|
} |
| 66 |
|
} |
| 67 |
|
|
|
|
|
| 83,3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0,33 |
1
PASS
|
|
| 68 |
1
|
@Test... |
| 69 |
|
public void throwAfterThrowable() throws IOException { |
| 70 |
1
|
mock.throwsIOException(0); |
| 71 |
1
|
control.setThrowable(new IOException(), MockControl.ONE_OR_MORE); |
| 72 |
1
|
try { |
| 73 |
1
|
control.setThrowable(new IOException()); |
| 74 |
0
|
fail("IllegalStateException expected"); |
| 75 |
|
} catch (IllegalStateException expected) { |
| 76 |
1
|
assertEquals( |
| 77 |
|
"last method called on mock already has a non-fixed count set.", |
| 78 |
|
expected.getMessage()); |
| 79 |
|
} |
| 80 |
|
} |
| 81 |
|
} |