Chapter 5. Stubbing Behavior of Spies

In this chapter, we will cover the following recipes:

  • Stubbing methods that return values
  • Stubbing methods so that they throw exceptions
  • Stubbing methods so that they return custom answers
  • Stubbing void methods
  • Stubbing void methods so that they throw exceptions
  • Stubbing void methods so that they return custom answers
  • Stubbing final methods with PowerMock

Introduction

As presented in previous chapters, Mockito is all about creating mocks and stubbing their behavior. In comparison to the previous chapter, which focused on mocks, in this chapter we will take a look at partial mocks, also known as spies. Spies are mocks that by default call real implementations. Additionally, you can also perform verification on such ...

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.