Rewrite the `testParsingDatesFormattedWithSystemLocale()`, Fix #2199 (#2287)

* Rewrite the `testParsingDatesFormattedWithSystemLocale()`, Fix #2199

* Format the test

* Format the code following Google Java Style Guide

* Revert "Format the code following Google Java Style Guide"

This reverts commit f5e2e16b290a4bed09ed7fcc162d4a2529fe4c38.
This commit is contained in:
Maicol 2022-12-16 20:18:32 +01:00 committed by GitHub
parent f2f53fbe8e
commit 6c12ded70d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 16 deletions

View File

@ -74,31 +74,35 @@ public class DefaultDateTypeAdapterTest extends TestCase {
} }
public void testParsingDatesFormattedWithSystemLocale() throws Exception { public void testParsingDatesFormattedWithSystemLocale() throws Exception {
// TODO(eamonnmcmanus): fix this test, which fails on JDK 8 and 17
if (JavaVersion.getMajorJavaVersion() != 11) {
return;
}
TimeZone defaultTimeZone = TimeZone.getDefault(); TimeZone defaultTimeZone = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone("UTC")); TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
Locale defaultLocale = Locale.getDefault(); Locale defaultLocale = Locale.getDefault();
Locale.setDefault(Locale.FRANCE); Locale.setDefault(Locale.FRANCE);
try { try {
String afterYearSep = JavaVersion.isJava9OrLater() ? " à " : " "; Date date = new Date(0);
assertParsed(String.format("1 janv. 1970%s00:00:00", afterYearSep), assertParsed(
DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(date),
DateType.DATE.createDefaultsAdapterFactory()); DateType.DATE.createDefaultsAdapterFactory());
assertParsed("01/01/70", DateType.DATE.createAdapterFactory(DateFormat.SHORT)); assertParsed(
assertParsed("1 janv. 1970", DateType.DATE.createAdapterFactory(DateFormat.MEDIUM)); DateFormat.getDateInstance(DateFormat.SHORT).format(date),
assertParsed("1 janvier 1970", DateType.DATE.createAdapterFactory(DateFormat.LONG)); DateType.DATE.createAdapterFactory(DateFormat.SHORT));
assertParsed("01/01/70 00:00", assertParsed(
DateFormat.getDateInstance(DateFormat.MEDIUM).format(date),
DateType.DATE.createAdapterFactory(DateFormat.MEDIUM));
assertParsed(
DateFormat.getDateInstance(DateFormat.LONG).format(date),
DateType.DATE.createAdapterFactory(DateFormat.LONG));
assertParsed(
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(date),
DateType.DATE.createAdapterFactory(DateFormat.SHORT, DateFormat.SHORT)); DateType.DATE.createAdapterFactory(DateFormat.SHORT, DateFormat.SHORT));
assertParsed(String.format("1 janv. 1970%s00:00:00", afterYearSep), assertParsed(
DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(date),
DateType.DATE.createAdapterFactory(DateFormat.MEDIUM, DateFormat.MEDIUM)); DateType.DATE.createAdapterFactory(DateFormat.MEDIUM, DateFormat.MEDIUM));
assertParsed(String.format("1 janvier 1970%s00:00:00 UTC", afterYearSep), assertParsed(
DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(date),
DateType.DATE.createAdapterFactory(DateFormat.LONG, DateFormat.LONG)); DateType.DATE.createAdapterFactory(DateFormat.LONG, DateFormat.LONG));
assertParsed(JavaVersion.isJava9OrLater() ? (JavaVersion.getMajorJavaVersion() <11 ? assertParsed(
"jeudi 1 janvier 1970 à 00:00:00 Coordinated Universal Time" : DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(date),
"jeudi 1 janvier 1970 à 00:00:00 Temps universel coordonné") :
"jeudi 1 janvier 1970 00 h 00 UTC",
DateType.DATE.createAdapterFactory(DateFormat.FULL, DateFormat.FULL)); DateType.DATE.createAdapterFactory(DateFormat.FULL, DateFormat.FULL));
} finally { } finally {
TimeZone.setDefault(defaultTimeZone); TimeZone.setDefault(defaultTimeZone);