| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
package org.easymock.tests; |
| 6 |
|
|
| 7 |
|
import static org.junit.Assert.*; |
| 8 |
|
|
| 9 |
|
import org.easymock.AbstractMatcher; |
| 10 |
|
import org.easymock.ArgumentsMatcher; |
| 11 |
|
import org.easymock.MockControl; |
| 12 |
|
import org.junit.Before; |
| 13 |
|
import org.junit.Test; |
| 14 |
|
|
| 15 |
|
@SuppressWarnings("deprecation") |
|
|
|
| 92,9% |
Uncovered Elements: 5 (70) |
Complexity: 15 |
Complexity Density: 0,27 |
|
| 16 |
|
public class ArgumentsMatcherTest { |
| 17 |
|
|
| 18 |
|
MockControl<IMethods> control; |
| 19 |
|
|
| 20 |
|
IMethods mock; |
| 21 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
| 22 |
6
|
@Before... |
| 23 |
|
public void setUp() { |
| 24 |
6
|
control = MockControl.createStrictControl(IMethods.class); |
| 25 |
6
|
mock = control.getMock(); |
| 26 |
|
} |
| 27 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0,14 |
1
PASS
|
|
| 28 |
1
|
@Test... |
| 29 |
|
public void expectedArgumentsDelegatedToMatcher() { |
| 30 |
1
|
mock.twoArgumentMethod(0, 5); |
| 31 |
1
|
control.setMatcher(new AbstractMatcher() { |
| 32 |
|
|
| 33 |
|
private static final long serialVersionUID = 1L; |
| 34 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
|
| 35 |
1
|
@Override... |
| 36 |
|
public boolean matches(Object[] expected, Object[] actual) { |
| 37 |
1
|
assertEquals(0, ((Integer) expected[0]).intValue()); |
| 38 |
1
|
assertEquals(5, ((Integer) expected[1]).intValue()); |
| 39 |
1
|
assertEquals(1, ((Integer) actual[0]).intValue()); |
| 40 |
1
|
assertEquals(6, ((Integer) actual[1]).intValue()); |
| 41 |
1
|
return true; |
| 42 |
|
} |
| 43 |
|
}); |
| 44 |
1
|
mock.simpleMethod(); |
| 45 |
1
|
control.replay(); |
| 46 |
1
|
mock.twoArgumentMethod(1, 6); |
| 47 |
1
|
mock.simpleMethod(); |
| 48 |
1
|
control.verify(); |
| 49 |
|
} |
| 50 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0,08 |
1
PASS
|
|
| 51 |
1
|
@Test... |
| 52 |
|
public void expectedArgumentsDelegatedToMatcher2() { |
| 53 |
1
|
mock.threeArgumentMethod(7, "", "A test"); |
| 54 |
1
|
control.setMatcher(new AbstractMatcher() { |
| 55 |
|
|
| 56 |
|
private static final long serialVersionUID = 1L; |
| 57 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
| 58 |
7
|
@Override... |
| 59 |
|
public boolean matches(Object[] expected, Object[] actual) { |
| 60 |
7
|
int expectedInt = ((Integer) expected[0]).intValue(); |
| 61 |
7
|
int actualInt = ((Integer) actual[0]).intValue(); |
| 62 |
7
|
return expectedInt < actualInt; |
| 63 |
|
} |
| 64 |
|
}); |
| 65 |
1
|
control.setReturnValue("1"); |
| 66 |
1
|
mock.threeArgumentMethod(6, "", "A test"); |
| 67 |
1
|
control.setReturnValue("2"); |
| 68 |
1
|
mock.threeArgumentMethod(12, "", "A test"); |
| 69 |
1
|
control.setReturnValue("3"); |
| 70 |
|
|
| 71 |
1
|
control.replay(); |
| 72 |
1
|
mock.threeArgumentMethod(9, "test", "test"); |
| 73 |
1
|
mock.threeArgumentMethod(8, "test", "test"); |
| 74 |
1
|
mock.threeArgumentMethod(13, "test", "test"); |
| 75 |
1
|
control.verify(); |
| 76 |
|
} |
| 77 |
|
|
|
|
|
| 83,3% |
Uncovered Elements: 2 (12) |
Complexity: 3 |
Complexity Density: 0,3 |
1
PASS
|
|
| 78 |
1
|
@Test... |
| 79 |
|
public void errorString() { |
| 80 |
1
|
mock.twoArgumentMethod(0, 5); |
| 81 |
1
|
control.setMatcher(new ArgumentsMatcher() { |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 82 |
2
|
public boolean matches(Object[] expected, Object[] actual) {... |
| 83 |
2
|
return false; |
| 84 |
|
} |
| 85 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 86 |
1
|
public String toString(Object[] arguments) {... |
| 87 |
1
|
return "<<" + arguments[0] + ">>"; |
| 88 |
|
} |
| 89 |
|
}); |
| 90 |
1
|
control.replay(); |
| 91 |
1
|
boolean failed = false; |
| 92 |
1
|
try { |
| 93 |
1
|
mock.twoArgumentMethod(1, 5); |
| 94 |
|
} catch (AssertionError expected) { |
| 95 |
1
|
failed = true; |
| 96 |
1
|
assertEquals("\n Unexpected method call twoArgumentMethod(1, 5):" |
| 97 |
|
+ "\n twoArgumentMethod(<<0>>): expected: 1, actual: 0", |
| 98 |
|
expected.getMessage()); |
| 99 |
|
} |
| 100 |
1
|
if (!failed) { |
| 101 |
0
|
fail("exception expected"); |
| 102 |
|
} |
| 103 |
|
} |
| 104 |
|
|
|
|
|
| 85,7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0,29 |
1
PASS
|
|
| 105 |
1
|
@Test... |
| 106 |
|
public void settingTheSameMatcherIsOk() { |
| 107 |
1
|
try { |
| 108 |
1
|
mock.twoArgumentMethod(1, 2); |
| 109 |
1
|
control.setMatcher(MockControl.ARRAY_MATCHER); |
| 110 |
1
|
control.setMatcher(MockControl.ARRAY_MATCHER); |
| 111 |
1
|
mock.twoArgumentMethod(1, 2); |
| 112 |
1
|
control.setMatcher(MockControl.ARRAY_MATCHER); |
| 113 |
|
|
| 114 |
|
} catch (IllegalStateException unexpected) { |
| 115 |
0
|
fail("no exception should be thrown if the same matcher is set twice"); |
| 116 |
|
} |
| 117 |
|
} |
| 118 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
1
PASS
|
|
| 119 |
1
|
@Test... |
| 120 |
|
public void abstractMatcher() { |
| 121 |
1
|
AbstractMatcher trueMatcher = new AbstractMatcher() { |
| 122 |
|
|
| 123 |
|
private static final long serialVersionUID = 1L; |
| 124 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 125 |
0
|
protected boolean parameterMatches(Object expected, Object actual) {... |
| 126 |
0
|
return true; |
| 127 |
|
} |
| 128 |
|
}; |
| 129 |
1
|
Object[] arrayWithNull = new Object[] { null }; |
| 130 |
1
|
Object[] arrayWithObject = new Object[] { new Object() }; |
| 131 |
1
|
assertFalse(trueMatcher.matches(arrayWithNull, arrayWithObject)); |
| 132 |
1
|
assertFalse(trueMatcher.matches(arrayWithObject, arrayWithNull)); |
| 133 |
|
} |
| 134 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
1
PASS
|
|
| 135 |
1
|
@Test... |
| 136 |
|
public void abstractMatcherToStringHandlesNullArray() { |
| 137 |
1
|
AbstractMatcher matcher = new AbstractMatcher() { |
| 138 |
|
private static final long serialVersionUID = 1L; |
| 139 |
|
}; |
| 140 |
1
|
assertEquals("", matcher.toString(null)); |
| 141 |
|
} |
| 142 |
|
|
| 143 |
|
} |