Verifying the order of interactions

In this recipe, we will verify that a set of methods get executed in the specified order.

Getting ready

For this recipe, our system under test will be TaxUpdator which is a simplified version of a facade that calls the TaxService methods (let's assume that it is a web service) to update tax-related data and perform a series of tax transfers. Let's assume that this web service is a legacy, a badly-written system, and we have to synchronously call it in a precisely defined sequence.

Let's take a look at the implementation of the TaxUpdator class:

public class TaxUpdator { public static final int TAX_FACTOR = 100; private final TaxService taxService; public TaxUpdator(TaxService taxService) { this.taxService = taxService; ...

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.