| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
package org.easymock.tests; |
| 6 |
|
|
| 7 |
|
import static org.junit.Assert.*; |
| 8 |
|
|
| 9 |
|
import java.lang.reflect.Method; |
| 10 |
|
|
| 11 |
|
import org.easymock.internal.EqualsMatcher; |
| 12 |
|
import org.easymock.internal.Invocation; |
| 13 |
|
import org.junit.Before; |
| 14 |
|
import org.junit.Test; |
| 15 |
|
|
|
|
|
| 96% |
Uncovered Elements: 1 (25) |
Complexity: 5 |
Complexity Density: 0,24 |
|
| 16 |
|
public class InvocationTest { |
| 17 |
|
|
| 18 |
|
private Invocation call; |
| 19 |
|
|
| 20 |
|
private Invocation equalCall; |
| 21 |
|
|
| 22 |
|
private Invocation nonEqualCall; |
| 23 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
|
| 24 |
3
|
@Before... |
| 25 |
|
public void setup() throws SecurityException, NoSuchMethodException { |
| 26 |
3
|
Object[] arguments1 = new Object[] { "" }; |
| 27 |
3
|
Object[] arguments2 = new Object[] { "" }; |
| 28 |
3
|
Object[] arguments3 = new Object[] { "X" }; |
| 29 |
3
|
Method m = Object.class.getMethod("equals", |
| 30 |
|
new Class[] { Object.class }); |
| 31 |
3
|
Object mock = new Object(); |
| 32 |
3
|
call = new Invocation(mock, m, arguments1); |
| 33 |
3
|
equalCall = new Invocation(mock, m, arguments2); |
| 34 |
3
|
nonEqualCall = new Invocation(mock, m, arguments3); |
| 35 |
|
} |
| 36 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
1
PASS
|
|
| 37 |
1
|
@Test... |
| 38 |
|
public void testEquals() { |
| 39 |
1
|
assertFalse(call.equals(null)); |
| 40 |
1
|
assertFalse(call.equals("")); |
| 41 |
1
|
assertTrue(call.equals(equalCall)); |
| 42 |
1
|
assertFalse(call.equals(nonEqualCall)); |
| 43 |
|
} |
| 44 |
|
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
| 45 |
1
|
@Test... |
| 46 |
|
public void testHashCode() { |
| 47 |
1
|
try { |
| 48 |
1
|
call.hashCode(); |
| 49 |
0
|
fail(); |
| 50 |
|
} catch (UnsupportedOperationException expected) { |
| 51 |
1
|
assertEquals("hashCode() is not implemented", expected.getMessage()); |
| 52 |
|
} |
| 53 |
|
} |
| 54 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
1
PASS
|
|
| 55 |
1
|
@Test... |
| 56 |
|
public void testShouldDisplayMocksToStringIfValidJavaIdentifier() |
| 57 |
|
throws SecurityException, NoSuchMethodException { |
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 3 |
Complexity Density: 1,5 |
|
| 58 |
|
class ToString { |
| 59 |
|
private final String name; |
| 60 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 61 |
2
|
public ToString(String name) {... |
| 62 |
2
|
this.name = name; |
| 63 |
|
} |
| 64 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 65 |
2
|
@Override... |
| 66 |
|
public String toString() { |
| 67 |
2
|
return name; |
| 68 |
|
} |
| 69 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 70 |
0
|
public void aMethod() {... |
| 71 |
|
} |
| 72 |
|
} |
| 73 |
|
|
| 74 |
1
|
Method method = ToString.class.getMethod("aMethod", new Class[0]); |
| 75 |
1
|
Invocation invocation = new Invocation(new ToString("validJavaIdentifier"), |
| 76 |
|
method, null); |
| 77 |
|
|
| 78 |
1
|
assertEquals(invocation.toString(new EqualsMatcher()), |
| 79 |
|
"validJavaIdentifier.aMethod()"); |
| 80 |
|
|
| 81 |
1
|
invocation = new Invocation(new ToString("no-valid-java-identifier"), |
| 82 |
|
method, null); |
| 83 |
|
|
| 84 |
1
|
assertEquals(invocation.toString(new EqualsMatcher()), "aMethod()"); |
| 85 |
|
|
| 86 |
|
} |
| 87 |
|
} |