Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
warnyul committed Apr 21, 2024
1 parent 38dc0db commit cd421c6
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class RobolectricExtension : InvocationInterceptor, BeforeAllCallback, BeforeEac
"beforeEach ${context.requiredTestClass.simpleName}::${context.requiredTestMethod.name}"
}
val testRunnerHelper = testRunnerHelper(context.requiredTestClass)
testRunnerHelper.createTestEnvironmentForMethod(context.requiredTestMethod)
testRunnerHelper.runOnMainThreadWithRobolectric(context.requiredTestMethod) {
testRunnerHelper.beforeEach(context.requiredTestMethod)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import java.util.concurrent.ConcurrentHashMap
internal class JUnit5RobolectricTestRunnerHelper(testClass: Class<*>) {
private inline val logger get() = createLogger()
private var _robolectricTestRunner: JUnit5RobolectricTestRunner? = null
private var _sdkEnvironment: Sandbox? = null
private var _frameworkMethod: FrameworkMethod? = null

init {
validateNestedTestClassCanNotOverrideRuntimeSdk(testClass)
Expand All @@ -30,10 +28,6 @@ internal class JUnit5RobolectricTestRunnerHelper(testClass: Class<*>) {

@VisibleForTesting
val robolectricTestRunner: JUnit5RobolectricTestRunner get() = requireNotNull(_robolectricTestRunner)
val sdkEnvironment: Sandbox get() = requireNotNull(_sdkEnvironment)

@VisibleForTesting
val frameworkMethod: FrameworkMethod get() = requireNotNull(_frameworkMethod)

fun sdkEnvironment(testMethod: Method?): Sandbox {
return if (testMethod == null) {
Expand Down Expand Up @@ -62,16 +56,6 @@ internal class JUnit5RobolectricTestRunnerHelper(testClass: Class<*>) {

private fun createTestEnvironmentForClass(testClass: Class<*>) {
_robolectricTestRunner = JUnit5RobolectricTestRunner(testClass)
// _sdkEnvironment = robolectricTestRunner.bootstrapSdkEnvironment()
// logger.trace { "$sdkEnvironment createTestEnvironmentForClass" }
}

fun createTestEnvironmentForMethod(testMethod: Method) {
// val frameworkMethod = robolectricTestRunner.frameworkMethod(testMethod)

// _sdkEnvironment = robolectricTestRunner.sdkEnvironment(frameworkMethod)
// _frameworkMethod = frameworkMethod
// logger.trace { "$sdkEnvironment createTestEnvironmentForMethod" }
}

fun beforeEach(testMethod: Method) {
Expand All @@ -98,8 +82,6 @@ internal class JUnit5RobolectricTestRunnerHelper(testClass: Class<*>) {

fun clearCachedRobolectricTestRunnerEnvironment() {
_robolectricTestRunner = null
_sdkEnvironment = null
_frameworkMethod = null
}

internal companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,13 @@ class JUnit5RobolectricRunnerHelperTest {
fun `Given the runnerHelper configured when call clear then the runnerHelper should be empty`() {
// Given
val testClass = TwoTestMethodsJunitJupiterTest::class.java
val testMethod2 = testClass.declaredMethods.first {
it.name == TwoTestMethodsJunitJupiterTest::testMethod2.name
}
val runnerHelper = subjectUnderTest(testClass) {
// And
createTestEnvironmentForMethod(testMethod2)

// When
clearCachedRobolectricTestRunnerEnvironment()
}

// Then
assertThrows<IllegalArgumentException> { runnerHelper.robolectricTestRunner }
assertThrows<IllegalArgumentException> { runnerHelper.sdkEnvironment }
assertThrows<IllegalArgumentException> { runnerHelper.frameworkMethod }
}

private fun subjectUnderTest(
Expand Down

0 comments on commit cd421c6

Please sign in to comment.