Mockito.any() 通过泛型接口

2022-01-14 00:00:00 mockito java generics

是否可以使用泛型传递接口的类型?

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

界面:

public interface AsyncCallback<T>

在我的测试方法中:

Mockito.any(AsyncCallback.class)

<ResponseX> 放在 .class 后面或为 .class 不起作用.

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

推荐答案

有一种类型安全的方法:使用 ArgumentMatchers.any() 并用类型限定它:

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

ArgumentMatchers.<AsyncCallback<ResponseX>>any()

相关文章