在升级到 Java 8 之后,之前有效的测试开始失败。 这是测试部分:
verify(session, times(1)).reject(any(), any(), any());
拒绝方法如下:
public void reject(@SuppressWarnings("hiding") String fieldName, Object... args) {
reject(fieldName, null, args);
}
这是错误信息:
Wanted but not invoked:
ruleSession.reject(<any>, <any>, <any>);
However, there were other interactions with this mock:
ruleSession.reject(
"year",
2000,
2000
);
可以看到,确实调用了reject方法,但是Mockito无法识别。我猜这与 Object... args 有关
然而,当使用两个参数运行该方法时:
verify(session).reject(any(), any());
错误是:
Actual invocation has different arguments:
ruleSession.reject(
"year",
2000,
2000
);
我正在使用 Mockito 版本 1.10.19
最佳答案
看来我需要更换
verify(session, times(1)).reject(any(), any(), any());
与:
verify(session, times(1)).reject(any(), anyVararg());
因为旧方法在 Java 8 中不再适用。
关于java - 升级 Java 后,Mockito 验证方法因 Object...args 而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32375740/