Mockito:使用通用参数进行验证 [英] Mockito: Verifying with generic parameters
本文介绍了Mockito:使用通用参数进行验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ b $ pre $
verify(someService).process(any(Person.class));
但是,如果 process
需要一个集合< Person>
来代替?无法弄清楚如何正确编写它。
解决方案
试试:
验证(someService).process(匹配器<收集和LT;人>>任何());
实际上,当我键入 any() code> ...不幸的是,在这种情况下,您不能使用静态导入。
With Mockito I can do the following:
verify(someService).process(any(Person.class));
But how do I write this if process
takes a Collection<Person>
instead? Can't figure out how to write it correctly. Just getting syntax errors...
解决方案
Try:
verify(someService).process(Matchers.<Collection<Person>>any());
Actually, IntelliJ automatically suggested this fix when I typed any()
... Unfortunately you cannot use static import in this case.
这篇关于Mockito:使用通用参数进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文