Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capture arguments to expected method calls multiple times (EasyMock)

I have the following line in my test:

Capture<MyType> myCapture = Capture.newInstance();
expect(myMockedObject.myMethod(capture(myCapture)).andReturn(...).times(2);

This expectation passes when the mocks are verified but myCapture.getValues().size() returns 1. I am expecting a capture for each method call. How can I capture the arguments to both method calls?

like image 420
Max Avatar asked Jul 03 '15 10:07

Max


1 Answers

There is a parameter, called CaptureType that determines what gets captured. By default, this parameter is set to CaptureType.LAST, which only captures the last invoked method parameter. To fix this, create the capture like so:

Capture<MyType> myCapture = Capture.newInstance(CaptureType.ALL);
like image 64
Max Avatar answered Oct 26 '22 02:10

Max