Skip to content

Commit 3afc885

Browse files
committed
Fix one JDK 21 test failure
1 parent 9e754eb commit 3afc885

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

src/test/java/com/fasterxml/classmate/AnnotationsTest.java

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
import java.lang.annotation.RetentionPolicy;
88
import 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,43 @@ 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+"]\nin ["+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") // Java 9 - 17
94+
|| asString.contains("expected=org.junit.Test.None"))) {
95+
fail("No 'expected' in: "+asString);
96+
}
97+
}
98+
99+
private static String _normalize(String str) {
100+
// 05-Dec-2025, tatu: Java 21 changes from "org.junit.Test$None" to "org.junit.Test.None"
101+
String str2;
102+
while ((str2 = str.replace('$', '.')) != str) {
103+
str = str2;
104+
}
105+
return str;
88106
}
89107
}

0 commit comments

Comments
 (0)