Mockito:列出泛型的匹配器 [英] Mockito: List Matchers with generics
本文介绍了Mockito:列出泛型的匹配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ b
when(mock.process (Matchers.any(List.class)));
code> process 需要一个 List< Bar>
而不是?
when(mock。处理(Matchers.anyList()));
对于Java 7及更低版本,编译器需要一些帮助。使用 anyListOf(Class< T> clazz)
:
when(mock .process(Matchers.anyListOf(Bar.class)));
Mockito offers:
when(mock.process(Matchers.any(List.class)));
How to avoid warning if process
takes a List<Bar>
instead?
解决方案
For Java 8 and above, it's easy:
when(mock.process(Matchers.anyList()));
For Java 7 and below, the compiler needs a bit of help. Use anyListOf(Class<T> clazz)
:
when(mock.process(Matchers.anyListOf(Bar.class)));
这篇关于Mockito:列出泛型的匹配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文