Easymock - 2 minute tutorial

How to define mock behaviour for any argument

The previous example shows how to stub a method for a hardcoded argument. However, Easymock api also allows us to mock for generalized arguments using methods anyInt(), anyObject() etc of class org.easymock.EasyMock.

Note that the method replay(..) must be called to mark the end of recording state and let the mock object know that the stubbed methods will now be called on it.