[英]ArgumentCaptor for generic method in Mockito
I have an object that I've mocked. 我有一个我嘲笑的对象。 This object has the following method:
该对象具有以下方法:
<R, M extends SomeAbstractClass<R>> List<R> execute(List<M> list)
And there are two calls for this method: 此方法有两个调用:
execute(List<A>);
execute(List<B>);
where class A extends SomeAbstractClass<String>
and B extends SomeAbstractClass<Void>
. 其中,类
A extends SomeAbstractClass<String>
而类B extends SomeAbstractClass<Void>
。
Is there any way to use ArgumentCaptor for this case? 在这种情况下,有什么方法可以使用ArgumentCaptor吗? I want to do something like this:
我想做这样的事情:
verify(..., times(3)).execute(argumentCaptor.capture())
I think (but not sure) this problem can't be solved since A and B doesn't have common ancestor which extends SomeAbstractClass<R>
. 我认为(但不确定)此问题无法解决,因为A和B没有共同的祖先,该祖先扩展了
SomeAbstractClass<R>
。
Anyway, thank you for any suggestions. 无论如何,谢谢您的任何建议。
I've found the solution. 我找到了解决方案。 If anybody interested we can use the following syntax for ArgumentCaptor:
如果有兴趣的人,我们可以对ArgumentCaptor使用以下语法:
ArgumentCaptor<List<? extends SomeAbstractClass>>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.