升级后 Mockito 验证方法因 Object...args 而失败 Java
Mockito verify method fails with Object... args after upgrading Java
升级到 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 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.
中不再适用