使用MockFor时,我怎样才能让它验证一个方法至少被调用了n 次?我尝试在设置需求后忽略方法调用,如下所示:
import groovy.mock.interceptor.MockFor;
import org.junit.Test
class FilterTest {
interface Filter {
boolean isEnabled()
}
@Test
public void test() {
MockFor mockContext = new MockFor(Filter)
// Expect at least one call
mockContext.demand.isEnabled {true}
mockContext.ignore.isEnabled {false}
// Obtaining a usuable mock instance
def filter = mockContext.proxyInstance()
// Fake calling the method
filter.isEnabled()
filter.isEnabled()
// Verify invoked at least once?
mockContext.verify(filter)
}
}
但是,我得到一个断言失败:
junit.framework.AssertionFailedError: verify[0]: expected 1..1 call(s) to
'isEnabled' but was called 0 time(s).