diff --git a/robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricTestRunner.kt b/robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricTestRunner.kt index c50dc33..141d2c4 100644 --- a/robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricTestRunner.kt +++ b/robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricTestRunner.kt @@ -16,9 +16,6 @@ import tech.apter.junit.jupiter.robolectric.internal.extensions.hasTheSameParame import tech.apter.junit.jupiter.robolectric.internal.extensions.outerMostDeclaringClass import java.lang.reflect.Method import java.util.concurrent.ConcurrentHashMap -import java.util.concurrent.locks.Lock -import java.util.concurrent.locks.ReentrantReadWriteLock -import kotlin.concurrent.withLock internal data class TestClassContainer(val testClass: Class<*>) @@ -74,7 +71,7 @@ internal class JUnit5RobolectricTestRunner( frameworkMethod: FrameworkMethod, bootstrappedMethod: Method, ) { - beforeTestLock(testClass.javaClass).withLock { + synchronized(beforeTestLock) { logger.trace { "runBeforeTest ${bootstrappedMethod.declaringClass.simpleName}::${bootstrappedMethod.name}" } super.beforeTest(sdkEnvironment, frameworkMethod, bootstrappedMethod) } @@ -131,7 +128,7 @@ internal class JUnit5RobolectricTestRunner( } private companion object { - private val beforeTestLocks = ConcurrentHashMap() + private val beforeTestLock = Any() private val sdkSandboxParentClassLoaderCache = ConcurrentHashMap() private fun defaultInjectorBuilder() = @@ -139,11 +136,6 @@ internal class JUnit5RobolectricTestRunner( .bind(MavenDependencyResolver::class.java, JUnit5MavenDependencyResolver::class.java) .bind(SandboxManager::class.java, JUnit5RobolectricSandboxManager::class.java) - private fun beforeTestLock(testClass: Class<*>): Lock = - beforeTestLocks.getOrPut(testClass.outerMostDeclaringClass().name) { - ReentrantReadWriteLock() - }.writeLock() - private fun createParentClassLoader(testClass: Class<*>) = sdkSandboxParentClassLoaderCache.getOrPut(testClass.outerMostDeclaringClass().name) { createLogger().trace {