In this recipe, we will stub a void method. It doesn't return a value, so it returns a custom answer.
In this recipe, we'll reuse the example from the previous recipes. A quick reminder again – we have a system under test that consists of two objects: a PersonDataUpdator
class that delegates work to TaxFactorService
. The output of the system is a calculation of a mean value of tax factors (we have a fixed value for that). The person's data then gets updated via a web service. In this scenario, we will verify how our system works when an exception related to connectivity issues occurs. Have a look at the following code:
public class PersonDataUpdator { private final TaxFactorService taxFactorService; public PersonDataUpdator(TaxFactorService taxFactorService) { this.taxFactorService = taxFactorService; } public boolean processTaxDataFor(Person person) { try { double meanTaxFactor = taxFactorService...