Skip to content

Commit 6c12ded

Browse files
authored
Rewrite the testParsingDatesFormattedWithSystemLocale(), Fix google#2199 (google#2287)
* Rewrite the `testParsingDatesFormattedWithSystemLocale()`, Fix google#2199 * Format the test * Format the code following Google Java Style Guide * Revert "Format the code following Google Java Style Guide" This reverts commit f5e2e16.
1 parent f2f53fb commit 6c12ded

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

gson/src/test/java/com/google/gson/internal/bind/DefaultDateTypeAdapterTest.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,31 +74,35 @@ private void assertFormattingAlwaysEmitsUsLocale(Locale locale) {
7474
}
7575

7676
public void testParsingDatesFormattedWithSystemLocale() throws Exception {
77-
// TODO(eamonnmcmanus): fix this test, which fails on JDK 8 and 17
78-
if (JavaVersion.getMajorJavaVersion() != 11) {
79-
return;
80-
}
8177
TimeZone defaultTimeZone = TimeZone.getDefault();
8278
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
8379
Locale defaultLocale = Locale.getDefault();
8480
Locale.setDefault(Locale.FRANCE);
8581
try {
86-
String afterYearSep = JavaVersion.isJava9OrLater() ? " à " : " ";
87-
assertParsed(String.format("1 janv. 1970%s00:00:00", afterYearSep),
82+
Date date = new Date(0);
83+
assertParsed(
84+
DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(date),
8885
DateType.DATE.createDefaultsAdapterFactory());
89-
assertParsed("01/01/70", DateType.DATE.createAdapterFactory(DateFormat.SHORT));
90-
assertParsed("1 janv. 1970", DateType.DATE.createAdapterFactory(DateFormat.MEDIUM));
91-
assertParsed("1 janvier 1970", DateType.DATE.createAdapterFactory(DateFormat.LONG));
92-
assertParsed("01/01/70 00:00",
86+
assertParsed(
87+
DateFormat.getDateInstance(DateFormat.SHORT).format(date),
88+
DateType.DATE.createAdapterFactory(DateFormat.SHORT));
89+
assertParsed(
90+
DateFormat.getDateInstance(DateFormat.MEDIUM).format(date),
91+
DateType.DATE.createAdapterFactory(DateFormat.MEDIUM));
92+
assertParsed(
93+
DateFormat.getDateInstance(DateFormat.LONG).format(date),
94+
DateType.DATE.createAdapterFactory(DateFormat.LONG));
95+
assertParsed(
96+
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(date),
9397
DateType.DATE.createAdapterFactory(DateFormat.SHORT, DateFormat.SHORT));
94-
assertParsed(String.format("1 janv. 1970%s00:00:00", afterYearSep),
98+
assertParsed(
99+
DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(date),
95100
DateType.DATE.createAdapterFactory(DateFormat.MEDIUM, DateFormat.MEDIUM));
96-
assertParsed(String.format("1 janvier 1970%s00:00:00 UTC", afterYearSep),
101+
assertParsed(
102+
DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(date),
97103
DateType.DATE.createAdapterFactory(DateFormat.LONG, DateFormat.LONG));
98-
assertParsed(JavaVersion.isJava9OrLater() ? (JavaVersion.getMajorJavaVersion() <11 ?
99-
"jeudi 1 janvier 1970 à 00:00:00 Coordinated Universal Time" :
100-
"jeudi 1 janvier 1970 à 00:00:00 Temps universel coordonné") :
101-
"jeudi 1 janvier 1970 00 h 00 UTC",
104+
assertParsed(
105+
DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(date),
102106
DateType.DATE.createAdapterFactory(DateFormat.FULL, DateFormat.FULL));
103107
} finally {
104108
TimeZone.setDefault(defaultTimeZone);

0 commit comments

Comments
 (0)