Skip to content

Instantly share code, notes, and snippets.

@indrekots
Last active January 4, 2016 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save indrekots/8602775 to your computer and use it in GitHub Desktop.
Save indrekots/8602775 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