简体   繁体   English

Mockito参数捕获器和only()

[英]Mockito argument captor and only()

I found, that whenever I use verify with only() - to check that invocation was just one time - ArgumentCaptor can't capture a value (I have null in value). 我发现,每当我通过对only()使用verify-检查调用是否只有一次-ArgumentCaptor都无法捕获值(我的值为null)。

For instance: verify(delegate, only()).call(captor.capture()); 例如:verify(delegate,only())。call(captor.capture());

What are the reasons for it? 原因是什么? Or it is just a bug? 还是只是一个错误?

Not sure what only() is actually doing, but Mockito.times(1) works, while the only() fails. 不知道only()实际在做什么,但是Mockito.times(1)可以工作,而only()失败。

My guess is when you call Mockito.when initially it's counted as the first invocation in case of only() , but not in Mockito.times 我的猜测是当您调用Mockito.when时,在only()情况下,最初它被视为第一次调用,但在Mockito.timesMockito.times被视为第一次调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM