Capturing and asserting the argument

In this recipe, we will capture an argument passed to the mock's method to perform further verification.

Getting ready

For this recipe, our system under test will be a TaxTransferer class that will prepare the person to be sent through the web service by marking him a Polish citizen. Only if the person is not null, the transfer of tax will take place. Let's also assume that it is absolutely crucial for us to make sure that the person that we send via the web service contains very specific data:

public class TaxTransferer { static final String POLAND = "Poland"; private final TaxService taxService; public TaxTransferer(TaxService taxService) { this.taxService = taxService; } public void transferTaxFor(Person person) ...

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.