Mockito: Verifying with generic parameters(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:使用泛型参数进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Mockito:使用泛型参数进行验证


基础教程推荐
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 存储 20 位数字的数据类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01