| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
package org.easymock.tests; |
| 6 |
|
|
| 7 |
|
import static org.easymock.EasyMock.*; |
| 8 |
|
import static org.junit.Assert.*; |
| 9 |
|
|
| 10 |
|
import org.easymock.MockControl; |
| 11 |
|
import org.junit.Before; |
| 12 |
|
import org.junit.Test; |
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
@author |
| 19 |
|
|
| 20 |
|
@SuppressWarnings("deprecation") |
|
|
|
| 86,7% |
Uncovered Elements: 10 (75) |
Complexity: 20 |
Complexity Density: 0,29 |
|
| 21 |
|
public class UsageExpectAndDefaultThrowTest { |
| 22 |
|
private MockControl<IMethods> control; |
| 23 |
|
|
| 24 |
|
private IMethods mock; |
| 25 |
|
|
| 26 |
|
private static RuntimeException EXCEPTION = new RuntimeException(); |
| 27 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
| 28 |
6
|
@Before... |
| 29 |
|
public void setup() { |
| 30 |
6
|
control = MockControl.createControl(IMethods.class); |
| 31 |
6
|
mock = control.getMock(); |
| 32 |
|
} |
| 33 |
|
|
|
|
|
| 81,8% |
Uncovered Elements: 2 (11) |
Complexity: 3 |
Complexity Density: 0,27 |
1
PASS
|
|
| 34 |
1
|
@Test... |
| 35 |
|
public void booleanType() { |
| 36 |
1
|
control |
| 37 |
|
.expectAndDefaultThrow(mock.booleanReturningMethod(4), |
| 38 |
|
EXCEPTION); |
| 39 |
1
|
control.replay(); |
| 40 |
1
|
try { |
| 41 |
1
|
mock.booleanReturningMethod(4); |
| 42 |
0
|
fail(); |
| 43 |
|
} catch (RuntimeException exception) { |
| 44 |
1
|
assertSame(EXCEPTION, exception); |
| 45 |
|
} |
| 46 |
1
|
try { |
| 47 |
1
|
mock.booleanReturningMethod(4); |
| 48 |
0
|
fail(); |
| 49 |
|
} catch (RuntimeException exception) { |
| 50 |
1
|
assertSame(EXCEPTION, exception); |
| 51 |
|
} |
| 52 |
1
|
control.verify(); |
| 53 |
|
} |
| 54 |
|
|
|
|
|
| 81,8% |
Uncovered Elements: 2 (11) |
Complexity: 3 |
Complexity Density: 0,27 |
1
PASS
|
|
| 55 |
1
|
@Test... |
| 56 |
|
public void longType() { |
| 57 |
1
|
control.expectAndDefaultThrow(mock.longReturningMethod(4), EXCEPTION); |
| 58 |
1
|
control.replay(); |
| 59 |
1
|
try { |
| 60 |
1
|
mock.longReturningMethod(4); |
| 61 |
0
|
fail(); |
| 62 |
|
} catch (RuntimeException exception) { |
| 63 |
1
|
assertSame(EXCEPTION, exception); |
| 64 |
|
} |
| 65 |
1
|
try { |
| 66 |
1
|
mock.longReturningMethod(4); |
| 67 |
0
|
fail(); |
| 68 |
|
} catch (RuntimeException exception) { |
| 69 |
1
|
assertSame(EXCEPTION, exception); |
| 70 |
|
} |
| 71 |
1
|
control.verify(); |
| 72 |
|
} |
| 73 |
|
|
|
|
|
| 81,8% |
Uncovered Elements: 2 (11) |
Complexity: 3 |
Complexity Density: 0,27 |
1
PASS
|
|
| 74 |
1
|
@Test... |
| 75 |
|
public void floatType() { |
| 76 |
1
|
control.expectAndDefaultThrow(mock.floatReturningMethod(4), EXCEPTION); |
| 77 |
1
|
control.replay(); |
| 78 |
1
|
try { |
| 79 |
1
|
mock.floatReturningMethod(4); |
| 80 |
0
|
fail(); |
| 81 |
|
} catch (RuntimeException exception) { |
| 82 |
1
|
assertSame(EXCEPTION, exception); |
| 83 |
|
} |
| 84 |
1
|
try { |
| 85 |
1
|
mock.floatReturningMethod(4); |
| 86 |
0
|
fail(); |
| 87 |
|
} catch (RuntimeException exception) { |
| 88 |
1
|
assertSame(EXCEPTION, exception); |
| 89 |
|
} |
| 90 |
1
|
control.verify(); |
| 91 |
|
} |
| 92 |
|
|
|
|
|
| 81,8% |
Uncovered Elements: 2 (11) |
Complexity: 3 |
Complexity Density: 0,27 |
1
PASS
|
|
| 93 |
1
|
@Test... |
| 94 |
|
public void doubleType() { |
| 95 |
1
|
control.expectAndDefaultThrow(mock.doubleReturningMethod(4), EXCEPTION); |
| 96 |
1
|
control.replay(); |
| 97 |
1
|
try { |
| 98 |
1
|
mock.doubleReturningMethod(4); |
| 99 |
0
|
fail(); |
| 100 |
|
} catch (RuntimeException exception) { |
| 101 |
1
|
assertSame(EXCEPTION, exception); |
| 102 |
|
} |
| 103 |
1
|
try { |
| 104 |
1
|
mock.doubleReturningMethod(4); |
| 105 |
0
|
fail(); |
| 106 |
|
} catch (RuntimeException exception) { |
| 107 |
1
|
assertSame(EXCEPTION, exception); |
| 108 |
|
} |
| 109 |
1
|
control.verify(); |
| 110 |
|
} |
| 111 |
|
|
|
|
|
| 81,8% |
Uncovered Elements: 2 (11) |
Complexity: 3 |
Complexity Density: 0,27 |
1
PASS
|
|
| 112 |
1
|
@Test... |
| 113 |
|
public void object() { |
| 114 |
1
|
control.expectAndDefaultThrow(mock.objectReturningMethod(4), EXCEPTION); |
| 115 |
1
|
control.replay(); |
| 116 |
1
|
try { |
| 117 |
1
|
mock.objectReturningMethod(4); |
| 118 |
0
|
fail(); |
| 119 |
|
} catch (RuntimeException exception) { |
| 120 |
1
|
assertSame(EXCEPTION, exception); |
| 121 |
|
} |
| 122 |
1
|
try { |
| 123 |
1
|
mock.objectReturningMethod(4); |
| 124 |
0
|
fail(); |
| 125 |
|
} catch (RuntimeException exception) { |
| 126 |
1
|
assertSame(EXCEPTION, exception); |
| 127 |
|
} |
| 128 |
1
|
control.verify(); |
| 129 |
|
} |
| 130 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 4 |
Complexity Density: 0,36 |
1
PASS
|
|
| 131 |
1
|
@Test... |
| 132 |
|
public void throwableAndDefaultThrowable() throws Exception { |
| 133 |
|
|
| 134 |
1
|
mock.oneArg("1"); |
| 135 |
|
|
| 136 |
1
|
expectLastCall().andThrow(new IllegalArgumentException()); |
| 137 |
1
|
control.setDefaultThrowable(new IllegalStateException()); |
| 138 |
|
|
| 139 |
1
|
control.replay(); |
| 140 |
|
|
| 141 |
1
|
try { |
| 142 |
1
|
mock.oneArg("1"); |
| 143 |
|
} catch (IllegalArgumentException ignored) { |
| 144 |
|
} |
| 145 |
1
|
try { |
| 146 |
1
|
mock.oneArg("1"); |
| 147 |
|
} catch (IllegalStateException ignored) { |
| 148 |
|
} |
| 149 |
1
|
try { |
| 150 |
1
|
mock.oneArg("2"); |
| 151 |
|
} catch (IllegalStateException ignored) { |
| 152 |
|
} |
| 153 |
1
|
control.verify(); |
| 154 |
|
} |
| 155 |
|
|
| 156 |
|
} |