Skip to content

Commit b841baa

Browse files
committed
Provide support for earlier JUnit versions without JUnit duplicates on claspath
1 parent 829494f commit b841baa

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

common/junit-platform-native/src/main/java/org/graalvm/junit/platform/JUnitPlatformFeature.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,13 @@ private static void initializeClassesForJDK21OrEarlier() {
264264
try (InputStream is = JUnitPlatformFeature.class.getResourceAsStream("/initialize-at-buildtime")) {
265265
if (is != null) {
266266
try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
267-
br.lines().forEach(RuntimeClassInitialization::initializeAtBuildTime);
267+
br.lines().forEach(cls -> {
268+
try {
269+
RuntimeClassInitialization.initializeAtBuildTime(cls);
270+
} catch (NoClassDefFoundError e) {
271+
// if users use older JUnit versions some classes might not be available
272+
}
273+
});
268274
}
269275
}
270276
} catch (IOException e) {

common/junit-platform-native/src/main/java/org/graalvm/junit/platform/config/jupiter/JupiterConfigProvider.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
import org.junit.jupiter.params.converter.ConvertWith;
5555
import org.junit.jupiter.params.provider.ArgumentsSource;
5656
import org.junit.jupiter.params.provider.EnumSource;
57-
import org.junit.jupiter.params.provider.MethodSource;
5857
import org.junit.jupiter.params.provider.FieldSource;
58+
import org.junit.jupiter.params.provider.MethodSource;
5959

6060
import java.lang.reflect.Method;
6161
import java.util.ArrayList;
@@ -86,9 +86,15 @@ public void onTestClassRegistered(Class<?> testClass, NativeImageConfiguration r
8686
AnnotationUtils.forEachAnnotatedMethodParameter(testClass, AggregateWith.class, annotation -> registry.registerAllClassMembersForReflection(annotation.value()));
8787
AnnotationUtils.forEachAnnotatedMethod(testClass, EnumSource.class, (m, annotation) -> handleEnumSource(m, annotation, registry));
8888
AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, registry, MethodSource.class, JupiterConfigProvider::handleMethodSource);
89-
AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, registry, FieldSource.class, JupiterConfigProvider::handleFieldSource);
9089
AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, registry, EnabledIf.class, JupiterConfigProvider::handleEnabledIf);
9190
AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, registry, DisabledIf.class, JupiterConfigProvider::handleDisabledIf);
91+
92+
try {
93+
AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, registry, FieldSource.class, JupiterConfigProvider::handleFieldSource);
94+
} catch (NoClassDefFoundError e) {
95+
// if users use JUnit version older than 5.11, FieldSource class won't be available
96+
}
97+
9298
}
9399

94100
private static Class<?>[] handleMethodSource(MethodSource annotation) {

common/junit-platform-native/src/main/resources/initialize-at-buildtime

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ org.junit.jupiter.engine.discovery.MethodSelectorResolver$MethodType$3
4646
org.junit.jupiter.engine.discovery.predicates.IsTestClassWithTests
4747
org.junit.jupiter.engine.discovery.predicates.IsTestFactoryMethod
4848
org.junit.jupiter.engine.execution.ConditionEvaluator
49+
org.junit.jupiter.engine.execution.ExecutableInvoker
4950
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker
5051
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall
5152
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall$VoidMethodInterceptorCall
@@ -78,6 +79,7 @@ org.junit.platform.launcher.core.DiscoveryIssueNotifier
7879
org.junit.platform.launcher.core.EngineDiscoveryOrchestrator
7980
org.junit.platform.launcher.core.EngineExecutionOrchestrator
8081
org.junit.platform.launcher.core.EngineFilterer
82+
org.junit.platform.launcher.core.EngineIdValidator
8183
org.junit.platform.launcher.core.HierarchicalOutputDirectoryProvider
8284
org.junit.platform.launcher.core.InternalTestPlan
8385
org.junit.platform.launcher.core.LauncherConfig
@@ -90,6 +92,8 @@ org.junit.platform.launcher.core.LauncherDiscoveryResult
9092
org.junit.platform.launcher.core.LauncherDiscoveryResult$EngineResultInfo
9193
org.junit.platform.launcher.core.LauncherListenerRegistry
9294
org.junit.platform.launcher.core.ListenerRegistry
95+
org.junit.platform.launcher.core.ServiceLoaderRegistry
96+
org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry
9397
org.junit.platform.launcher.core.SessionPerRequestLauncher
9498
org.junit.platform.launcher.EngineDiscoveryResult
9599
org.junit.platform.launcher.LauncherSessionListener$1

0 commit comments

Comments
 (0)