Book Image

Mockito Cookbook

By : Marcin Grzejszczak
Book Image

Mockito Cookbook

By: Marcin Grzejszczak

Overview of this book

Table of Contents (17 chapters)
Mockito Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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

    public void transferTaxFor(Person person) {
        taxService.updateTaxFactor(person, calculateTaxFactor(1));
        taxService.transferTaxFor(person);
        taxService.transferTaxFor(person);
        taxService...