Sign in Go Pro

Mockito

Argument Captors

This lesson is for PRO members.

Upgrade today to get access to all the PRO lessons.

Unlock this lesson

Previous

About

#### Argument Captor In this lesson, we'll explain how to verify the parameters which are passed to mock objects. We'll explain how Argument Captors work and how you can use them to ensure that not only is your mock method being called, but that it is being called with the correct parameter. #### Summary of Content - Showing an example where we need to not only verify that a mock method was called, but we also need interrogate the parameter passed to a mock method - Explanation of what an Argument Captor is - How to create an Argument Captor, using the `ArgumentCaptor.forClass()` method - How to retrieve the object that was _captured_ by the argument captor, using the `getValue()` method - Showing a test passing which successfully verifies the parameter passed to a mock object. ####Other Relevant Links: - [http://mockito.org/](http://mockito.org/) - [https://static.javadoc.io/org.mockito/mockito-core/2.2.9/org/mockito/ArgumentCaptor.html](https://static.javadoc.io/org.mockito/mockito-core/2.2.9/org/mockito/ArgumentCaptor.html)

Lessons in Mockito