Mockito:使用泛型参数进行验证 [英] Mockito: Verifying with generic parameters

查看:37
本文介绍了Mockito:使用泛型参数进行验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Mockito,我可以做到以下几点:

With Mockito I can do the following:

verify(someService).process(any(Person.class));

但是,如果 process 采用 Collection 代替,我该怎么写呢?无法弄清楚如何正确编写它.只是遇到语法错误...

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...

推荐答案

试试:

verify(someService).process(Matchers.<Collection<Person>>any());

实际上,当我键入 any() 时,IntelliJ 会自动建议此修复程序...不幸的是,在这种情况下您不能使用静态导入.

Actually, IntelliJ automatically suggested this fix when I typed any()... Unfortunately you cannot use static import in this case.

这篇关于Mockito:使用泛型参数进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆