Chapter 7. Verifying Behavior with Object Matchers

In this chapter, we will cover the following recipes:

  • Using Hamcrest matchers for assertions
  • Creating custom Hamcrest matchers
  • Using Hamcrest matchers for stubbing and verification
  • Using AssertJ for assertions
  • Creating custom AssertJ assertions
  • Capturing and asserting the argument

Introduction

In this chapter, you will learn how to use both Hamcrest matchers (https://github.com/hamcrest/JavaHamcrest) and AssertJ assertions (http://joel-costigliola.github.io/assertj/assertj-core.html) in order to properly check the output of your system under test. Now, let's take a quick look at both of the libraries and check their pros and cons.

Hamcrest is a library that is incorporated inside one of the most frequently ...

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.