diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4f2fcc7..0c36f2a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,8 +23,7 @@ jobs: strategy: fail-fast: false matrix: - # 26-Sep-2025, tatu: some test failures on 21 cannot yet enable - java_version: ['8', '11', '17'] + java_version: ['8', '17', '21', '25'] env: JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1" steps: diff --git a/src/test/java/com/fasterxml/classmate/AnnotationsTest.java b/src/test/java/com/fasterxml/classmate/AnnotationsTest.java index 096bed3..6b0a49e 100644 --- a/src/test/java/com/fasterxml/classmate/AnnotationsTest.java +++ b/src/test/java/com/fasterxml/classmate/AnnotationsTest.java @@ -7,17 +7,15 @@ import java.lang.annotation.RetentionPolicy; import java.lang.reflect.Method; -import static junit.framework.Assert.*; -import static org.junit.Assert.assertEquals; - -@SuppressWarnings("deprecation") -public class AnnotationsTest { +import static org.junit.Assert.*; +public class AnnotationsTest +{ @Retention(RetentionPolicy.RUNTIME) private static @interface Marker { } @Test @Marker - public void addAsDefault() throws NoSuchMethodException { + public void addAsDefault() throws Exception { Annotations annotations = new Annotations(); Method thisMethod = AnnotationsTest.class.getDeclaredMethod("addAsDefault"); @@ -39,7 +37,7 @@ public void addAsDefault() throws NoSuchMethodException { } @Test - public void size() throws NoSuchMethodException { + public void size() throws Exception { Annotations annotations = new Annotations(); Method thisMethod = AnnotationsTest.class.getDeclaredMethod("addAsDefault"); @@ -57,7 +55,7 @@ public void size() throws NoSuchMethodException { } @Test - public void annotationsToSize() throws NoSuchMethodException { + public void annotationsToSize() throws Exception { Annotations annotations = new Annotations(); Method thisMethod = AnnotationsTest.class.getDeclaredMethod("addAsDefault"); @@ -67,23 +65,42 @@ public void annotationsToSize() throws NoSuchMethodException { annotations.addAsDefault(testAnnotation); // order is unspecified as the internal representation is a HashMap; just assert the constituent parts are present - String asString = annotations.toString(); + String asString = _normalize(annotations.toString()); assertTrue(asString.contains("{interface org.junit.Test=@org.junit.Test(")); assertTrue(asString.contains("timeout=0")); // 15-Nov-2016, tatu: Java 9 changes description slightly, need to modify - assertTrue(asString.contains("expected=class org.junit.Test$None") // until Java 8 - || asString.contains("expected=org.junit.Test$None")); + // 05-Dec-2025, tatu: Java 21 adds further variation + if (!(asString.contains("expected=class org.junit.Test.None") // until Java 8 + || asString.contains("expected=org.junit.Test.None"))) { + fail("No 'expected' in: "+asString); + } Annotation markerAnnotation = thisMethod.getAnnotation(Marker.class); annotations.addAsDefault(markerAnnotation); - asString = annotations.toString(); - assertTrue(asString.contains("interface com.fasterxml.classmate.AnnotationsTest$Marker=@com.fasterxml.classmate.AnnotationsTest$Marker()")); + asString = _normalize(annotations.toString()); + + String exp = "interface com.fasterxml.classmate.AnnotationsTest.Marker=@com.fasterxml.classmate.AnnotationsTest.Marker()"; + if (!asString.contains(exp)) { + fail("Expected: ["+exp+"]\nin ["+asString+"]"); + } assertTrue(asString.contains("interface org.junit.Test=@org.junit.Test")); assertTrue(asString.contains("timeout=0")); // 15-Nov-2016, tatu: Java 9 changes description slightly, need to modify - assertTrue(asString.contains("expected=class org.junit.Test$None") - || asString.contains("expected=org.junit.Test$None")); + // 05-Dec-2025, tatu: Java 21 adds further variation + if (!(asString.contains("expected=class org.junit.Test.None") // until Java 8 + || asString.contains("expected=org.junit.Test.None"))) { + fail("No 'expected' in: "+asString); + } + } + + private static String _normalize(String str) { + // 05-Dec-2025, tatu: Java 21 changes from "org.junit.Test$None" to "org.junit.Test.None" + String str2; + while ((str2 = str.replace('$', '.')) != str) { + str = str2; + } + return str; } } diff --git a/src/test/java/com/fasterxml/classmate/TestMemberResolver.java b/src/test/java/com/fasterxml/classmate/MemberResolverTest.java similarity index 93% rename from src/test/java/com/fasterxml/classmate/TestMemberResolver.java rename to src/test/java/com/fasterxml/classmate/MemberResolverTest.java index 50c6442..bd05ae6 100644 --- a/src/test/java/com/fasterxml/classmate/TestMemberResolver.java +++ b/src/test/java/com/fasterxml/classmate/MemberResolverTest.java @@ -8,7 +8,7 @@ import com.fasterxml.classmate.types.ResolvedObjectType; import com.fasterxml.classmate.util.ClassKey; -public class TestMemberResolver extends BaseTest +public class MemberResolverTest extends BaseTest { /* /********************************************************************** @@ -214,7 +214,11 @@ public void testIncludeObject() mr.setIncludeLangObject(true); simpleResolvedTypeWithMembers = mr.resolve(simpleResolvedType, null, null); - assertEquals(12, simpleResolvedTypeWithMembers.getMemberMethods().length); + // With JDK < 21, 12 member methods, 21+ 13 + int methodCount = simpleResolvedTypeWithMembers.getMemberMethods().length; + if (methodCount < 12 || methodCount > 13) { + fail("Expected [12, 13] methods, got: "+methodCount); + } assertEquals(1, simpleResolvedTypeWithMembers.getMemberFields().length); } @@ -225,7 +229,12 @@ public void testFilters() mr.setIncludeLangObject(true); ResolvedTypeWithMembers simpleResolvedTypeWithMembers = mr.resolve(simpleResolvedType, null, null); - assertEquals(12, simpleResolvedTypeWithMembers.getMemberMethods().length); + // With JDK < 21, 12 member methods, 21+ 13 + int methodCount = simpleResolvedTypeWithMembers.getMemberMethods().length; + if (methodCount < 12 || methodCount > 13) { + fail("Expected [12, 13] methods, got: "+methodCount); + } + assertEquals(1, simpleResolvedTypeWithMembers.getMemberFields().length); assertEquals(2, simpleResolvedTypeWithMembers.getConstructors().length); @@ -253,7 +262,12 @@ public void testFilters() }); simpleResolvedTypeWithMembers = mr.resolve(simpleResolvedType, null, null); - assertEquals(12, simpleResolvedTypeWithMembers.getMemberMethods().length); + + // With JDK < 21, 12 member methods, 21+ 13 + methodCount = simpleResolvedTypeWithMembers.getMemberMethods().length; + if (methodCount < 12 || methodCount > 13) { + fail("Expected [12, 13] methods, got: "+methodCount); + } assertEquals(0, simpleResolvedTypeWithMembers.getMemberFields().length); assertEquals(2, simpleResolvedTypeWithMembers.getConstructors().length); @@ -267,7 +281,11 @@ public void testFilters() }); simpleResolvedTypeWithMembers = mr.resolve(simpleResolvedType, null, null); - assertEquals(12, simpleResolvedTypeWithMembers.getMemberMethods().length); + // With JDK < 21, 12 member methods, 21+ 13 + methodCount = simpleResolvedTypeWithMembers.getMemberMethods().length; + if (methodCount < 12 || methodCount > 13) { + fail("Expected [12, 13] methods, got: "+methodCount); + } assertEquals(1, simpleResolvedTypeWithMembers.getMemberFields().length); assertEquals(1, simpleResolvedTypeWithMembers.getConstructors().length); }