Skip to content

Commit b97092d

Browse files
MaicolAntalitibor-universe
authored andcommitted
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. (cherry picked from commit 6c12ded)
1 parent f861617 commit b97092d

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

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

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,32 +77,35 @@ private void assertFormattingAlwaysEmitsUsLocale(Locale locale) {
7777
}
7878

7979
public void testParsingDatesFormattedWithSystemLocale() throws Exception {
80-
// TODO(eamonnmcmanus): fix this test, which fails on JDK 8 and 17
81-
if (JavaVersion.getMajorJavaVersion() != 11) {
82-
return;
83-
}
8480
TimeZone defaultTimeZone = TimeZone.getDefault();
8581
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
8682
Locale defaultLocale = Locale.getDefault();
8783
Locale.setDefault(Locale.FRANCE);
8884
try {
89-
String afterYearSep1 = JavaVersion.isJava9OrLater() ? JavaVersion.getMajorJavaVersion() < 16 ? " à " : ", " : " ";
90-
String afterYearSep2 = JavaVersion.isJava9OrLater() ? " à " : " ";
91-
assertParsed(String.format("1 janv. 1970%s00:00:00", afterYearSep1),
85+
Date date = new Date(0);
86+
assertParsed(
87+
DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(date),
9288
DateType.DATE.createDefaultsAdapterFactory());
93-
assertParsed("01/01/70", DateType.DATE.createAdapterFactory(DateFormat.SHORT));
94-
assertParsed("1 janv. 1970", DateType.DATE.createAdapterFactory(DateFormat.MEDIUM));
95-
assertParsed("1 janvier 1970", DateType.DATE.createAdapterFactory(DateFormat.LONG));
96-
assertParsed("01/01/70 00:00",
89+
assertParsed(
90+
DateFormat.getDateInstance(DateFormat.SHORT).format(date),
91+
DateType.DATE.createAdapterFactory(DateFormat.SHORT));
92+
assertParsed(
93+
DateFormat.getDateInstance(DateFormat.MEDIUM).format(date),
94+
DateType.DATE.createAdapterFactory(DateFormat.MEDIUM));
95+
assertParsed(
96+
DateFormat.getDateInstance(DateFormat.LONG).format(date),
97+
DateType.DATE.createAdapterFactory(DateFormat.LONG));
98+
assertParsed(
99+
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(date),
97100
DateType.DATE.createAdapterFactory(DateFormat.SHORT, DateFormat.SHORT));
98-
assertParsed(String.format("1 janv. 1970%s00:00:00", afterYearSep1),
101+
assertParsed(
102+
DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(date),
99103
DateType.DATE.createAdapterFactory(DateFormat.MEDIUM, DateFormat.MEDIUM));
100-
assertParsed(String.format("1 janvier 1970%s00:00:00 UTC", afterYearSep2),
104+
assertParsed(
105+
DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(date),
101106
DateType.DATE.createAdapterFactory(DateFormat.LONG, DateFormat.LONG));
102-
assertParsed(JavaVersion.isJava9OrLater() ? (JavaVersion.getMajorJavaVersion() < 11 ?
103-
"jeudi 1 janvier 1970 à 00:00:00 Coordinated Universal Time" :
104-
"jeudi 1 janvier 1970 à 00:00:00 Temps universel coordonné") :
105-
"jeudi 1 janvier 1970 00 h 00 UTC",
107+
assertParsed(
108+
DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(date),
106109
DateType.DATE.createAdapterFactory(DateFormat.FULL, DateFormat.FULL));
107110
} finally {
108111
TimeZone.setDefault(defaultTimeZone);

0 commit comments

Comments
 (0)