Mockito: Verifying with generic parameters

Svish picture Svish · May 30, 2011 · Viewed 37.8k times · Source

With Mockito I can do the following:

verify(someService).process(any(Person.class));

But how do I write this if process takes a Collection<Person> instead? Can't figure out how to write it correctly. Just getting syntax errors...

Answer

Tomasz Nurkiewicz picture Tomasz Nurkiewicz · May 30, 2011

Try:

verify(someService).process(Matchers.<Collection<Person>>any());

Actually, IntelliJ automatically suggested this fix when I typed any()... Unfortunately you cannot use static import in this case.