1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.easymock.tests2; |
18 |
|
|
19 |
|
import static org.junit.Assert.*; |
20 |
|
|
21 |
|
import java.lang.reflect.Constructor; |
22 |
|
import java.lang.reflect.Method; |
23 |
|
|
24 |
|
import org.easymock.internal.ReflectionUtils; |
25 |
|
import org.junit.Test; |
26 |
|
|
27 |
|
|
28 |
|
@author |
29 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (39) |
Complexity: 15 |
Complexity Density: 0,6 |
|
30 |
|
public class ReflectionUtilsTest { |
31 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: - |
|
32 |
|
public static class B { |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
33 |
0
|
protected void foo(final long l) {... |
34 |
|
} |
35 |
|
} |
36 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 9 |
Complexity Density: - |
|
37 |
|
public static class A extends B { |
38 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
39 |
0
|
public A(final boolean bool, final byte b, final int i, final short s, final char c, final long l,... |
40 |
|
final float f, final double d) { |
41 |
|
} |
42 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
43 |
0
|
public A(final int i) {... |
44 |
|
} |
45 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
46 |
0
|
protected A(final long l) {... |
47 |
|
} |
48 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
49 |
0
|
private A(final byte b) {... |
50 |
|
} |
51 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
52 |
0
|
A(final char c) {... |
53 |
|
} |
54 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
55 |
0
|
public A(final CharSequence c) {... |
56 |
|
} |
57 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
58 |
0
|
public A(final StringBuilder s) {... |
59 |
|
} |
60 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
61 |
0
|
public void foo(final String s) {... |
62 |
|
} |
63 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
64 |
0
|
public void foo(final int i) {... |
65 |
|
} |
66 |
|
} |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
1
PASS
|
|
68 |
2
|
@Test... |
69 |
|
public void testFindMethod() { |
70 |
2
|
final Method m = ReflectionUtils.findMethod(String.class, "length"); |
71 |
2
|
assertEquals("public int java.lang.String.length()", m.toString()); |
72 |
|
} |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
1
PASS
|
|
74 |
2
|
@Test... |
75 |
|
public void testFindMethod_NotFound() { |
76 |
2
|
final Method m = ReflectionUtils.findMethod(String.class, "aaa"); |
77 |
2
|
assertNull(m); |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 0,67 |
1
PASS
|
|
80 |
2
|
@Test... |
81 |
|
public void testFindMethod_Ambiguous() { |
82 |
2
|
try { |
83 |
2
|
ReflectionUtils.findMethod(A.class, "foo"); |
84 |
|
} catch (final RuntimeException e) { |
85 |
2
|
assertEquals("Ambiguous name: More than one method are named foo", e.getMessage()); |
86 |
|
} |
87 |
|
} |
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
1
PASS
|
|
89 |
2
|
@Test... |
90 |
|
public void testFindMethod_WrongParams() { |
91 |
2
|
final Method m = ReflectionUtils.findMethod(A.class, "foo", int.class, int.class); |
92 |
2
|
assertNull(m); |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
1
PASS
|
|
95 |
2
|
@Test... |
96 |
|
public void testFindMethod_Superclass() { |
97 |
2
|
final Method m = ReflectionUtils.findMethod(A.class, "foo", long.class); |
98 |
2
|
assertEquals("protected void " + B.class.getName() + ".foo(long)", m.toString()); |
99 |
|
} |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
1
PASS
|
|
101 |
2
|
@Test... |
102 |
|
public void testFindMethodClassOfQStringClassOfQArray() { |
103 |
2
|
final Method m = ReflectionUtils.findMethod(A.class, "foo", int.class); |
104 |
2
|
assertEquals("public void " + A.class.getName() + ".foo(int)", m.toString()); |
105 |
|
} |
106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
1
PASS
|
|
107 |
2
|
@Test... |
108 |
|
public void testGetConstructor_public() throws NoSuchMethodException { |
109 |
2
|
final Constructor<A> c = ReflectionUtils.getConstructor(A.class, 5); |
110 |
2
|
assertArrayEquals(new Class[] { int.class }, c.getParameterTypes()); |
111 |
|
} |
112 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
1
PASS
|
|
113 |
2
|
@Test... |
114 |
|
public void testGetConstructor_protected() throws NoSuchMethodException { |
115 |
2
|
final Constructor<A> c = ReflectionUtils.getConstructor(A.class, 5l); |
116 |
2
|
assertArrayEquals(new Class[] { long.class }, c.getParameterTypes()); |
117 |
|
} |
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
1
PASS
|
|
119 |
2
|
@Test... |
120 |
|
public void testGetConstructor_default() throws NoSuchMethodException { |
121 |
2
|
final Constructor<A> c = ReflectionUtils.getConstructor(A.class, 'c'); |
122 |
2
|
assertArrayEquals(new Class[] { char.class }, c.getParameterTypes()); |
123 |
|
} |
124 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
125 |
2
|
@Test(expected = NoSuchMethodException.class)... |
126 |
|
public void testGetConstructor_private() throws NoSuchMethodException { |
127 |
2
|
ReflectionUtils.getConstructor(A.class, (byte) 5); |
128 |
|
} |
129 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
130 |
2
|
@Test(expected = IllegalArgumentException.class)... |
131 |
|
public void testGetConstructor_twoMatching() throws NoSuchMethodException { |
132 |
2
|
ReflectionUtils.getConstructor(A.class, new StringBuilder()); |
133 |
|
} |
134 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
135 |
2
|
@Test(expected = NoSuchMethodException.class)... |
136 |
|
public void testGetConstructor_notFound() throws NoSuchMethodException { |
137 |
2
|
ReflectionUtils.getConstructor(A.class, true); |
138 |
|
} |
139 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
140 |
2
|
@Test(expected = NoSuchMethodException.class)... |
141 |
|
public void testGetConstructor_WrongParams() throws NoSuchMethodException { |
142 |
2
|
ReflectionUtils.getConstructor(A.class, "", ""); |
143 |
|
} |
144 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
1
PASS
|
|
145 |
2
|
@Test... |
146 |
|
public void testGetConstructor_AllPrimitives() throws NoSuchMethodException { |
147 |
2
|
final Constructor<A> c = ReflectionUtils.getConstructor(A.class, true, (byte) 1, 2, (short) 3, 'g', |
148 |
|
5l, 4.0f, 8.0); |
149 |
2
|
assertNotNull(c); |
150 |
|
} |
151 |
|
} |