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

Creating mocks with a different default answer


If not changed by the custom configuration, Mockito sets the mock ReturnsEmptyValues answer by default (for details on that answer, please check the subsequent There's more... section). Note that in Chapter 4, Stubbing Behavior of Mocks, where we deal with stubbing of particular methods, you can learn how to stub particular methods with a custom answer.

In the following recipe, we will see how to change the default answer to a custom or a predefined one.

Getting ready

It is more than probable that you will not ever need to create a custom answer for Mockito—there are plenty of them already bundled in Mockito and there is no need to reinvent the wheel. Why would you want to create a custom answer anyway? Let's take a look at a couple of possible answers to that question:

  • It is possible that for debugging purposes, you would like to log the arguments that were passed to the stubbed method

  • You could also want to perform some more complex logic on the...