Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
47 changes: 32 additions & 15 deletions src/test/java/com/fasterxml/classmate/AnnotationsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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");

Expand All @@ -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");

Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/*
/**********************************************************************
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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);
}
Expand Down