I think I may have run into a possible bug with using captures() to capture a parameter passed to a mocked method.
I've attached a (very simplified) test case to prove the behavior.
Please note that this is just a simplified test case - I know that I could specify the exact value of the arguments I expect passed to my mock, but in my real code the arguments are complex objects with a number of fields, and in the unit test (of the class using the mocked component), I want to capture the object so I can assert against just a few of those fields without re-creating the entire object in my test case.
Can someone please confirm if this is indeed a bug or if I am simply using this method wrong?
Thanks
Matt Brown
octavius@gmail.com
test case
It is indeed a bug. The capture is done even if it was already done. The current workaround is to implement your own capture object and override setValue to do this:
@Override
public void setValue(T value) {
if(!hasCaptured()) {
super.setValue(value);
}
}
Thanks Henri - that workaround seems to do the trick.