我Mockito.spy(...)
在非 Mock 对象上使用来验证它的方法之一是否从未被调用。但是,有一个歧义,因为我只是在使用any(), any()
,并且有两个带有两个参数的重载:
我对 Java 有点陌生,无法找出正确的方式来表达 Mockito 对我的要求。我认为我对 Java 中的反射概念没有很好的处理,例如Class
, Function
, lambdas 等之间的区别。
这是该方法的实际(非 Mockito)使用示例:
return jdbiExecutor.execute(Foo.class,
foo -> {
// Some code.
return Bar.newBuilder().build();
});
所以,我要验证的是第一个重载,Function<D, T>
它的第二个参数是 a。我尝试过但不起作用的一些事情:
// Is specifying just one of the parameters enough?
verifyZeroInteractions(executor.execute(any(Foo, any()));
// Maybe I need to supply the `.class()`?
verifyZeroInteractions(executor.execute(any(Foo.class, any()));
// Or literally, `Class<Foo>`?
verifyZeroInteractions(executor.execute(any(Class<Foo>), any()));
// Or what, do I _have_ to specify both parameters to some degree?
我怎样才能让它工作?