Mockito.any() pass Interface with Generics

前端 未结 7 1310
我在风中等你
我在风中等你 2020-11-29 16:26

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

The interface:

public interface AsyncCallback

In my test me

7条回答
  •  佛祖请我去吃肉
    2020-11-29 17:12

    You can just cast it, adding suppress warnings if you like:

    @SuppressWarnings("unchecked")    
    AsyncCallback callback = Mockito.any(AsyncCallback.class)
    

    If Java allowed 'generic' generics they could have a method like this which is what you are looking for

    private static  T mock(Class> clazz)
    

提交回复
热议问题