In Mockito documentation and javadocs it says
It is recommended to use ArgumentCaptor with verification but not with stubbing.
but I don’t understand how ArgumentCaptor can be used for stubbing. Can someone explain the above statement and show how ArgumentCaptor can be used for stubbing or provide a link that shows how it can be done?
Assuming the following method to test:
Mockito documentation says that you should not use captor in this way:
Because you can just use matcher during stubbing:
But verification is a different story. If your test needs to ensure that this method was called with a specific argument, use
ArgumentCaptorand this is the case for which it is designed: