-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Description
VarargMatcher
is an internal interface used to match some matchers as 'varargs aware'.
When MatcherApplicationStrategy
sees a VarargMatcher
passed as the last matcher to a varargs method, it will use this matcher to match each value passed to the varargs parameter.
This approach has been identified as broken, as it does not allow users to differentiate between matching an invocation where a single value is passed to the varargs parameter from an invocation matching any number of parameters.
// For example, given:
String varargsMethod(String... args);
when(mock.varargsMethod(any()).thenReturn("any()");
when(mock.varargsMethod(any(), any()).thenReturn("any(), any()");
// Then:
// The following invocation will match the second mocking and therefore return "any(), any()"
mock.varargsMethod("1", "2");
// So far so good, ...but all the following invocations will match the first mocking and therefore return "any()":
mock.varargsMethod();
mock.varargsMethod("1");
mock.varargsMethod("1", "2", "3");
// i.e. there is no way to say "match exactly 1 param"
Metadata
Metadata
Assignees
Labels
No labels