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