Browse Source

Merge branch '5.3.x'

# Conflicts:
#	spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java
pull/28041/head
Sam Brannen 4 years ago
parent
commit
a4e192e33d
  1. 75
      spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java

75
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 jakarta.annotation.Resource;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.JRE;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.core.annotation.MergedAnnotation.Adapt; import org.springframework.core.annotation.MergedAnnotation.Adapt;
@ -1872,57 +1871,41 @@ class MergedAnnotationsTests {
assertThat(webMappingWithAliases.toString()).isNotEqualTo(synthesizedWebMapping1.toString()); assertThat(webMappingWithAliases.toString()).isNotEqualTo(synthesizedWebMapping1.toString());
// The unsynthesized annotation for handleMappedWithSamePathAndValueAttributes() // The unsynthesized annotation for handleMappedWithSamePathAndValueAttributes()
// should produce the same toString() results as synthesized annotations for // should produce almost the same toString() results as synthesized annotations for
// handleMappedWithPathAttribute() on Java 9 or higher // handleMappedWithPathAttribute() on Java 9 or higher; however, due to multiple changes
assertToStringForWebMappingWithPathAndValue(webMappingWithPathAndValue); // 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(synthesizedWebMapping1);
assertToStringForWebMappingWithPathAndValue(synthesizedWebMapping2); assertToStringForWebMappingWithPathAndValue(synthesizedWebMapping2);
} }
private void assertToStringForWebMappingWithPathAndValue(RequestMapping webMapping) { private void assertToStringForWebMappingWithPathAndValue(RequestMapping webMapping) {
String string = webMapping.toString(); assertThat(webMapping.toString())
.startsWith("@org.springframework.core.annotation.MergedAnnotationsTests.RequestMapping(")
// Formatting common to Spring and JDK 9+ .contains(
assertThat(string) // Strings
.contains("value={\"/test\"}", "path={\"/test\"}", "name=\"bar\"", "ch='X'", "chars={'X'}") "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(")"); .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 @Test

Loading…
Cancel
Save