11package com .fasterxml .classmate ;
22
3- import org .junit .Test ;
3+ import org .junit .jupiter . api . Test ;
44
55import java .lang .annotation .Annotation ;
66import java .lang .annotation .Retention ;
77import java .lang .annotation .RetentionPolicy ;
88import java .lang .reflect .Method ;
99
10- import static org .junit .Assert .*;
10+ import static org .junit .jupiter . api . Assertions .*;
1111
1212public class AnnotationsTest
1313{
1414 @ Retention (RetentionPolicy .RUNTIME )
1515 private static @interface Marker { }
1616
17- @ Test @ Marker
17+ // Annotation with a property, to verify `toString()` output
18+ @ Retention (RetentionPolicy .RUNTIME )
19+ private static @interface Configured {
20+ int timeout () default 0 ;
21+ }
22+
23+ @ Test @ Marker @ Configured
1824 public void addAsDefault () throws Exception {
1925 Annotations annotations = new Annotations ();
2026 Method thisMethod = AnnotationsTest .class .getDeclaredMethod ("addAsDefault" );
2127
22- assertNull (annotations .get (Test .class ));
28+ assertNull (annotations .get (Configured .class ));
2329 assertNull (annotations .get (Marker .class ));
2430
25- Annotation testAnnotation = thisMethod .getAnnotation (Test .class );
31+ Annotation testAnnotation = thisMethod .getAnnotation (Configured .class );
2632 annotations .addAsDefault (testAnnotation );
2733
2834 Annotation markerAnnotation = thisMethod .getAnnotation (Marker .class );
2935 annotations .addAsDefault (markerAnnotation );
3036
31- assertNotNull (annotations .get (Test .class ));
37+ assertNotNull (annotations .get (Configured .class ));
3238 assertNotNull (annotations .get (Marker .class ));
3339
3440 assertEquals (2 , annotations .size ());
@@ -43,7 +49,7 @@ public void size() throws Exception {
4349
4450 assertEquals (0 , annotations .size ());
4551
46- Annotation testAnnotation = thisMethod .getAnnotation (Test .class );
52+ Annotation testAnnotation = thisMethod .getAnnotation (Configured .class );
4753 annotations .addAsDefault (testAnnotation );
4854
4955 assertEquals (1 , annotations .size ());
@@ -61,20 +67,14 @@ public void annotationsToSize() throws Exception {
6167
6268 assertEquals ("[null]" , annotations .toString ());
6369
64- Annotation testAnnotation = thisMethod .getAnnotation (Test .class );
70+ Annotation testAnnotation = thisMethod .getAnnotation (Configured .class );
6571 annotations .addAsDefault (testAnnotation );
6672
6773 // order is unspecified as the internal representation is a HashMap; just assert the constituent parts are present
6874 String asString = _normalize (annotations .toString ());
69- assertTrue (asString .contains ("{interface org.junit.Test=@org.junit.Test(" ));
70- assertTrue (asString .contains ("timeout=0" ));
71-
72- // 15-Nov-2016, tatu: Java 9 changes description slightly, need to modify
73- // 05-Dec-2025, tatu: Java 21 adds further variation
74- if (!(asString .contains ("expected=class org.junit.Test.None" ) // until Java 8
75- || asString .contains ("expected=org.junit.Test.None" ))) {
76- fail ("No 'expected' in: " +asString );
77- }
75+ assertTrue (asString .contains ("{interface com.fasterxml.classmate.AnnotationsTest.Configured=@com.fasterxml.classmate.AnnotationsTest.Configured(" ),
76+ asString );
77+ assertTrue (asString .contains ("timeout=0" ), asString );
7878
7979 Annotation markerAnnotation = thisMethod .getAnnotation (Marker .class );
8080 annotations .addAsDefault (markerAnnotation );
@@ -85,18 +85,13 @@ public void annotationsToSize() throws Exception {
8585 if (!asString .contains (exp )) {
8686 fail ("Expected: [" +exp +"]\n in [" +asString +"]" );
8787 }
88- assertTrue (asString .contains ("interface org.junit.Test=@org.junit.Test" ));
89- assertTrue (asString .contains ("timeout=0" ));
90- // 15-Nov-2016, tatu: Java 9 changes description slightly, need to modify
91- // 05-Dec-2025, tatu: Java 21 adds further variation
92- if (!(asString .contains ("expected=class org.junit.Test.None" ) // until Java 8
93- || asString .contains ("expected=org.junit.Test.None" ))) {
94- fail ("No 'expected' in: " +asString );
95- }
88+ assertTrue (asString .contains ("interface com.fasterxml.classmate.AnnotationsTest.Configured=@com.fasterxml.classmate.AnnotationsTest.Configured(" ),
89+ asString );
90+ assertTrue (asString .contains ("timeout=0" ), asString );
9691 }
9792
9893 private static String _normalize (String str ) {
99- // 05-Dec-2025, tatu: Java 21 changes from "org.junit.Test$None" to "org.junit.Test.None"
94+ // Nested type names use '$' on some JDKs and '.' on others
10095 String str2 ;
10196 while ((str2 = str .replace ('$' , '.' )) != str ) {
10297 str = str2 ;
0 commit comments