Как протестировать актера, созданного путем внедрения зависимостей? В моем приложении я могу получить ActorRef с помощью именованной инъекции:
public MyClass {
@Inject
@Named("ping")
ActorRef mPingRef;
}
Как мне получить эту ссылку в моих тестах?
Это мой актер:
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 {}
}
Я настроил свое приложение с помощью собственного модуля:
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");
}
}
Модуль включен в application.conf:
play.modules.enabled += "com.my.package.MyModule"