Question

I am not sure what i do is correct or not. I want assert times of void method call. My code is below. processor.processInitialDump will invoke service.applyInitialDump. My question is event I give times as 100, Still can pass the test. I want assert the call times. What I can do for this issue?

        Service service = EasyMock.createMock(Service.class);
    service.applyInitialDump(entities);
    EasyMock.expectLastCall().times(100);

    processor.processInitialDump(entities)

BTW: If I the expect is less than call time. expectLastCall work correctly. exception will be throw.

    Service service = EasyMock.createMock(Service.class);
    service.applyInitialDump(entities);
    EasyMock.expectLastCall().times(1);

    processor.processInitialDump(entities)
    processor.processInitialDump(entities)
Was it helpful?

Solution

If I understand correctly, you want your test to fail when you expect the call 100 times, but it only happens once.

From the code you've posted, it looks like you're not calling EasyMock.verify(). This is what makes EasyMock check all the expectations you have set up against what actually happened.

Service service = EasyMock.createMock(Service.class);
service.applyInitialDump(entities);
EasyMock.expectLastCall().times(100);

processor.processInitialDump(entities)
EasyMock.verify(service);

This previously worked because the call had been expected at least once, so the code ran fine. With the verification added, an assertion error will be thrown warning that expected calls didn't happen.

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