Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


#48 Using a matcher causes a failure in next expectation

EasyMock (40)
Gaetan PItteloud

I need to test a Service class that depends on the Factory (interface). The factory creates objects of type ExtendedSession (concrete class). When a session is created in the service, it calls the open method (which is defined on the superclass of ExtendedSession : Session, a concrete class), then the getValue method, (which is defined on the super-superclass of ExtendedSession : BaseSession, a concrete class). Both methods don't accept parameters, and return int.
In the test, I create a mock for Factory and a mock for ExtendedSession, then I expect a call to the factory that returns the mock session, then a call to session.open() that returns anyInt(), and a call to session.getValue() that returns 5. In the 2nd expectation, I get a mismatched matchers exception that states "0 matchers expected, 1 recorded". When I change the first expectation so that it returns a real value (say 3), the test passes.

You can see things in real within the attached zipped classes.
Thanks for your help