|
41 | 41 |
|
42 | 42 | package org.graalvm.junit.platform.config.jupiter; |
43 | 43 |
|
44 | | -import org.graalvm.junit.platform.config.core.NativeImageConfiguration; |
| 44 | +import org.graalvm.junit.platform.JUnitPlatformFeatureUtils; |
45 | 45 | import org.graalvm.junit.platform.config.core.PluginConfigProvider; |
46 | 46 | import org.graalvm.junit.platform.config.util.AnnotationUtils; |
| 47 | +import org.graalvm.junit.platform.config.util.Utils; |
47 | 48 | import org.junit.jupiter.api.DisplayNameGeneration; |
48 | 49 | import org.junit.jupiter.api.IndicativeSentencesGeneration; |
49 | 50 | import org.junit.jupiter.api.TestMethodOrder; |
|
61 | 62 | import java.util.ArrayList; |
62 | 63 | import java.util.List; |
63 | 64 |
|
64 | | -import static org.graalvm.junit.platform.JUnitPlatformFeature.debug; |
| 65 | +import static org.graalvm.junit.platform.JUnitPlatformFeatureUtils.debug; |
65 | 66 |
|
66 | 67 | public class JupiterConfigProvider extends PluginConfigProvider { |
67 | 68 |
|
68 | 69 | @Override |
69 | | - public void onLoad(NativeImageConfiguration config) { |
| 70 | + public void onLoad() { |
70 | 71 | /* Provide support for Timeout annotation */ |
71 | | - config.registerAllClassMembersForReflection( |
72 | | - "org.junit.jupiter.engine.extension.TimeoutExtension$ExecutorResource", |
73 | | - "org.junit.jupiter.engine.extension.TimeoutInvocationFactory$SingleThreadExecutorResource" |
74 | | - ); |
| 72 | + JUnitPlatformFeatureUtils.registerAllClassMembersForReflection(Utils.toClasses("org.junit.jupiter.engine.extension.TimeoutExtension$ExecutorResource", "org.junit.jupiter.engine.extension.TimeoutInvocationFactory$SingleThreadExecutorResource")); |
75 | 73 | } |
76 | 74 |
|
77 | 75 | @Override |
78 | | - public void onTestClassRegistered(Class<?> testClass, NativeImageConfiguration registry) { |
| 76 | + public void onTestClassRegistered(Class<?> testClass) { |
79 | 77 | /* Provide support for various annotations */ |
80 | 78 |
|
81 | 79 | /* Annotations from org.junit.jupiter.api */ |
82 | 80 | try { |
83 | | - AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, registry, TestMethodOrder.class, TestMethodOrder::value); |
84 | | - AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, registry, ExtendWith.class, ExtendWith::value); |
85 | | - AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, registry, DisplayNameGeneration.class, DisplayNameGeneration::value); |
86 | | - AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, registry, IndicativeSentencesGeneration.class, IndicativeSentencesGeneration::generator); |
87 | | - AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, registry, EnabledIf.class, JupiterConfigProvider::handleEnabledIf); |
88 | | - AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, registry, DisabledIf.class, JupiterConfigProvider::handleDisabledIf); |
| 81 | + AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, TestMethodOrder.class, TestMethodOrder::value); |
| 82 | + AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, ExtendWith.class, ExtendWith::value); |
| 83 | + AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, DisplayNameGeneration.class, DisplayNameGeneration::value); |
| 84 | + AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, IndicativeSentencesGeneration.class, IndicativeSentencesGeneration::generator); |
| 85 | + AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, EnabledIf.class, JupiterConfigProvider::handleEnabledIf); |
| 86 | + AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, DisabledIf.class, JupiterConfigProvider::handleDisabledIf); |
89 | 87 | } catch (NoClassDefFoundError e) { |
90 | 88 | debug("Cannot register annotations %s from 'org.junit.jupiter.api'. " + |
91 | | - "Please verify that you have dependency that includes 'org.junit.jupiter.api' if you want to use these annotations.", |
92 | | - List.of("TestMethodOrder", "ExtendWith", "DisplayNameGeneration", "IndicativeSentencesGeneration", "EnabledIf", "DisabledIf")); |
| 89 | + "Please verify that you have dependency that includes 'org.junit.jupiter.api' if you want to use these annotations.", |
| 90 | + List.of("TestMethodOrder", "ExtendWith", "DisplayNameGeneration", "IndicativeSentencesGeneration", "EnabledIf", "DisabledIf")); |
93 | 91 | } |
94 | 92 |
|
95 | 93 | /* Annotations from org.junit.jupiter.params */ |
96 | 94 | try { |
97 | | - AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, registry, ArgumentsSource.class, ArgumentsSource::value); |
98 | | - AnnotationUtils.forEachAnnotatedMethodParameter(testClass, ConvertWith.class, annotation -> registry.registerAllClassMembersForReflection(annotation.value())); |
99 | | - AnnotationUtils.forEachAnnotatedMethodParameter(testClass, AggregateWith.class, annotation -> registry.registerAllClassMembersForReflection(annotation.value())); |
100 | | - AnnotationUtils.forEachAnnotatedMethod(testClass, EnumSource.class, (m, annotation) -> handleEnumSource(m, annotation, registry)); |
101 | | - AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, registry, MethodSource.class, JupiterConfigProvider::handleMethodSource); |
| 95 | + AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, ArgumentsSource.class, ArgumentsSource::value); |
| 96 | + AnnotationUtils.forEachAnnotatedMethodParameter(testClass, ConvertWith.class, annotation -> JUnitPlatformFeatureUtils.registerAllClassMembersForReflection(annotation.value())); |
| 97 | + AnnotationUtils.forEachAnnotatedMethodParameter(testClass, AggregateWith.class, annotation -> JUnitPlatformFeatureUtils.registerAllClassMembersForReflection(annotation.value())); |
| 98 | + AnnotationUtils.forEachAnnotatedMethod(testClass, EnumSource.class, (m, annotation) -> handleEnumSource(m, annotation)); |
| 99 | + AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, MethodSource.class, JupiterConfigProvider::handleMethodSource); |
102 | 100 |
|
103 | 101 | // special case because the class might not be available because the annotation was introduced in JUnit 5.13 |
104 | 102 | try { |
105 | | - AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, registry, FieldSource.class, JupiterConfigProvider::handleFieldSource); |
| 103 | + AnnotationUtils.registerClassesFromAnnotationForReflection(testClass, FieldSource.class, JupiterConfigProvider::handleFieldSource); |
106 | 104 | } catch (NoClassDefFoundError e) { |
107 | 105 | debug("Cannot register @FieldSource annotation from org.junit.jupiter.params. " + |
108 | 106 | "Please verify that you have this dependency (with version greater than JUnit 5.13) if you want to use this annotation."); |
109 | 107 | } |
110 | 108 | } catch (NoClassDefFoundError e) { |
111 | 109 | debug("Cannot register annotations %s from 'org.junit.jupiter.params'. " + |
112 | | - "Please verify that you have dependency that includes 'org.junit.jupiter.params' if you want to use these annotations.", |
113 | | - List.of("ArgumentsSource", "ConvertWith", "AggregateWith", "EnumSource", "MethodSource", "FieldSource")); |
| 110 | + "Please verify that you have dependency that includes 'org.junit.jupiter.params' if you want to use these annotations.", |
| 111 | + List.of("ArgumentsSource", "ConvertWith", "AggregateWith", "EnumSource", "MethodSource", "FieldSource")); |
114 | 112 | } |
115 | 113 |
|
116 | 114 | } |
@@ -155,15 +153,15 @@ private static Class<?>[] handleMethodReference(String... methodNames) { |
155 | 153 | return classList.toArray(new Class<?>[0]); |
156 | 154 | } |
157 | 155 |
|
158 | | - public static void handleEnumSource(Method method, EnumSource source, NativeImageConfiguration registry) { |
159 | | - registry.registerAllClassMembersForReflection(source.value()); |
| 156 | + public static void handleEnumSource(Method method, EnumSource source) { |
| 157 | + JUnitPlatformFeatureUtils.registerAllClassMembersForReflection(source.value()); |
160 | 158 | if (method.getParameterCount() > 0) { |
161 | 159 | Class<?>[] parameterTypes = method.getParameterTypes(); |
162 | 160 | /* EnumSource annotated methods without an enum in the annotation value must have the enum as the first parameter. */ |
163 | 161 | Class<?> enumParameterType = parameterTypes[0]; |
164 | 162 | if (enumParameterType.isEnum()) { |
165 | 163 | debug("Registering method enum parameter for reflection. Method: %s Parameter: %s", method, parameterTypes[0]); |
166 | | - registry.registerAllClassMembersForReflection(enumParameterType); |
| 164 | + JUnitPlatformFeatureUtils.registerAllClassMembersForReflection(enumParameterType); |
167 | 165 | } else { |
168 | 166 | debug("First parameter of method not an enum - skipping. Method: %s", method); |
169 | 167 | } |
|
0 commit comments