Question

I try to learn EasyMock 3.2 by refactoring tests using jMock. Excuse me if the answer is obvious, but currently I cannot find it. I know there is a 'strict' mock which detects if the order of expected calls is wrong. But I was surprised that I don't get an error if some expectations are left. Example:

// This test passes as expected

@Test
public void connectShouldPass() {
    expect(sessionMock.setTimeout(10000)).andReturn(true);
    replay(sessionMock);
    sessionMock.setTimeout(10000);
}

// Here I would expect an fail but it passes too

@Test
public void connectShouldPass() {
    expect(sessionMock.setTimeout(10000)).andReturn(true);
    expect(sessionMock.setTimeout(10000)).andReturn(true);
    replay(sessionMock);
    sessionMock.setTimeout(10000);
}

Is it possible to check (maybe in the @After method) if more expectations were defined than called? Thanx, Andi

Was it helpful?

Solution

[OP found their own answer. Providing answer as an answer, rather than a comment]

EasyMock.verify(mock) does the job.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top