When refactoring some old unit tests, I added a verify() call to see how many times a method was being expected and was surprised to see that the "expected" calls was greater than what was set using times(). For some reason the expect call on the next line is being added to my method.
Why is this happening?
Test Class
public class SandBoxTest {
@Test
public void shouldGetSand() {
Sand niceMock = EasyMock.createNiceMock(Sand.class);
EasyMock.expect(niceMock.sandMethod()).andReturn(1).times(2);
EasyMock.expect(Box.boxMethod()).andReturn(99).times(11);
EasyMock.replay(niceMock);
EasyMock.verify(niceMock);
}
}
Output When Run
java.lang.AssertionError:
Expectation failure on verify:
Sand.sandMethod(): expected: 13, actual: 0
Output That Was Expected
java.lang.AssertionError:
Expectation failure on verify:
Sand.sandMethod(): expected: 2, actual: 0
Details: EasyMock v3.1
Followup: Opened feature request with EasyMock. https://jira.codehaus.org/browse/EASYMOCK-128