Mockito.any() pass Interface with Generics

lrxw picture lrxw · Oct 27, 2011 · Viewed 85.3k times · Source

is it possible to pass the type of an interface with generics?

The interface:

public interface AsyncCallback<T>

In my test method:

Mockito.any(AsyncCallback.class)

Putting <ResponseX> behind or for .class didnt work.

Answer

thSoft picture thSoft · Dec 18, 2012

There is a type-safe way: use ArgumentMatchers.any() and qualify it with the type:

ArgumentMatchers.<AsyncCallback<ResponseX>>any()