Marcus Randevik
09/09/2024, 1:03 PM@Tag(TestCategory.DatabaseTest)
annotation class DatabaseTest {
companion object {
init {
sharedDependency = TestImplementationOfDependency()
}
}
}
The shared dependency is declared as follow in order to be switched out in tests:
var sharedDependency: SharedDependency? = null
val SHARED_DEPENDENCY: SharedDependency
get() {
if (sharedDependency == null) {
sharedDependency = ProductionImplementationOfDependency()
}
return sharedDependency ?: throw RuntimeException("SharedDependency set to null by another thread")
}
When running on java 11, the shared dependency is correctly set to the TestImplementation, this can clearly be seen by placing a breakpoint in the init block. However, when running on java 21 the init block of the tag is not executed. Does anyone have a clue as to why that could be?