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

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

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