I\'m interested to know about how to test Akka Actor functionality, by mocking some methods (substitute real object\'s/actor\'s method implementation by moc
Akka has a class AutoPilot
that is basically a general mock for actors, with the ability to respond to messages and assert that messages were sent.
http://doc.akka.io/docs/akka/snapshot/java/testing.html
Here's the java example for that page. You create a probe, set an auto-pilot that can respond to messages, and get an ActorRef
from it that you can substitute in for your real actor.
new JavaTestKit(system) {{
final JavaTestKit probe = new JavaTestKit(system);
// install auto-pilot
probe.setAutoPilot(new TestActor.AutoPilot() {
public AutoPilot run(ActorRef sender, Object msg) {
sender.tell(msg, ActorRef.noSender());
return noAutoPilot();
}
});
// first one is replied to directly ...
probe.getRef().tell("hello", getRef());
expectMsgEquals("hello");
// ... but then the auto-pilot switched itself off
probe.getRef().tell("world", getRef());
expectNoMsg();
}};