Verifying interactions and ignoring stubbed methods
In this recipe, we will perform the verification of the interaction with a mock, but at the same time, we will ignore the stubbed methods from this verification.
Getting ready
For this recipe, our system under test will be a TaxTransferer
class that will transfer tax through the web service for the given person if this person is not null. It will send a statistics report regardless of the fact whether the transfer took place or not:
public class TaxTransferer { private final TaxService taxService; public TaxTransferer(TaxService taxService) { this.taxService = taxService; } public boolean transferTaxFor(Person person) { if(person != null) { taxService.transferTaxFor(person); } return taxService.sendStatisticsReport(); } }
How to do it…
To verify a mock's behavior in such a way that Mockito ignores the stubbed methods, you have to either call Mockito.verifyNoMoreInteractions...