简体   繁体   English

Mockito.verify方法包含布尔值和参数captor

[英]Mockito.verify method contain boolean and argument captor

I don't know how can I use Mockito.verify in this case. 在这种情况下,我不知道如何使用Mockito.verify How can I pass false to Mockito.verify? 如何将false传递给Mockito.verify? I try 2 different ways but it does not work. 我尝试了两种不同的方法,但它不起作用。

public Sample someMethod(Sample s, boolean a){....}
@Test
public void test() {
...
verify(mock).someMethod(sampleCaptor.capture(), false));
verify(mock).someMethod(sampleCaptor.capture(), org.mockito.Matchers.eq(false)));
...
}

You have it right the second way: 第二种方式你是对的:

verify(mock).someMethod(sampleCaptor.capture(), Matchers.eq(false));

When using Matchers (including ArgumentCaptor.capture), you have to use a Matcher for every value, because Matchers work via side-effects . 使用Matchers(包括ArgumentCaptor.capture)时,必须为每个值使用Matcher,因为Matchers通过副作用工作

If the above doesn't work, you may be misusing matchers earlier in the method. 如果上述方法不起作用,您可能会在方法的早期误用匹配器。 It is sometimes helpful to explicitly call Mockito.validateMockitoUsage() immediately before your call to verify , to ensure that there's nothing wrong with Mockito's internal state. 在你的电话verify之前立即明确地调用Mockito.validateMockitoUsage()有时很有帮助,以确保Mockito的内部状态没有任何问题。 (Additional information about how it "does not work", including a minimal reproducible example, may be helpful in solving your specific case.) (关于它如何“不起作用”的附加信息,包括最小的可重复示例,可能有助于解决您的具体情况。)

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

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