diff --git a/kotest-extensions-android/src/main/kotlin/br/com/colman/kotest/android/extensions/robolectric/ContainedRobolectricRunner.kt b/kotest-extensions-android/src/main/kotlin/br/com/colman/kotest/android/extensions/robolectric/ContainedRobolectricRunner.kt index 6d60bd1..56329c4 100644 --- a/kotest-extensions-android/src/main/kotlin/br/com/colman/kotest/android/extensions/robolectric/ContainedRobolectricRunner.kt +++ b/kotest-extensions-android/src/main/kotlin/br/com/colman/kotest/android/extensions/robolectric/ContainedRobolectricRunner.kt @@ -6,18 +6,15 @@ import org.junit.runners.model.FrameworkMethod import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config import org.robolectric.internal.bytecode.InstrumentationConfiguration -import org.robolectric.pluginapi.config.ConfigurationStrategy import org.robolectric.pluginapi.config.Configurer import org.robolectric.plugins.HierarchicalConfigurationStrategy +import org.robolectric.util.inject.Injector import java.lang.reflect.Method @RunWith(Enclosed::class) internal class ContainedRobolectricRunner( - private val config: Config -) : RobolectricTestRunner(PlaceholderTest::class.java, injector) { - init { - injectKotestConfig() - } + config: Config +) : RobolectricTestRunner(PlaceholderTest::class.java, kotestInjector(config)) { private val placeHolderMethod: FrameworkMethod = children[0] val sdkEnvironment = getSandbox(placeHolderMethod).also { @@ -43,16 +40,6 @@ internal class ContainedRobolectricRunner( .build() } - private fun injectKotestConfig() { - val configurationStrategyField = - RobolectricTestRunner::class.java - .getField(ConfigurationStrategy::class.java) - .apply { isAccessible = true } - val configurers = injector.getInstance(arrayOf>()::class.java) - val newConfigurationStrategy = KotestHierarchicalConfigurationStrategy(config, configurers) - configurationStrategyField.set(this, newConfigurationStrategy) - } - class PlaceholderTest { @org.junit.Test fun testPlaceholder() { @@ -76,6 +63,10 @@ internal class ContainedRobolectricRunner( } companion object { - private val injector = defaultInjector().build() + private fun kotestInjector(config: Config): Injector { + val defaultInjector = defaultInjector().bind(Config::class.java, config).build() + return Injector.Builder(defaultInjector, ContainedRobolectricRunner::class.java.classLoader) + .build() + } } } diff --git a/kotest-extensions-android/src/main/resources/META-INF/services/org.robolectric.pluginapi.config.ConfigurationStrategy b/kotest-extensions-android/src/main/resources/META-INF/services/org.robolectric.pluginapi.config.ConfigurationStrategy new file mode 100644 index 0000000..1070ee0 --- /dev/null +++ b/kotest-extensions-android/src/main/resources/META-INF/services/org.robolectric.pluginapi.config.ConfigurationStrategy @@ -0,0 +1 @@ +br.com.colman.kotest.android.extensions.robolectric.ContainedRobolectricRunner$KotestHierarchicalConfigurationStrategy \ No newline at end of file