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

Chapter 4. Stubbing Behavior of Mocks

In this chapter, we will cover the following recipes:

  • Using argument matchers for stubbing
  • Stubbing methods that return values
  • Stubbing methods so they throw exceptions
  • Stubbing methods so they return custom answers
  • Stubbing methods so they call real methods
  • Stubbing void methods
  • Stubbing void methods so they throw exceptions
  • Stubbing void methods so they return custom answers
  • Stubbing final methods with PowerMock
  • Stubbing static methods with PowerMock
  • Stubbing object instantiation with PowerMock

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

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