Easymock - 2 minute tutorial

How to define mock behaviour for sequential method calls

Easymock api allows us to define behaviour of mock objects for the case where same mocked methods are called multiple times. This is done by using methods andReturn(...) of class org.easymock.EasyMock multiple times.

Now, when the mocked method is called first time, the first behaviour (returning string "abc") manifests itself. On all subsequent calls, the second behaviour(returning string "pqr") manisfest itself.