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
This commit is contained in:
parent
69bbdce826
commit
e489706f13
|
@ -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();
|
||||
|
|
|
@ -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…
Reference in New Issue