I am using TestKit to test some of my classes for a Scala project I am working on involving Akka Actors, and I'm running into this issue:
One or more requested classes are not Suites: poc.PocConstituentsWatcher
The class in question looks like this:
class PocConstituentsWatcher(_system: ActorSystem) extends TestKit(_system) with ImplicitSender with WordSpecLike with Matchers with BeforeAndAfter with BeforeAndAfterAll {
I didn't used to have this issue, because I had
def this() = this(ActorSystem)
but now I define my own ActorSystem via injection, so I have val actorSystem = injector.instance[ActorSystem]
instead, and when I do
def this() = this(actorSystem)
I get an error saying it can't find actorSystem. I think it's because the constructor signature is incorrect? Thanks for your help.
EDIT:
Showed how to inject my actor system.
val injector = Guice.createInjector(new AkkaModule)
val actorSystem = injector.instance[ActorSystem]
In AkkaModule
object AkkaModule {
class ActorSystemProvider @Inject() (val config: Config, val injector: Injector) extends Provider[ActorSystem] {
override def get() = {
val system = ActorSystem("poc-actor-system", config)
GuiceAkkaExtension(system).initialize(injector)
system
}
}
}
class AkkaModule extends AbstractModule with ScalaModule {
override def configure() {
bind[ActorSystem].toProvider[ActorSystemProvider].asEagerSingleton()
}
}
def this() = this(ActorSystem)
. Off the cuff I can't think of a way of getting around this. - Mario Camou