Reputation: 135
After upgrading to Java 8 a test, which previously worked, has started to fail. Here is the test part:
verify(session, times(1)).reject(any(), any(), any());
Here is the reject method:
public void reject(@SuppressWarnings("hiding") String fieldName, Object... args) {
reject(fieldName, null, args);
}
Here is the error message:
Wanted but not invoked:
ruleSession.reject(<any>, <any>, <any>);
However, there were other interactions with this mock:
ruleSession.reject(
"year",
2000,
2000
);
As you can see, the reject method is actually called, but Mockito can't identify it. I'm guess it has something to do with Object... args
However when running the method with two args:
verify(session).reject(any(), any());
The error is:
Actual invocation has different arguments:
ruleSession.reject(
"year",
2000,
2000
);
I'm using Mockito version 1.10.19
Upvotes: 3
Views: 712
Reputation: 135
It appears that I need to replace
verify(session, times(1)).reject(any(), any(), any());
with:
verify(session, times(1)).reject(any(), anyVararg());
As the old way no longer works in Java 8.
Upvotes: 1