你想要一个部分模拟。假设具有的类名为 Bar:setFoo()
private static abstract class AssertingBar implements Bar {
@Override
void setFoo(int offset, float[] floats) {
this.offset = offset;
this.floats = floats
}
public void verify(float[] expectedFloats, float delta) {
// do your verification here
}
}
@Test
public void valuesShouldBeCloseEnough() {
AssertingBar bar = Mockito.mock(AssertingBar.class, Mockito.CALLS_REAL_METHODS);
Sut sut = new Sut(bar);
sut.doSomething();
bar.verify(...);
}
如果 是类,而不是接口,则可以使用Bar
doCallRealMethod()