refine tests

This commit is contained in:
XenoAmess 2020-06-26 16:54:16 +08:00
parent acb237c52d
commit dd5d284e86
1 changed files with 13 additions and 5 deletions

View File

@ -708,29 +708,37 @@ public class FastDateParserTest {
assertEquals(expected.getTime(), fdp.parse("14 avr 2014")); assertEquals(expected.getTime(), fdp.parse("14 avr 2014"));
} }
@Test
public void java15BuggyLocaleTestAll() throws ParseException {
for (final Locale locale : Locale.getAvailableLocales()) {
testSingleLocale(locale);
}
}
@Test @Test
public void java15BuggyLocaleTest() throws ParseException { public void java15BuggyLocaleTest() throws ParseException {
final String buggyLocaleName = "ff_LR_#Adlm"; final String buggyLocaleName = "ff_LR_#Adlm";
Locale buggyLocale = null; Locale buggyLocale = null;
for (final Locale locale : Locale.getAvailableLocales()) { for (final Locale locale : Locale.getAvailableLocales()) {
if (buggyLocaleName.equals(locale.toString())) { if (buggyLocaleName.equals(locale.toString())) {
buggyLocale = locale; buggyLocale = locale;
break; break;
} }
} }
if (buggyLocale == null) { if (buggyLocale == null) {
return; return;
} }
testSingleLocale(buggyLocale);
}
private void testSingleLocale(Locale locale) throws ParseException {
final Calendar cal = Calendar.getInstance(GMT); final Calendar cal = Calendar.getInstance(GMT);
cal.clear(); cal.clear();
cal.set(2003, Calendar.FEBRUARY, 10); cal.set(2003, Calendar.FEBRUARY, 10);
final SimpleDateFormat sdf = new SimpleDateFormat(LONG_FORMAT, buggyLocale); final SimpleDateFormat sdf = new SimpleDateFormat(LONG_FORMAT, locale);
final String formattedDate = sdf.format(cal.getTime()); final String formattedDate = sdf.format(cal.getTime());
sdf.parse(formattedDate); sdf.parse(formattedDate);
sdf.parse(formattedDate.toUpperCase(buggyLocale)); sdf.parse(formattedDate.toUpperCase(locale));
sdf.parse(formattedDate.toLowerCase(buggyLocale)); sdf.parse(formattedDate.toLowerCase(locale));
} }
} }