Specifying the number of times to return object in a chained AndReturn expression with multiple return objects

702 Views Asked by At

I have a mock, for which I expect object1 for 1st call and object2 for next 2 calls. Is this expression correct?

EasyMock.expect(result.get(0)).andReturn(object1).andReturn(object2).times(2);

or should I use

EasyMock.expect(result.get(0)).andReturn(object1).andReturn(object2).andReturn(object2);

Specifically, does adding times at the end make the entire group of expectations be expected twice, or only the last expectation in the chain?

1

There are 1 best solutions below

0
On BEST ANSWER

It is possible to chain multiple expectations and the expected number of calls.

So the first method indeed works. I have tested it as well. EasyMock.expect(result.get(0)).andReturn(object1).andReturn(object2).times(2);