Elye Elye - 1 month ago 12
Java Question

Unit Test Any: Unchecked assignment from 'java.util.List' to 'java.util.List<java.lang.Long>'. How to fix?

In my unit test, I am verifying a function that get List variable

verify(myMockObj).myFunction(any(List.class));


Hence it complains

Unchecked assignment from 'java.util.List' to 'java.util.List<java.lang.Long>'


I can't change to

verify(myMockObj).myFunction(any(List<Long>.class));


How could I fix it?

Answer

That's how you can fix it:

verify(myMockObj).myFunction(Matchers.<List<Long>>any());