Skip to content

Commit e489706

Browse files
committed
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
1 parent 69bbdce commit e489706

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,14 @@ void styleDateWithInvalidFormat() {
140140
.hasCauseInstanceOf(ParseException.class).getCause()
141141
// Unable to parse date time value "99/01/01" using configuration from
142142
// @org.springframework.format.annotation.DateTimeFormat(pattern=, style=S-, iso=NONE, fallbackPatterns=[])
143+
// We do not check "fallbackPatterns=[]", since the array representation in the toString()
144+
// implementation for annotations changed from [] to {} in Java 9. In addition, strings
145+
// are enclosed in double quotes beginning with Java 9. Thus, we cannot check directly
146+
// for the presence of "style=S-".
143147
.hasMessageContainingAll(
144148
"Unable to parse date time value \"99/01/01\" using configuration from",
145149
"@org.springframework.format.annotation.DateTimeFormat",
146-
"style=S-", "iso=NONE", "fallbackPatterns=[]")
150+
"style=", "S-", "iso=NONE")
147151
.hasCauseInstanceOf(ParseException.class).getCause()
148152
.hasMessageStartingWith("Unparseable date: \"99/01/01\"")
149153
.hasNoCause();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,11 @@ void isoLocalDateWithInvalidFormat() {
339339
.hasCauseInstanceOf(DateTimeParseException.class).getCause()
340340
// Unable to parse date time value "2009-31-10" using configuration from
341341
// @org.springframework.format.annotation.DateTimeFormat(pattern=, style=SS, iso=DATE, fallbackPatterns=[])
342+
// We do not check "fallbackPatterns=[]", since the array representation in the toString()
343+
// implementation for annotations changed from [] to {} in Java 9.
342344
.hasMessageContainingAll(
343345
"Unable to parse date time value \"2009-31-10\" using configuration from",
344-
"@org.springframework.format.annotation.DateTimeFormat",
345-
"iso=DATE", "fallbackPatterns=[]")
346+
"@org.springframework.format.annotation.DateTimeFormat", "iso=DATE")
346347
.hasCauseInstanceOf(DateTimeParseException.class).getCause()
347348
.hasMessageStartingWith("Text '2009-31-10'")
348349
.hasCauseInstanceOf(DateTimeException.class).getCause()

0 commit comments

Comments
 (0)