This post suggests both- that there is a difference (see comment by user SnoopyMe) and that the two can be used interchangeably. The EasyMock documentation makes no mention of any difference.
Is there any difference, either practically or semantically? If so, when is it more appropriate to use one over the other?
EDIT:
The following test suggests that there is a difference, at least when used with a strict mock:
@Test
public void testTestMe() {
Bar bar = createStrictMock(Bar.class);
expect(bar.doBar()).andReturn(1).anyTimes();
expect(bar.doOtherBar()).andReturn(2).once();
replay(bar);
Foo foo = new Foo(bar);
foo.testMe();
verify(bar);
}
@Test
public void testTestMeAgain() {
Bar bar = createStrictMock(Bar.class);
expect(bar.doBar()).andStubReturn(1);
expect(bar.doOtherBar()).andReturn(2).once();
replay(bar);
Foo foo = new Foo(bar);
foo.testMe();
verify(bar);
}
public class Foo {
private final Bar _bar;
public Foo(Bar bar) {
_bar = bar;
}
public void testMe() {
_bar.doBar();
_bar.doOtherBar();
_bar.doBar();
}
}
andReturn(...).anyTimes() still verifies order, which is enforced by the strict mock on verification. andStubReturn(...), however, does not.
However, it's still not clear to me if this is the only difference, or what the semantic difference is. For example, is anyTimes() the same as stubReturn() for a regular (not strict) mock?