Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
warnyul committed May 2, 2024
1 parent 8aca672 commit 76f02c6
Showing 1 changed file with 2 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<*>)

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -131,19 +128,14 @@ internal class JUnit5RobolectricTestRunner(
}

private companion object {
private val beforeTestLocks = ConcurrentHashMap<String, ReentrantReadWriteLock>()
private val beforeTestLock = Any()
private val sdkSandboxParentClassLoaderCache = ConcurrentHashMap<String, ClassLoader>()

private fun defaultInjectorBuilder() =
defaultInjector().bind(SandboxBuilder::class.java, JUnit5RobolectricSandboxBuilder::class.java)
.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 {
Expand Down

0 comments on commit 76f02c6

Please sign in to comment.