If I understand what you want to do correctly, you should be able to use andAnswer():
mockObject.someMethod(eq(param1), eq(param2));
expectLastCall().andAnswer(new IAnswer() {
public Object answer() {
//supply your mock implementation here...
SomeClass arg1 = (SomeClass) getCurrentArguments()[0];
AnotherClass arg2 = (AnotherClass) getCurrentArguments()[1];
arg1.doSomething(blah);
//return the value to be returned by the method (null for void)
return null;
}
});
The EasyMock User Guide explains:
Creating Return Values or Exceptions
Sometimes we would like our mock object to return a value or throw an exception that is created at the time of the actual call. Since EasyMock 2.2, the object returned by
expectLastCall()andexpect(T value)provides the methodandAnswer(IAnswer answer)which allows [you] to specify an implementation of the interfaceIAnswerthat is used to create the return value or exception.Inside an
IAnswercallback, the arguments passed to the mock call are available viaEasyMock.getCurrentArguments(). If you use these, refactorings like reordering parameters may break your tests. You have been warned.