diff --git a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java index 3a1151e5f62..a64233d4851 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java @@ -37,7 +37,6 @@ import java.util.stream.Stream; import jakarta.annotation.Resource; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.JRE; import org.springframework.core.Ordered; import org.springframework.core.annotation.MergedAnnotation.Adapt; @@ -1872,57 +1871,41 @@ class MergedAnnotationsTests { assertThat(webMappingWithAliases.toString()).isNotEqualTo(synthesizedWebMapping1.toString()); // The unsynthesized annotation for handleMappedWithSamePathAndValueAttributes() - // should produce the same toString() results as synthesized annotations for - // handleMappedWithPathAttribute() on Java 9 or higher - assertToStringForWebMappingWithPathAndValue(webMappingWithPathAndValue); + // should produce almost the same toString() results as synthesized annotations for + // handleMappedWithPathAttribute() on Java 9 or higher; however, due to multiple changes + // in the JDK's toString() implementation for annotations in JDK 9, 14, and 19, + // we do not test the JDK implementation. + // assertToStringForWebMappingWithPathAndValue(webMappingWithPathAndValue); + assertToStringForWebMappingWithPathAndValue(synthesizedWebMapping1); assertToStringForWebMappingWithPathAndValue(synthesizedWebMapping2); } private void assertToStringForWebMappingWithPathAndValue(RequestMapping webMapping) { - String string = webMapping.toString(); - - // Formatting common to Spring and JDK 9+ - assertThat(string) - .contains("value={\"/test\"}", "path={\"/test\"}", "name=\"bar\"", "ch='X'", "chars={'X'}") + assertThat(webMapping.toString()) + .startsWith("@org.springframework.core.annotation.MergedAnnotationsTests.RequestMapping(") + .contains( + // Strings + "value={\"/test\"}", "path={\"/test\"}", "name=\"bar\"", + // Characters + "ch='X'", "chars={'X'}", + // Enums + "method={GET, POST}", + // Classes + "clazz=org.springframework.core.annotation.MergedAnnotationsTests.RequestMethod.class", + "classes={int[][].class, org.springframework.core.annotation.MergedAnnotationsTests.RequestMethod[].class}", + // Bytes + "byteValue=(byte) 0xFF", "bytes={(byte) 0xFF}", + // Shorts + "shortValue=9876", "shorts={9876}", + // Longs + "longValue=42L", "longs={42L}", + // Floats + "floatValue=3.14f", "floats={3.14f}", + // Doubles + "doubleValue=99.999d", "doubles={99.999d}" + ) .endsWith(")"); - - if (webMapping instanceof SynthesizedAnnotation) { - assertThat(string).as("Spring formatting") - .startsWith("@org.springframework.core.annotation.MergedAnnotationsTests.RequestMapping(") - .contains("method={GET, POST}", - "clazz=org.springframework.core.annotation.MergedAnnotationsTests.RequestMethod.class", - "classes={int[][].class, org.springframework.core.annotation.MergedAnnotationsTests.RequestMethod[].class}", - "byteValue=(byte) 0xFF", "bytes={(byte) 0xFF}", - "shortValue=9876", "shorts={9876}", - "longValue=42L", "longs={42L}", - "floatValue=3.14f", "floats={3.14f}", - "doubleValue=99.999d", "doubles={99.999d}" - ); - } - else { - assertThat(string).as("JDK 9-18 formatting") - .startsWith("@org.springframework.core.annotation.MergedAnnotationsTests$RequestMapping(") - .contains("method={method: get, method: post}", - "clazz=org.springframework.core.annotation.MergedAnnotationsTests$RequestMethod.class", - "classes={int[][].class, org.springframework.core.annotation.MergedAnnotationsTests$RequestMethod[].class}", - "shortValue=9876", "shorts={9876}", - "floatValue=3.14f", "floats={3.14f}", - "doubleValue=99.999", "doubles={99.999}" - ); - if (JRE.currentVersion().ordinal() < JRE.JAVA_14.ordinal()) { - assertThat(string).as("JDK 9-13 formatting") - .contains("longValue=42", "longs={42}", - "byteValue=-1", "bytes={-1}" - ); - } - else { - assertThat(string).as("JDK 14+ formatting") - .contains("longValue=42L", "longs={42L}", - "byteValue=(byte)0xff", "bytes={(byte)0xff}" - ); - } - } } @Test