【发布时间】:2018-08-23 09:50:18
【问题描述】:
我有一个服务类,方法如下:
void doSomething(List<String> list)
我模拟了这个类,我想验证作为参数传递的列表是否只有一个元素。我是这样做的:
verify(myService).doSomething((List<String>) argThat(hasSize(1))))
如您所见 我必须将参数转换为 List<String> 否则它不会被编译:
incompatible types: inferred type does not conform to upper bound(s)
inferred: java.util.Collection<? extends java.lang.Object>
upper bound(s): java.util.List<java.lang.String>,java.lang.Object
问题:如何在不进行强制转换的情况下验证调用?我想让事情保持简单、可读和优雅。
【问题讨论】:
标签: java junit mockito junit4 hamcrest