Skip to content

Commit 323f046

Browse files
committed
Refactor test as a @ParameterizedTest
1 parent 7335e26 commit 323f046

2 files changed

Lines changed: 18 additions & 25 deletions

File tree

src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -704,23 +704,20 @@ void testToStringContainsName() {
704704

705705
// we cannot use historic dates to test time zone parsing, some time zones have second offsets
706706
// as well as hours and minutes which makes the z formats a low fidelity round trip
707-
@Test
708-
void testTzParses() throws Exception {
707+
@ParameterizedTest
708+
@MethodSource("org.apache.commons.lang3.LocaleUtils#availableLocaleList()")
709+
void testTzParses(final Locale locale) throws Exception {
709710
// Check that all Locales can parse the time formats we use
710-
for (final Locale locale : Locale.getAvailableLocales()) {
711-
final FastDateParser fdp = new FastDateParser("yyyy/MM/dd z", TimeZone.getDefault(), locale);
712-
713-
for (final TimeZone timeZone : new TimeZone[] {NEW_YORK, REYKJAVIK, TimeZones.GMT}) {
714-
final Calendar cal = Calendar.getInstance(timeZone, locale);
715-
cal.clear();
716-
cal.set(Calendar.YEAR, 2000);
717-
cal.set(Calendar.MONTH, 1);
718-
cal.set(Calendar.DAY_OF_MONTH, 10);
719-
final Date expected = cal.getTime();
720-
721-
final Date actual = fdp.parse("2000/02/10 " + timeZone.getDisplayName(locale));
722-
assertEquals(expected, actual, "timeZone:" + timeZone.getID() + " locale:" + locale.getDisplayName());
723-
}
711+
final FastDateParser fdp = new FastDateParser("yyyy/MM/dd z", TimeZone.getDefault(), locale);
712+
for (final TimeZone timeZone : new TimeZone[] { NEW_YORK, REYKJAVIK, TimeZones.GMT }) {
713+
final Calendar cal = Calendar.getInstance(timeZone, locale);
714+
cal.clear();
715+
cal.set(Calendar.YEAR, 2000);
716+
cal.set(Calendar.MONTH, 1);
717+
cal.set(Calendar.DAY_OF_MONTH, 10);
718+
final Date expected = cal.getTime();
719+
final Date actual = fdp.parse("2000/02/10 " + timeZone.getDisplayName(locale));
720+
assertEquals(expected, actual, "timeZone:" + timeZone.getID() + " locale:" + locale.getDisplayName());
724721
}
725722
}
726723

src/test/java/org/apache/commons/lang3/time/Java15BugFastDateParserTest.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,31 +58,27 @@ void testJava15BuggyLocaleTest() throws ParseException {
5858
testSingleLocale(buggyLocale);
5959
}
6060

61-
@Test
62-
void testJava15BuggyLocaleTestAll() throws ParseException {
63-
for (final Locale locale : Locale.getAvailableLocales()) {
64-
testSingleLocale(locale);
65-
}
61+
@ParameterizedTest
62+
@MethodSource("org.apache.commons.lang3.LocaleUtils#availableLocaleList()")
63+
void testJava15BuggyLocaleTestAll(final Locale locale) throws ParseException {
64+
testSingleLocale(locale);
6665
}
6766

6867
private void testLocales(final TriFunction<String, TimeZone, Locale, DateParser> dbProvider, final String format,
69-
final boolean eraBC) throws Exception {
70-
68+
final boolean eraBC) throws Exception {
7169
final Calendar cal = Calendar.getInstance(TimeZones.GMT);
7270
cal.clear();
7371
cal.set(2003, Calendar.FEBRUARY, 10);
7472
if (eraBC) {
7573
cal.set(Calendar.ERA, GregorianCalendar.BC);
7674
}
77-
7875
for (final Locale locale : Locale.getAvailableLocales()) {
7976
// ja_JP_JP cannot handle dates before 1868 properly
8077
if (eraBC && locale.equals(FastDateParser.JAPANESE_IMPERIAL)) {
8178
continue;
8279
}
8380
final SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
8481
final DateParser fdf = dbProvider.apply(format, TimeZone.getDefault(), locale);
85-
8682
// If parsing fails, a ParseException will be thrown and the test will fail
8783
FastDateParserTest.checkParse(locale, cal, sdf, fdf);
8884
}

0 commit comments

Comments
 (0)