Browse Source

Ensure @DateTimeFormat tests pass on Java 9+

Prior to this commit, two tests for exception handling regarding
@DateTimeFormat processing only passed on Java 8. This is due to the
fact that the toString() implementation for annotations changed in Java
9. Specifically, the representation for arrays changed from [] to {},
and strings are enclosed in double quotes beginning with Java 9.

This commit ensures that the affected @DateTimeFormat tests pass on
Java 9+, by making the assertions more lenient regarding toString()
output for annotations.

See gh-26777
See gh-26804
pull/26823/head
Sam Brannen 4 years ago
parent
commit
e489706f13
  1. 6
      spring-context/src/test/java/org/springframework/format/datetime/DateFormattingTests.java
  2. 5
      spring-context/src/test/java/org/springframework/format/datetime/standard/DateTimeFormattingTests.java

6
spring-context/src/test/java/org/springframework/format/datetime/DateFormattingTests.java

@ -140,10 +140,14 @@ public class DateFormattingTests { @@ -140,10 +140,14 @@ public class DateFormattingTests {
.hasCauseInstanceOf(ParseException.class).getCause()
// Unable to parse date time value "99/01/01" using configuration from
// @org.springframework.format.annotation.DateTimeFormat(pattern=, style=S-, iso=NONE, fallbackPatterns=[])
// We do not check "fallbackPatterns=[]", since the array representation in the toString()
// implementation for annotations changed from [] to {} in Java 9. In addition, strings
// are enclosed in double quotes beginning with Java 9. Thus, we cannot check directly
// for the presence of "style=S-".
.hasMessageContainingAll(
"Unable to parse date time value \"99/01/01\" using configuration from",
"@org.springframework.format.annotation.DateTimeFormat",
"style=S-", "iso=NONE", "fallbackPatterns=[]")
"style=", "S-", "iso=NONE")
.hasCauseInstanceOf(ParseException.class).getCause()
.hasMessageStartingWith("Unparseable date: \"99/01/01\"")
.hasNoCause();

5
spring-context/src/test/java/org/springframework/format/datetime/standard/DateTimeFormattingTests.java

@ -339,10 +339,11 @@ class DateTimeFormattingTests { @@ -339,10 +339,11 @@ class DateTimeFormattingTests {
.hasCauseInstanceOf(DateTimeParseException.class).getCause()
// Unable to parse date time value "2009-31-10" using configuration from
// @org.springframework.format.annotation.DateTimeFormat(pattern=, style=SS, iso=DATE, fallbackPatterns=[])
// We do not check "fallbackPatterns=[]", since the array representation in the toString()
// implementation for annotations changed from [] to {} in Java 9.
.hasMessageContainingAll(
"Unable to parse date time value \"2009-31-10\" using configuration from",
"@org.springframework.format.annotation.DateTimeFormat",
"iso=DATE", "fallbackPatterns=[]")
"@org.springframework.format.annotation.DateTimeFormat", "iso=DATE")
.hasCauseInstanceOf(DateTimeParseException.class).getCause()
.hasMessageStartingWith("Text '2009-31-10'")
.hasCauseInstanceOf(DateTimeException.class).getCause()

Loading…
Cancel
Save