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 d974b01 commit ba9525b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.jupiter.api.extension.InvocationInterceptor
import org.junit.jupiter.api.extension.ReflectiveInvocationContext
import tech.apter.junit.jupiter.robolectric.internal.JUnit5RobolectricTestRunnerHelper
import tech.apter.junit.jupiter.robolectric.internal.validation.TestClassValidator
import tech.apter.junit.jupiter.robolectric.internal.extensions.createLogger
import tech.apter.junit.jupiter.robolectric.internal.validation.TestClassValidator
import tech.apter.junit.jupiter.robolectric.internal.validation.TestMethodValidator
import java.lang.reflect.Method
import kotlin.jvm.optionals.getOrNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ internal class TestClassValidator(private val testClass: Class<*>) {
annotationsClasses.forEach { annotationClass ->
val annotation = testClass.getAnnotation(annotationClass)
if (annotation != null) {
error("${annotationClass.simpleName} annotation cannot be used on a nested test class: ${testClass.name}")
error(
"${annotationClass.simpleName} annotation cannot be used on a nested test class: ${testClass.name}"
)
}
}
}
Expand All @@ -52,16 +54,18 @@ internal class TestClassValidator(private val testClass: Class<*>) {
) {
fun Class<*>.isDeclaredNestedTestClasses() = declaredClasses.any { it.isNestedTest }
fun Class<*>.isConcurrent() =
(System.getProperty("junit.jupiter.execution.parallel.mode.classes.default") == "concurrent" &&
executionMode() != ExecutionMode.SAME_THREAD) ||
(
System.getProperty("junit.jupiter.execution.parallel.mode.classes.default") == "concurrent" &&
executionMode() != ExecutionMode.SAME_THREAD
) ||
executionMode() == ExecutionMode.CONCURRENT

if (testClass.declaringClass == null) {
if (testClass.isDeclaredNestedTestClasses() && testClass.isConcurrent()) {
error(
"${testClass.simpleName} must be annotated with @Execution(ExecutionMode.SAME_THREAD). " +
"Because it declared nested test classes. " +
"Or system property junit.jupiter.execution.parallel.mode.classes.default=same_thread must be set"
"Because it declared nested test classes. Or" +
" system property junit.jupiter.execution.parallel.mode.classes.default=same_thread must be set"
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import org.junit.jupiter.api.DynamicTest
import org.junit.jupiter.api.TestFactory
import org.junit.jupiter.api.assertDoesNotThrow
import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.api.parallel.Execution
import org.junit.jupiter.api.parallel.ExecutionMode
import kotlin.test.assertContains
import kotlin.test.assertEquals
import kotlin.test.assertIs
Expand Down

0 comments on commit ba9525b

Please sign in to comment.