@@ -77,22 +77,35 @@ public void onLoad(NativeImageConfiguration config) {
7777 @ Override
7878 public void onTestClassRegistered (Class <?> testClass , NativeImageConfiguration registry ) {
7979 /* Provide support for various annotations */
80- AnnotationUtils .registerClassesFromAnnotationForReflection (testClass , registry , TestMethodOrder .class , TestMethodOrder ::value );
81- AnnotationUtils .registerClassesFromAnnotationForReflection (testClass , registry , ArgumentsSource .class , ArgumentsSource ::value );
82- AnnotationUtils .registerClassesFromAnnotationForReflection (testClass , registry , ExtendWith .class , ExtendWith ::value );
83- AnnotationUtils .registerClassesFromAnnotationForReflection (testClass , registry , DisplayNameGeneration .class , DisplayNameGeneration ::value );
84- AnnotationUtils .registerClassesFromAnnotationForReflection (testClass , registry , IndicativeSentencesGeneration .class , IndicativeSentencesGeneration ::generator );
85- AnnotationUtils .forEachAnnotatedMethodParameter (testClass , ConvertWith .class , annotation -> registry .registerAllClassMembersForReflection (annotation .value ()));
86- AnnotationUtils .forEachAnnotatedMethodParameter (testClass , AggregateWith .class , annotation -> registry .registerAllClassMembersForReflection (annotation .value ()));
87- AnnotationUtils .forEachAnnotatedMethod (testClass , EnumSource .class , (m , annotation ) -> handleEnumSource (m , annotation , registry ));
88- AnnotationUtils .registerClassesFromAnnotationForReflection (testClass , registry , MethodSource .class , JupiterConfigProvider ::handleMethodSource );
89- AnnotationUtils .registerClassesFromAnnotationForReflection (testClass , registry , EnabledIf .class , JupiterConfigProvider ::handleEnabledIf );
90- AnnotationUtils .registerClassesFromAnnotationForReflection (testClass , registry , DisabledIf .class , JupiterConfigProvider ::handleDisabledIf );
9180
81+ /* Annotations from org.junit.jupiter.api */
9282 try {
93- AnnotationUtils .registerClassesFromAnnotationForReflection (testClass , registry , FieldSource .class , JupiterConfigProvider ::handleFieldSource );
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 );
9489 } catch (NoClassDefFoundError e ) {
95- // if users use JUnit version older than 5.11, FieldSource class won't be available
90+ AnnotationUtils .printMissingAnnotationsWarning ("org.junit.jupiter.api" , List .of ("TestMethodOrder" , "ExtendWith" , "DisplayNameGeneration" , "IndicativeSentencesGeneration" , "EnabledIf" , "DisabledIf" ));
91+ }
92+
93+ /* Annotations from org.junit.jupiter.params */
94+ try {
95+ AnnotationUtils .registerClassesFromAnnotationForReflection (testClass , registry , ArgumentsSource .class , ArgumentsSource ::value );
96+ AnnotationUtils .forEachAnnotatedMethodParameter (testClass , ConvertWith .class , annotation -> registry .registerAllClassMembersForReflection (annotation .value ()));
97+ AnnotationUtils .forEachAnnotatedMethodParameter (testClass , AggregateWith .class , annotation -> registry .registerAllClassMembersForReflection (annotation .value ()));
98+ AnnotationUtils .forEachAnnotatedMethod (testClass , EnumSource .class , (m , annotation ) -> handleEnumSource (m , annotation , registry ));
99+ AnnotationUtils .registerClassesFromAnnotationForReflection (testClass , registry , MethodSource .class , JupiterConfigProvider ::handleMethodSource );
100+
101+ // special case because the class might not be available because the annotation was introduced in JUnit 5.13
102+ try {
103+ AnnotationUtils .registerClassesFromAnnotationForReflection (testClass , registry , FieldSource .class , JupiterConfigProvider ::handleFieldSource );
104+ } catch (NoClassDefFoundError e ) {
105+ System .out .println ("[junit-platform-native] Cannot register @FieldSource annotation from org.junit.jupiter.params. Please verify that you have this dependency (with version greater than JUnit 5.13) if you want to use this annotation." );
106+ }
107+ } catch (NoClassDefFoundError e ) {
108+ AnnotationUtils .printMissingAnnotationsWarning ("org.junit.jupiter.params" , List .of ("ArgumentsSource" , "ConvertWith" , "AggregateWith" , "EnumSource" , "MethodSource" , "FieldSource" ));
96109 }
97110
98111 }
0 commit comments