Let's say I have a parent actor who creates Actor by himself.
public static class Parent extends UntypedActor {
private ActorRef child = context().actorOf(Props.create(Child.class));
@Override
public void onReceive(Object message) throws Exception {
// do some stuff
child.tell("some stuff", self());
}
}
public static class Child extends UntypedActor {
@Override
public void onReceive(Object message) throws Exception {
}
}
How can I mock this child Actor? Google didn't give me any reasonable results. I've been told by Akka's documentation that creating an actor is a good practice. But how can I follow this practice if I can't even test my actors?
I use probes as described in this answer to a similar question:
How to mock child Actors for testing an Akka system?
ActorSystem system = ActorSystem.create();
new JavaTestKit( system )
{{
final JavaTestKit probe = new JavaTestKit( system );
final Props props = Props.create( SupervisorActor.class );
final TestActorRef<SupervisorActor> supervisorActor =
TestActorRef.create( system, props, "Superman" );
supervisorActor.tell( callCommand, getTestActor() );
probe.expectMsgEquals(42);
assertEquals(getRef(), probe.getLastSender());
}};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With