Given the trait (simplified)
trait A {
val eventStream: EventStream
val credentialsStorage = // something here
val userStorage = // something here
val crypto = // something here
...
lazy val authSvc = new CoreAuthentication(credentialsStorage, new AuthenticationProviderResolver, userStorage, eventStream, crypto)
}
class T extends A with TraitProvidingEventStream with FlatSpec with [lot of another traits here] {
val eventStream = systemFromTraitProvidingEventStream.eventStream
"This" should "work" in {
println(authSvc) // this is "magic"
val user = authSvc.doSomethingWithUser(...);
}
}
if I remove line marked as //this is "magic", then I will get NullPointerException on the next line, so authSvc is null.
What may be wrong there?
I wasn't be able to create clean small test case for that, usually this works well
authSvc
throws a NPE and not the methoddoSomethingWithUser
or its parameters? – MasterDelayedInit
trait being mixed into yourT
class. You should try making the example truly minimal to see exactly where the bug is. – PhilemoltoString()
method ofCoreAuthentication
class? It gets called byprintln
. Maybe it does something so that NPE doesn't occur? – Mapp