Mockito.any()通过泛型接口 [英] Mockito.any() pass Interface with Generics
本文介绍了Mockito.any()通过泛型接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
接口:
<$ p $
是否可以传递泛型类型的接口? p> public interface AsyncCallback< T>
在我的测试方法中:
Mockito.any(AsyncCallback.class)
将< ResponseX>
后面或 .class
没有用。
解决方案
有一种类型安全的方法:使用 ArgumentMatchers.any()
并使用类型限定它:
ArgumentMatchers。< AsyncCallback< ResponseX>>任何()
作为评论中提到的pierrefevrier,新版本的Mockito它是
Matchers。< ; AsyncCallback< ResponseX>> any()
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.
解决方案
There is a type-safe way: use ArgumentMatchers.any()
and qualify it with the type:
ArgumentMatchers.<AsyncCallback<ResponseX>>any()
as pierrefevrier mentioned in the comments, with the new versions of Mockito it's
Matchers.<AsyncCallback<ResponseX>>any()
这篇关于Mockito.any()通过泛型接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文