| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
package org.easymock.tests; |
| 6 |
|
|
| 7 |
|
import static org.junit.Assert.*; |
| 8 |
|
|
| 9 |
|
import org.easymock.MockControl; |
| 10 |
|
import org.junit.Before; |
| 11 |
|
import org.junit.Test; |
| 12 |
|
|
| 13 |
|
@SuppressWarnings("deprecation") |
|
|
|
| 88,1% |
Uncovered Elements: 5 (42) |
Complexity: 9 |
Complexity Density: 0,26 |
|
| 14 |
|
public class DefaultMatcherTest { |
| 15 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
| 16 |
|
public static interface ArrayInterface { |
| 17 |
|
void methodA(int[] argument); |
| 18 |
|
|
| 19 |
|
void methodB(int[] argument); |
| 20 |
|
} |
| 21 |
|
|
| 22 |
|
private MockControl<ArrayInterface> control; |
| 23 |
|
|
| 24 |
|
private ArrayInterface mock; |
| 25 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
| 26 |
4
|
@Before... |
| 27 |
|
public void setup() { |
| 28 |
4
|
control = MockControl.createControl(ArrayInterface.class); |
| 29 |
4
|
mock = control.getMock(); |
| 30 |
|
} |
| 31 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0,14 |
1
PASS
|
|
| 32 |
1
|
@Test... |
| 33 |
|
public void defaultMatcher() { |
| 34 |
1
|
control.setDefaultMatcher(MockControl.ARRAY_MATCHER); |
| 35 |
|
|
| 36 |
1
|
mock.methodA(new int[] { 1, 1 }); |
| 37 |
1
|
mock.methodB(new int[] { 2, 2 }); |
| 38 |
|
|
| 39 |
1
|
control.replay(); |
| 40 |
|
|
| 41 |
1
|
mock.methodA(new int[] { 1, 1 }); |
| 42 |
1
|
mock.methodB(new int[] { 2, 2 }); |
| 43 |
|
|
| 44 |
1
|
control.verify(); |
| 45 |
|
} |
| 46 |
|
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
| 47 |
1
|
@Test... |
| 48 |
|
public void failInReplayState() { |
| 49 |
1
|
control.replay(); |
| 50 |
1
|
try { |
| 51 |
1
|
control.setDefaultMatcher(MockControl.ARRAY_MATCHER); |
| 52 |
0
|
fail(); |
| 53 |
|
} catch (IllegalStateException expected) { |
| 54 |
|
} |
| 55 |
|
} |
| 56 |
|
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
| 57 |
1
|
@Test... |
| 58 |
|
public void failIfDefaultMatcherSetTwice() { |
| 59 |
1
|
control.setDefaultMatcher(MockControl.ARRAY_MATCHER); |
| 60 |
1
|
try { |
| 61 |
1
|
control.setDefaultMatcher(MockControl.ARRAY_MATCHER); |
| 62 |
0
|
fail(); |
| 63 |
|
} catch (IllegalStateException expected) { |
| 64 |
1
|
assertEquals( |
| 65 |
|
"default matcher can only be set once directly after creation of the MockControl", |
| 66 |
|
expected.getMessage()); |
| 67 |
|
} |
| 68 |
|
} |
| 69 |
|
|
|
|
|
| 84,2% |
Uncovered Elements: 3 (19) |
Complexity: 3 |
Complexity Density: 0,18 |
1
PASS
|
|
| 70 |
1
|
@Test... |
| 71 |
|
public void defaultMatcherSetTooLate() { |
| 72 |
1
|
int[] integers = new int[] { 1, 1 }; |
| 73 |
1
|
int[] integers2 = new int[] { 2, 2 }; |
| 74 |
1
|
mock.methodA(integers); |
| 75 |
1
|
control.setVoidCallable(); |
| 76 |
1
|
control.setDefaultMatcher(MockControl.ARRAY_MATCHER); |
| 77 |
1
|
mock.methodA(integers2); |
| 78 |
1
|
control.setVoidCallable(); |
| 79 |
1
|
control.replay(); |
| 80 |
|
|
| 81 |
1
|
boolean failed = true; |
| 82 |
1
|
try { |
| 83 |
1
|
mock.methodA(new int[] { 1, 1 }); |
| 84 |
0
|
failed = false; |
| 85 |
|
} catch (AssertionError expected) { |
| 86 |
|
} |
| 87 |
1
|
if (!failed) { |
| 88 |
0
|
fail(); |
| 89 |
|
} |
| 90 |
1
|
mock.methodA(integers); |
| 91 |
1
|
mock.methodA(new int[] { 2, 2 }); |
| 92 |
1
|
control.verify(); |
| 93 |
|
} |
| 94 |
|
} |