verifyNoMoreInteractions() is not a framework contract that you have
to remember and write for every test method.
verifyNoMoreInteractions() is just an assertion from the interaction
testing toolkit. Use it only if it is relevant. Have a look at this
dummy example:
someMethod() {
service.foo();
service.bar();
}
For above code I wouldn't use verifyNoMoreInteractions().
However in following scenario:
someMethod() {
if (condition) {
service.foo();
} else {
service.bar();
service.baz();
}
}
it perfectly makes sense to do the following:
shouldFooWhenCondition() {
...
verify(service).foo();
verifyNoMoreInteractions(service);
}
I use verifyNoMoreInteractions() only if it describes relevant application code.
Cheers,
Szczepan Faber
shouldFooWhenCondition() {
...
verify(service).foo();
verify(service, never()).bar();
verify(service, never()).baz();
}
However, when there's more than a few undesirable interaction,
verifyNoMoreInteractions() is much more convenient.
Igor