Introduction
As explained in the previous chapters, Mockito is all about creating mocks and stubbing their behavior. It's worth taking another look at the differences between mocks and stubs in order to properly distinguish possible actions that can be taken on either of them. In his xUnit patterns (http://xunitpatterns.com/Test%20Double%20Patterns.html), Gerard Meszaros describes stubs and mocks as follows:
- Stub: This is an object that has predefined answers to method executions made during the test
- Mock: This is an object that has predefined answers to method executions made during the test and that has recorded expectations of these executions
Mockito does not distinguish this separation, so each test double, regardless of its purpose, is considered to be a mock. This chapter will focus on showing you numerous ways of the stubbing behavior of mocks in order to simulate real interactions. We'll cover stubbing methods that return values and those that are void. We'll simulate...