Creating mocks with annotations
In the previous recipe, we saw how to create a mock by means of the Mockito.mock
static method. It's much better, however, to use Mockito's annotations to make your tests look even nicer. Before going into the details of how to do it, let's take a closer look at the system under test (it's the same as in the previous recipe, but in order for you not to jump around pages, let's take a look at it here).
Getting ready
In this recipe, our system under test is a class that calculates a mean value of tax factors retrieved through a web service, as shown in the following code:
public class MeanTaxFactorCalculator { private final TaxService taxService; public MeanTaxFactorCalculator(TaxService taxService) { this.taxService = taxService; } public double calculateMeanTaxFactorFor(Person person) { double currentTaxFactor = taxService.getCurrentTaxFactorFor(person); double anotherTaxFactor = taxService...