10000 Drop varargs collector before invoking a user method. · mockito/mockito@160e3da · GitHub
[go: up one dir, main page]

Skip to content

Commit 160e3da

Browse files
committed
Drop varargs collector before invoking a user method.
1 parent e123c2c commit 160e3da

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/main/java/org/mockito/internal/util/reflection/InstrumentationMemberAccessor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ public Object invoke(Method method, Object target, Object... arguments)
235235
if (!Modifier.isStatic(method.getModifiers())) {
236236
handle = handle.bindTo(target);
237237
}
238+
if (handle.isVarargsCollector()) {
239+
handle = handle.asFixedArity();
240+
}
238241
try {
239242
return DISPATCHER.invokeWithArguments(handle, arguments);
240243
} catch (Throwable t) {

subprojects/inline/src/test/java/org/mockitoinline/StaticMockTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ public void testStaticMockMustUseValidMatchers() {
212212
}
213213
}
214214

215+
@Test
216+
public void testStaticMockVarargs() {
217+
assertEquals("foobar", Dummy.fooVarargs("foo", "bar"));
218+
try (MockedStatic<Dummy> ignored = Mockito.mockStatic(Dummy.class)) {
219+
assertNull(Dummy.fooVarargs("foo", "bar"));
220+
}
221+
assertEquals("foobar", Dummy.fooVarargs("foo", "bar"));
222+
}
223+
215224
static class Dummy {
216225

217226
static String var1 = null;
@@ -227,5 +236,13 @@ static void fooVoid(String var2) {
227236
static void fooVoid(String var2, String var3) {
228237
var1 = var2;
229238
}
239+
240+
static String fooVarargs(String... args) {
241+
StringBuilder sb = new StringBuilder();
242+
for (String arg : args) {
243+
sb.append(arg);
244+
}
245+
return sb.toString();
246+
}
230247
}
231248
}

0 commit comments

Comments
 (0)
0