O'Reilly logo

Mockito Cookbook by Marcin Grzejszczak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required