#44 IExpectationSetters.andThenExecute

open
EasyMock (33)
5
2012-10-05
2011-05-28
Stepan Koltsov
No

Requesting

IExpectationSetters.andThenExecute(Runnable)

Use case:

===
interface MessageContext {
void reply(Object reply);
}

interface Actor {
void processMessage(Object message, MessageContext context);
}

Actor actor = expect(Actor.class);
final Capture<MessageContext> messageContext = new Capture();
actor.processMessage(eq("hello to you"), capture(messageContext));
expectLastCall().andThenExecute(new Runnable() {
void run() {
messageContext.getValue().reply("hello to you too");
}
});
===

Runnable must be called after easymock encounters a call to actor.processMessage().

Note, MessageContext is not a mock, it is real object created by system I'm testing, and I must reply using that MessageContext.

Discussion