Stubbing void methods so that they return custom answers

In this recipe, we will stub a void method. It doesn't return a value, so it returns a custom answer.

Getting ready

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 ...

Get Mockito Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.