I\'m using Mockito to write a unit test in Java, and I\'d like to verify that a certain method is the last one called on an object.
I\'m doing something lik
I think it requires more custom work.
verify(row, new LastCall()).saveToDatabase();
and then
public class LastCall implements VerificationMode {
public void verify(VerificationData data) {
List invocations = data.getAllInvocations();
InvocationMatcher matcher = data.getWanted();
Invocation invocation = invocations.get(invocations.size() - 1);
if (!matcher.matches(invocation)) throw new MockitoException("...");
}
}
Previous Answer:
You are right. verifyNoMoreInteractions is what you need.
verify(row).setSomething(value);
verify(row).setSomethingElse(anotherValue);
verify(row).editABunchMoreStuff();
verify(row).saveToDatabase();
verifyNoMoreInteractions(row);