0

I'm trying to run this line:

verify(imagesSorterSpy, atLeast(2)).sortImages(anyList(), null);

to verify this method was called with null as second argument.

but i get this error:

rg.mockito.exceptions.misusing.InvalidUseOfMatchersException: 
Invalid use of argument matchers!
2 matchers expected, 1 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"));

how can I verify invocation with null as 2nd arg?

Elad Benda
  • 35,076
  • 87
  • 265
  • 471

1 Answers1

1

Error indicates you cannot mix raw or real values with matchers.

Since i dont know the method sortImages signature, am going to guess

sortImage(List, String).

If thats the case, the below should work.

verify(imagesSorterSpy, atLeast(2)).sortImages(anyList(), isNull(String.class));

isNull is from org.mockito.Matchers.isNull

Sajan Chandran
  • 11,287
  • 3
  • 29
  • 38
  • In any case. It is worth mentioning that when using explicit matchers, they have to be used for all arguments of the stub. – bric3 Oct 01 '14 at 11:01
  • how can I limit the anyList() to non-empty lists or a list which is greater than 2 ? – Elad Benda Oct 01 '14 at 11:41