Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mockito anyListOf() List<List<String>>

I'm using mockito-core:2.8.47 and Java 7 and want to use in a when and verify anyListOf or some other any method. My Problem is, if I just use anyList it says:

The method name( int, List < List < String > >) in the type Y is not
applicable for the arguments ( int, List < Object > )

How can I fix this?

ArgumentMatchers.anyListOf(ArgumentMatchers.anyListOf( String.class ) ) doesn't work...

like image 977
Ganymed Avatar asked Oct 13 '25 10:10

Ganymed


1 Answers

In my opinion you can get away with just the basic anyList() method with additional generics information:

Mockito.doReturn("1").when(classMock).name(ArgumentMatchers.eq(1)
                , ArgumentMatchers.<List<String>>anyList());

This worked for me and also remember to add the ArgumentMatcher for the first int variable otherwise Mockito will fail.

like image 181
Maciej Kowalski Avatar answered Oct 15 '25 00:10

Maciej Kowalski