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.easymock.EasyMock.*; |
20 |
|
import static org.junit.Assert.*; |
21 |
|
|
22 |
|
import java.lang.reflect.InvocationHandler; |
23 |
|
import java.lang.reflect.Method; |
24 |
|
import java.lang.reflect.Proxy; |
25 |
|
|
26 |
|
import org.junit.Before; |
27 |
|
import org.junit.Test; |
28 |
|
|
29 |
|
|
30 |
|
@author |
31 |
|
|
|
|
| 99% |
Uncovered Elements: 1 (102) |
Complexity: 15 |
Complexity Density: 0,17 |
|
32 |
|
public class UsageVarargTest { |
33 |
|
|
34 |
|
private IVarArgs mock; |
35 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
36 |
24
|
@Before... |
37 |
|
public void setup() { |
38 |
24
|
mock = createStrictMock(IVarArgs.class); |
39 |
|
} |
40 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0,08 |
1
PASS
|
|
41 |
2
|
@Test... |
42 |
|
public void varargObjectAccepted() { |
43 |
2
|
mock.withVarargsString(1, "1"); |
44 |
2
|
mock.withVarargsString(2, "1", "2"); |
45 |
2
|
mock.withVarargsString(2, "1", "2"); |
46 |
2
|
mock.withVarargsObject(3, "1"); |
47 |
2
|
mock.withVarargsObject(4, "1", "2"); |
48 |
|
|
49 |
2
|
replay(mock); |
50 |
2
|
mock.withVarargsString(1, "1"); |
51 |
2
|
mock.withVarargsString(2, "1", "2"); |
52 |
2
|
mock.withVarargsString(2, "1", "2"); |
53 |
2
|
mock.withVarargsObject(3, "1"); |
54 |
2
|
mock.withVarargsObject(4, "1", "2"); |
55 |
2
|
verify(mock); |
56 |
|
} |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
1
PASS
|
|
58 |
2
|
@Test... |
59 |
|
public void varargBooleanAccepted() { |
60 |
2
|
mock.withVarargsBoolean(1, true); |
61 |
2
|
mock.withVarargsBoolean(2, true, false); |
62 |
|
|
63 |
2
|
replay(mock); |
64 |
2
|
mock.withVarargsBoolean(1, true); |
65 |
2
|
mock.withVarargsBoolean(2, true, false); |
66 |
2
|
verify(mock); |
67 |
|
} |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
1
PASS
|
|
69 |
2
|
@Test... |
70 |
|
public void varargByteAccepted() { |
71 |
2
|
mock.withVarargsByte(1, (byte) 1); |
72 |
2
|
mock.withVarargsByte(2, (byte) 1, (byte) 2); |
73 |
|
|
74 |
2
|
replay(mock); |
75 |
2
|
mock.withVarargsByte(1, (byte) 1); |
76 |
2
|
mock.withVarargsByte(2, (byte) 1, (byte) 2); |
77 |
2
|
verify(mock); |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
1
PASS
|
|
80 |
2
|
@Test... |
81 |
|
public void varargCharAccepted() { |
82 |
2
|
mock.withVarargsChar(1, 'a'); |
83 |
2
|
mock.withVarargsChar(1, 'a', 'b'); |
84 |
|
|
85 |
2
|
replay(mock); |
86 |
2
|
mock.withVarargsChar(1, 'a'); |
87 |
2
|
mock.withVarargsChar(1, 'a', 'b'); |
88 |
2
|
verify(mock); |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
1
PASS
|
|
91 |
2
|
@Test... |
92 |
|
public void varargDoubleAccepted() { |
93 |
2
|
mock.withVarargsDouble(1, 1.0d); |
94 |
2
|
mock.withVarargsDouble(1, 1.0d, 2.0d); |
95 |
|
|
96 |
2
|
replay(mock); |
97 |
2
|
mock.withVarargsDouble(1, 1.0d); |
98 |
2
|
mock.withVarargsDouble(1, 1.0d, 2.0d); |
99 |
2
|
verify(mock); |
100 |
|
} |
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
1
PASS
|
|
102 |
2
|
@Test... |
103 |
|
public void varargFloatAccepted() { |
104 |
2
|
mock.withVarargsFloat(1, 1.0f); |
105 |
2
|
mock.withVarargsFloat(1, 1.0f, 2.0f); |
106 |
|
|
107 |
2
|
replay(mock); |
108 |
2
|
mock.withVarargsFloat(1, 1.0f); |
109 |
2
|
mock.withVarargsFloat(1, 1.0f, 2.0f); |
110 |
2
|
verify(mock); |
111 |
|
} |
112 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
1
PASS
|
|
113 |
2
|
@Test... |
114 |
|
public void varargIntAccepted() { |
115 |
2
|
mock.withVarargsInt(1, 1); |
116 |
2
|
mock.withVarargsInt(1, 1, 2); |
117 |
|
|
118 |
2
|
replay(mock); |
119 |
2
|
mock.withVarargsInt(1, 1); |
120 |
2
|
mock.withVarargsInt(1, 1, 2); |
121 |
2
|
verify(mock); |
122 |
|
} |
123 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
1
PASS
|
|
124 |
2
|
@Test... |
125 |
|
public void varargLongAccepted() { |
126 |
2
|
mock.withVarargsLong(1, (long) 1); |
127 |
2
|
mock.withVarargsLong(1, 1, 2); |
128 |
|
|
129 |
2
|
replay(mock); |
130 |
2
|
mock.withVarargsLong(1, (long) 1); |
131 |
2
|
mock.withVarargsLong(1, 1, 2); |
132 |
2
|
verify(mock); |
133 |
|
} |
134 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
1
PASS
|
|
135 |
2
|
@Test... |
136 |
|
public void varargShortAccepted() { |
137 |
2
|
mock.withVarargsShort(1, (short) 1); |
138 |
2
|
mock.withVarargsShort(1, (short) 1, (short) 2); |
139 |
|
|
140 |
2
|
replay(mock); |
141 |
2
|
mock.withVarargsShort(1, (short) 1); |
142 |
2
|
mock.withVarargsShort(1, (short) 1, (short) 2); |
143 |
2
|
verify(mock); |
144 |
|
} |
145 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0,14 |
1
PASS
|
|
146 |
2
|
@Test... |
147 |
|
public void varargAcceptedIfArrayIsGiven() { |
148 |
2
|
final IVarArgs object = (IVarArgs) Proxy.newProxyInstance(Thread.currentThread() |
149 |
|
.getContextClassLoader(), new Class[] { IVarArgs.class }, new InvocationHandler() { |
150 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
151 |
12
|
public Object invoke(final Object proxy, final Method method, final Object[] args)... |
152 |
|
throws Throwable { |
153 |
12
|
return null; |
154 |
|
} |
155 |
|
}); |
156 |
2
|
object.withVarargsObject(1); |
157 |
2
|
object.withVarargsObject(1, (Object) null); |
158 |
2
|
object.withVarargsObject(1, (Object[]) null); |
159 |
2
|
object.withVarargsObject(1, new Object[0]); |
160 |
2
|
object.withVarargsObject(1, false); |
161 |
2
|
object.withVarargsObject(1, new boolean[] { true, false }); |
162 |
|
} |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0,07 |
1
PASS
|
|
167 |
2
|
@Test... |
168 |
|
public void allKinds() { |
169 |
2
|
mock.withVarargsObject(eq(1), aryEq((Object[]) null)); |
170 |
2
|
mock.withVarargsObject(eq(1), isNull()); |
171 |
2
|
mock.withVarargsObject(1, "a", "b"); |
172 |
2
|
mock.withVarargsObject(1, "a", "b"); |
173 |
2
|
mock.withVarargsObject(eq(1), aryEq(new Object[] { "a", "b" })); |
174 |
2
|
mock.withVarargsObject(1); |
175 |
2
|
replay(mock); |
176 |
2
|
mock.withVarargsObject(1, (Object[]) null); |
177 |
2
|
mock.withVarargsObject(1, (Object) null); |
178 |
2
|
mock.withVarargsObject(1, "a", "b"); |
179 |
2
|
mock.withVarargsObject(1, new Object[] { "a", "b" }); |
180 |
2
|
mock.withVarargsObject(1, (Object) new Object[] { "a", "b" }); |
181 |
2
|
mock.withVarargsObject(1); |
182 |
2
|
verify(mock); |
183 |
|
} |
184 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
185 |
2
|
@Test... |
186 |
|
public void differentLength() { |
187 |
2
|
mock.withVarargsInt(1, 2, 3); |
188 |
2
|
replay(mock); |
189 |
2
|
try { |
190 |
2
|
mock.withVarargsInt(1, 2); |
191 |
0
|
fail("not the same number of params"); |
192 |
|
} catch (final AssertionError e) { |
193 |
|
|
194 |
|
} |
195 |
|
} |
196 |
|
} |