提交 e489706f 编写于 作者: S Sam Brannen

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
上级 69bbdce8
...@@ -140,10 +140,14 @@ public class DateFormattingTests { ...@@ -140,10 +140,14 @@ public class DateFormattingTests {
.hasCauseInstanceOf(ParseException.class).getCause() .hasCauseInstanceOf(ParseException.class).getCause()
// Unable to parse date time value "99/01/01" using configuration from // Unable to parse date time value "99/01/01" using configuration from
// @org.springframework.format.annotation.DateTimeFormat(pattern=, style=S-, iso=NONE, fallbackPatterns=[]) // @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( .hasMessageContainingAll(
"Unable to parse date time value \"99/01/01\" using configuration from", "Unable to parse date time value \"99/01/01\" using configuration from",
"@org.springframework.format.annotation.DateTimeFormat", "@org.springframework.format.annotation.DateTimeFormat",
"style=S-", "iso=NONE", "fallbackPatterns=[]") "style=", "S-", "iso=NONE")
.hasCauseInstanceOf(ParseException.class).getCause() .hasCauseInstanceOf(ParseException.class).getCause()
.hasMessageStartingWith("Unparseable date: \"99/01/01\"") .hasMessageStartingWith("Unparseable date: \"99/01/01\"")
.hasNoCause(); .hasNoCause();
......
...@@ -339,10 +339,11 @@ class DateTimeFormattingTests { ...@@ -339,10 +339,11 @@ class DateTimeFormattingTests {
.hasCauseInstanceOf(DateTimeParseException.class).getCause() .hasCauseInstanceOf(DateTimeParseException.class).getCause()
// Unable to parse date time value "2009-31-10" using configuration from // Unable to parse date time value "2009-31-10" using configuration from
// @org.springframework.format.annotation.DateTimeFormat(pattern=, style=SS, iso=DATE, fallbackPatterns=[]) // @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( .hasMessageContainingAll(
"Unable to parse date time value \"2009-31-10\" using configuration from", "Unable to parse date time value \"2009-31-10\" using configuration from",
"@org.springframework.format.annotation.DateTimeFormat", "@org.springframework.format.annotation.DateTimeFormat", "iso=DATE")
"iso=DATE", "fallbackPatterns=[]")
.hasCauseInstanceOf(DateTimeParseException.class).getCause() .hasCauseInstanceOf(DateTimeParseException.class).getCause()
.hasMessageStartingWith("Text '2009-31-10'") .hasMessageStartingWith("Text '2009-31-10'")
.hasCauseInstanceOf(DateTimeException.class).getCause() .hasCauseInstanceOf(DateTimeException.class).getCause()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册