Argument capture - by value or by reference?

11 views
Skip to first unread message

Fr Jeremy Krieg (Home)

unread,
Jul 23, 2021, 3:57:49 AMJul 23
to mockito
Dear Mockito lovers,

I pray that you are all well.

I had a quick question: the model in Mockito clearly is that you capture the arguments, and then verify them.

I was using Mockito in a dynamic environment, and the question occurred to me: when Mockito captures the argument, does it store a reference to the argument, or does it somehow make a copy?

This is relevant because in a dynamic environment, the argument obviously might have changed between the time the invocation was captured and the time when you are attempting to run the matcher against it during verification. I'm interested in what the object looked like at the time the invocation was made, not later when I'm running the verification. 

I know that this use case may be a little outside of the anticipated use cases of Mockito, but I thought I'd put the question to see if anyone had come across this issue before and if there was a standard way around it.

Blessings,
Fr Jeremy Krieg

Virus-free. www.avast.com

James Hurley

unread,
Jul 23, 2021, 7:08:23 PMJul 23
to mockito
Mockito captures by reference.  I had a related problem several months ago where the argument captures I was performing were changing due to object pooling and this made it impossible to validate them (at least using the stock Mockito classes).

Reply all
Reply to author
Forward
0 new messages