How do I test an actor that is created by dependency injection? In my application I can get an ActorRef by named injection:
public MyClass {
@Inject
@Named("ping")
ActorRef mPingRef;
}
How do I get this reference in my tests?
This is my actor:
public class PingActor extends UntypedActor {
@Inject
public PingActor(Configuration configuration) {
... // Use config
}
@Override
public void onReceive(Object message) throws Exception {
if (message instanceof Ping) {
getSender().tell(new Pong(), getSelf());
}
}
public static class Ping {}
public static class Pong {}
}
I have configured my application with my own module:
public class MyModule extends AbstractModule implements AkkaGuiceSupport {
private final Configuration mConfig;
public MyModule(Environment environment, Configuration configuration){
this.mConfig = configuration;
}
@Override
protected void configure() {
bindActor(PingActor.class, "ping");
}
}
The module is enabled in application.conf:
play.modules.enabled += "com.my.package.MyModule"