In this recipe, we will verify that a specified method on a mock was executed and then any interactions stopped taking place.
For this recipe, our system under test will be a TaxTransferer
class that will transfer tax for a non-null person. If the passed person value is null, then an error report is sent:
public class TaxTransferer { private final TaxService taxService; public TaxTransferer(TaxService taxService) { this.taxService = taxService; } public void transferTaxFor(Person person) { if (person == null) { taxService.sendErrorReport(); return; } taxService.transferTaxFor(person); } }