| 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") |
|
|
|
| 84,6% |
Uncovered Elements: 4 (26) |
Complexity: 9 |
Complexity Density: 0,43 |
|
| 16 |
|
public class RecordStateInvalidDefaultThrowableTest { |
| 17 |
|
MockControl<IMethods> control; |
| 18 |
|
|
| 19 |
|
IMethods mock; |
| 20 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
| 21 |
|
private class CheckedException extends Exception { |
| 22 |
|
private static final long serialVersionUID = 1L; |
| 23 |
|
} |
| 24 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
| 25 |
4
|
@Before... |
| 26 |
|
public void setup() { |
| 27 |
4
|
control = MockControl.createControl(IMethods.class); |
| 28 |
4
|
mock = control.getMock(); |
| 29 |
|
} |
| 30 |
|
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
| 31 |
1
|
@Test... |
| 32 |
|
public void throwNull() { |
| 33 |
1
|
mock.throwsNothing(false); |
| 34 |
1
|
try { |
| 35 |
1
|
control.setDefaultThrowable(null); |
| 36 |
0
|
fail("NullPointerException expected"); |
| 37 |
|
} catch (NullPointerException expected) { |
| 38 |
1
|
assertEquals("null cannot be thrown", expected.getMessage()); |
| 39 |
|
} |
| 40 |
|
|
| 41 |
|
} |
| 42 |
|
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
| 43 |
1
|
@Test... |
| 44 |
|
public void throwCheckedExceptionWhereNoCheckedExceptionIsThrown() { |
| 45 |
1
|
mock.throwsNothing(false); |
| 46 |
1
|
try { |
| 47 |
1
|
control.setDefaultThrowable(new CheckedException()); |
| 48 |
0
|
fail("IllegalArgumentException expected"); |
| 49 |
|
} catch (IllegalArgumentException expected) { |
| 50 |
1
|
assertEquals("last method called on mock cannot throw " |
| 51 |
|
+ this.getClass().getName() + "$CheckedException", expected |
| 52 |
|
.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.setDefaultThrowable(new CheckedException()); |
| 61 |
0
|
fail("IllegalArgumentException expected"); |
| 62 |
|
} catch (IllegalArgumentException expected) { |
| 63 |
1
|
assertEquals("last method called on mock cannot throw " |
| 64 |
|
+ this.getClass().getName() + "$CheckedException", expected |
| 65 |
|
.getMessage()); |
| 66 |
|
} |
| 67 |
|
} |
| 68 |
|
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
| 69 |
1
|
@Test... |
| 70 |
|
public void setDefaultThrowableWithoutMethodCall() throws IOException { |
| 71 |
1
|
try { |
| 72 |
1
|
control.setDefaultThrowable(new RuntimeException()); |
| 73 |
0
|
fail("IllegalStateException expected"); |
| 74 |
|
} catch (IllegalStateException expected) { |
| 75 |
1
|
assertEquals( |
| 76 |
|
"method call on the mock needed before setting default Throwable", |
| 77 |
|
expected.getMessage()); |
| 78 |
|
} |
| 79 |
|
} |
| 80 |
|
|
| 81 |
|
} |