how do I match vararg parameter if I do not care about the values?

62 views
Skip to first unread message

nanoSK

unread,
Mar 20, 2009, 6:49:56 AM3/20/09
to mockito
Hello there,

the following method is given:

public Set<GUICommand> getCommandsByGroups(final Class<? extends View>
viewClass, final CommandGroup... commandGroups)

Since I do not care about the commandGroups given I'd like to do the
following verification:

Mockito.verify(myMock).getCommandsByGroups(Mockito.eq
(AdditionalCostTypeMDView.class), Mockito.any????));

Which matcher can I use/implement for the commandGroups parameter?

I've been trying various matchers, i.e.
class CommandGroupArrayMatcher extends ArgumentMatcher<CommandGroup[]
> {
@Override
public boolean matches(Object argument) {
return true;
}

}

But this does not work:
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 1 matchers expected, 2 recorded. <<<<<<<<<<<<<<<<<<<<<
This exception may occur if matchers are combined with raw values:
//incorrect:
someMethod(anyObject(), "raw String");
When using matchers, all arguments have to be provided by matchers.
For example:
//correct:
someMethod(anyObject(), eq("String by matcher"));

For more info see javadoc for Matchers class.

Why does Mockito expect just one matcher?



Any help?

nanoSK

unread,
Mar 23, 2009, 4:36:08 AM3/23/09
to mockito
I found Issue-62 dealing with the same problem:
http://code.google.com/p/mockito/issues/detail?id=62
Reply all
Reply to author
Forward
0 new messages