Skip to content

Instantly share code, notes, and snippets.

@henieek
Created August 27, 2015 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henieek/333b128620d959c41f6b to your computer and use it in GitHub Desktop.
Save henieek/333b128620d959c41f6b to your computer and use it in GitHub Desktop.
verify with reset
@Test
public void shouldConsume() throws Exception {
component.doSomething();
verify(component).doSomething();
component.doSomething();
verify(component).doSomething();
}
private static <T> T verify(T mock) {
return Mockito.verify(mock, resetMode);
}
private static ResetMode resetMode = new ResetMode();
private static class ResetMode implements VerificationMode {
private int lastPosition = 0;
@Override
public void verify(final VerificationData data) {
final List<Invocation> allInvocations = data.getAllInvocations();
VerificationData dataWrapper = new VerificationData() {
@Override
public List<Invocation> getAllInvocations() {
return allInvocations.subList(lastPosition, allInvocations.size());
}
@Override
public InvocationMatcher getWanted() {
return data.getWanted();
}
};
VerificationModeFactory.times(1).verify(dataWrapper);
lastPosition = allInvocations.size();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment