This has been asked before - at Can Mockito verify parameters based on their values at the time of method call?
When you call a method that has been stubbed with Mockito, Mockito will store the arguments that are passed to it, so that you can use verify
later. That is, it stores object references, not the contents of the objects themselves. If you later change the contents of those objects, then your verify
call will compare its arguments to the updated objects - it doesn't make a deep copy of the original objects.
If you need to verify what the contents of the objects were, you'll need to EITHER
- store them yourself at the time of the method call; OR
- verify them at the time of the method call.
The right way to do either of these is with a Mockito Answer
. So, for the second option, you would create an Answer
that does the verification, and throws an AssertionFailedError
if the argument values are incorrect; instead of using verify
at the end of the test.