Skip to content

Instantly share code, notes, and snippets.

@thiagomarinho
Forked from indrekots/argumentCaptor.java
Created October 20, 2015 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagomarinho/4c159859875312f46890 to your computer and use it in GitHub Desktop.
Save thiagomarinho/4c159859875312f46890 to your computer and use it in GitHub Desktop.
How to capture values with ArgumentCaptor
UserDao userDao = Mockito.mock(UserDao.class);
ArgumentCaptor<User> captor = ArgumentCaptor.forClass(User.class);
Mockito.verify(userDao).save(captor.capture());
//do some testing logic, eg. call save on a userService object,
//which internally uses userDao to save the user object
//get the user as it was passed to the save method in userDao
User user = captor.getValue()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment