Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does "EasyMock.expectLastCall();" do anything without a further call to resulting IExpectationSetters?

Tags:

void

easymock

Consider this code snippet:-

Whatever mock = EasyMock.createMock( Whatever.class );
mock.doSomething();
EasyMock.expectLastCall();   // <- Does this do anything?
EasyMock.replay( whatever );

Does expectLastCall() here actually do anything? Adding or removing this line from my test appears to make no difference.

Obviously it is useful if you add .andThrow or .atLeastOnce(), etc. to the call. That is not what I'm asking about.

like image 499
WW. Avatar asked May 22 '12 05:05

WW.


1 Answers

No, you only usually use expectLastCall() when you need the result to specify behaviour. That's its purpose.

Of course, it does no harm to call it if you find it makes your test more readable. For example, I might do that for consistency - if I've had to call it twice in order to specify more behaviour, I might include it a third time even if I didn't need to. I'd probably add the default behaviour explicitly though, just for additional consistency.

like image 151
Jon Skeet Avatar answered Oct 12 '22 01:10

Jon Skeet