Created
August 27, 2015 21:19
-
-
Save henieek/333b128620d959c41f6b to your computer and use it in GitHub Desktop.
verify with reset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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