main.tech.apter.junit.jupiter.robolectric.internal.plugins.JUnit5TextLayoutModeConfigurer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of robolectric-extension Show documentation
Show all versions of robolectric-extension Show documentation
This repository aims to bridge the gap between JUnit 5 and Robolectric,
enabling developers to leverage the benefits of both frameworks
for unit testing Android applications. While Robolectric currently lacks
a dedicated JUnit 5 extension, this project proposes a community-driven solution to
achieve seamless integration.
The newest version!
package tech.apter.junit.jupiter.robolectric.internal.plugins
import org.robolectric.annotation.TextLayoutMode
import org.robolectric.plugins.PackagePropertiesLoader
import org.robolectric.plugins.TextLayoutModeConfigurer
import tech.apter.junit.jupiter.robolectric.internal.extensions.isNonStaticInnerClass
import java.util.Properties
internal class JUnit5TextLayoutModeConfigurer(
systemProperties: Properties,
propertyFileLoader: PackagePropertiesLoader,
) : TextLayoutModeConfigurer(systemProperties, propertyFileLoader) {
override fun getConfigFor(testClass: Class<*>): TextLayoutMode.Mode? {
return if (testClass.isNonStaticInnerClass) {
getConfigMergedWithDeclaringClassConfig(testClass)
} else {
super.getConfigFor(testClass)
}
}
private fun getConfigMergedWithDeclaringClassConfig(testClass: Class<*>): TextLayoutMode.Mode? {
val config = super.getConfigFor(testClass)
return if (testClass.isNonStaticInnerClass) {
val parentConfig = getConfigMergedWithDeclaringClassConfig(testClass.declaringClass)
config?.let { c -> return parentConfig?.let { p -> merge(p, c) } ?: c } ?: parentConfig
} else {
config
}
}
}