77import java .lang .annotation .RetentionPolicy ;
88import java .lang .reflect .Method ;
99
10- import static junit .framework .Assert .*;
11- import static org .junit .Assert .assertEquals ;
12-
13- @ SuppressWarnings ("deprecation" )
14- public class AnnotationsTest {
10+ import static org .junit .Assert .*;
1511
12+ public class AnnotationsTest
13+ {
1614 @ Retention (RetentionPolicy .RUNTIME )
1715 private static @interface Marker { }
1816
1917 @ Test @ Marker
20- public void addAsDefault () throws NoSuchMethodException {
18+ public void addAsDefault () throws Exception {
2119 Annotations annotations = new Annotations ();
2220 Method thisMethod = AnnotationsTest .class .getDeclaredMethod ("addAsDefault" );
2321
@@ -39,7 +37,7 @@ public void addAsDefault() throws NoSuchMethodException {
3937 }
4038
4139 @ Test
42- public void size () throws NoSuchMethodException {
40+ public void size () throws Exception {
4341 Annotations annotations = new Annotations ();
4442 Method thisMethod = AnnotationsTest .class .getDeclaredMethod ("addAsDefault" );
4543
@@ -57,7 +55,7 @@ public void size() throws NoSuchMethodException {
5755 }
5856
5957 @ Test
60- public void annotationsToSize () throws NoSuchMethodException {
58+ public void annotationsToSize () throws Exception {
6159 Annotations annotations = new Annotations ();
6260 Method thisMethod = AnnotationsTest .class .getDeclaredMethod ("addAsDefault" );
6361
@@ -67,23 +65,42 @@ public void annotationsToSize() throws NoSuchMethodException {
6765 annotations .addAsDefault (testAnnotation );
6866
6967 // order is unspecified as the internal representation is a HashMap; just assert the constituent parts are present
70- String asString = annotations .toString ();
68+ String asString = _normalize ( annotations .toString () );
7169 assertTrue (asString .contains ("{interface org.junit.Test=@org.junit.Test(" ));
7270 assertTrue (asString .contains ("timeout=0" ));
7371
7472 // 15-Nov-2016, tatu: Java 9 changes description slightly, need to modify
75- assertTrue (asString .contains ("expected=class org.junit.Test$None" ) // until Java 8
76- || asString .contains ("expected=org.junit.Test$None" ));
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+ }
7778
7879 Annotation markerAnnotation = thisMethod .getAnnotation (Marker .class );
7980 annotations .addAsDefault (markerAnnotation );
8081
81- asString = annotations .toString ();
82- assertTrue (asString .contains ("interface com.fasterxml.classmate.AnnotationsTest$Marker=@com.fasterxml.classmate.AnnotationsTest$Marker()" ));
82+ asString = _normalize (annotations .toString ());
83+
84+ String exp = "interface com.fasterxml.classmate.AnnotationsTest.Marker=@com.fasterxml.classmate.AnnotationsTest.Marker()" ;
85+ if (!asString .contains (exp )) {
86+ fail ("Expected: [" +exp +"]\n in [" +asString +"]" );
87+ }
8388 assertTrue (asString .contains ("interface org.junit.Test=@org.junit.Test" ));
8489 assertTrue (asString .contains ("timeout=0" ));
8590 // 15-Nov-2016, tatu: Java 9 changes description slightly, need to modify
86- assertTrue (asString .contains ("expected=class org.junit.Test$None" )
87- || asString .contains ("expected=org.junit.Test$None" ));
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+ }
96+ }
97+
98+ private static String _normalize (String str ) {
99+ // 05-Dec-2025, tatu: Java 21 changes from "org.junit.Test$None" to "org.junit.Test.None"
100+ String str2 ;
101+ while ((str2 = str .replace ('$' , '.' )) != str ) {
102+ str = str2 ;
103+ }
104+ return str ;
88105 }
89106}
0 commit comments