You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/06/11 19:55:37 UTC
(commons-lang) 05/06: Refactor test as a @ParameterizedTest
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
commit 323f046c23823d70cda067c90d269c305a8ceb62
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Wed Jun 11 15:55:04 2025 -0400
Refactor test as a @ParameterizedTest
---
.../commons/lang3/time/FastDateParserTest.java | 29 ++++++++++------------
.../lang3/time/Java15BugFastDateParserTest.java | 14 ++++-------
2 files changed, 18 insertions(+), 25 deletions(-)
diff --git a/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java b/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
index d6540ed07..5c4a4225a 100644
--- a/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
@@ -704,23 +704,20 @@ void testToStringContainsName() {
// we cannot use historic dates to test time zone parsing, some time zones have second offsets
// as well as hours and minutes which makes the z formats a low fidelity round trip
- @Test
- void testTzParses() throws Exception {
+ @ParameterizedTest
+ @MethodSource("org.apache.commons.lang3.LocaleUtils#availableLocaleList()")
+ void testTzParses(final Locale locale) throws Exception {
// Check that all Locales can parse the time formats we use
- for (final Locale locale : Locale.getAvailableLocales()) {
- final FastDateParser fdp = new FastDateParser("yyyy/MM/dd z", TimeZone.getDefault(), locale);
-
- for (final TimeZone timeZone : new TimeZone[] {NEW_YORK, REYKJAVIK, TimeZones.GMT}) {
- final Calendar cal = Calendar.getInstance(timeZone, locale);
- cal.clear();
- cal.set(Calendar.YEAR, 2000);
- cal.set(Calendar.MONTH, 1);
- cal.set(Calendar.DAY_OF_MONTH, 10);
- final Date expected = cal.getTime();
-
- final Date actual = fdp.parse("2000/02/10 " + timeZone.getDisplayName(locale));
- assertEquals(expected, actual, "timeZone:" + timeZone.getID() + " locale:" + locale.getDisplayName());
- }
+ final FastDateParser fdp = new FastDateParser("yyyy/MM/dd z", TimeZone.getDefault(), locale);
+ for (final TimeZone timeZone : new TimeZone[] { NEW_YORK, REYKJAVIK, TimeZones.GMT }) {
+ final Calendar cal = Calendar.getInstance(timeZone, locale);
+ cal.clear();
+ cal.set(Calendar.YEAR, 2000);
+ cal.set(Calendar.MONTH, 1);
+ cal.set(Calendar.DAY_OF_MONTH, 10);
+ final Date expected = cal.getTime();
+ final Date actual = fdp.parse("2000/02/10 " + timeZone.getDisplayName(locale));
+ assertEquals(expected, actual, "timeZone:" + timeZone.getID() + " locale:" + locale.getDisplayName());
}
}
diff --git a/src/test/java/org/apache/commons/lang3/time/Java15BugFastDateParserTest.java b/src/test/java/org/apache/commons/lang3/time/Java15BugFastDateParserTest.java
index 45ac0513d..fbbb8f0e6 100644
--- a/src/test/java/org/apache/commons/lang3/time/Java15BugFastDateParserTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/Java15BugFastDateParserTest.java
@@ -58,23 +58,20 @@ void testJava15BuggyLocaleTest() throws ParseException {
testSingleLocale(buggyLocale);
}
- @Test
- void testJava15BuggyLocaleTestAll() throws ParseException {
- for (final Locale locale : Locale.getAvailableLocales()) {
- testSingleLocale(locale);
- }
+ @ParameterizedTest
+ @MethodSource("org.apache.commons.lang3.LocaleUtils#availableLocaleList()")
+ void testJava15BuggyLocaleTestAll(final Locale locale) throws ParseException {
+ testSingleLocale(locale);
}
private void testLocales(final TriFunction<String, TimeZone, Locale, DateParser> dbProvider, final String format,
- final boolean eraBC) throws Exception {
-
+ final boolean eraBC) throws Exception {
final Calendar cal = Calendar.getInstance(TimeZones.GMT);
cal.clear();
cal.set(2003, Calendar.FEBRUARY, 10);
if (eraBC) {
cal.set(Calendar.ERA, GregorianCalendar.BC);
}
-
for (final Locale locale : Locale.getAvailableLocales()) {
// ja_JP_JP cannot handle dates before 1868 properly
if (eraBC && locale.equals(FastDateParser.JAPANESE_IMPERIAL)) {
@@ -82,7 +79,6 @@ private void testLocales(final TriFunction<String, TimeZone, Locale, DateParser>
}
final SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
final DateParser fdf = dbProvider.apply(format, TimeZone.getDefault(), locale);
-
// If parsing fails, a ParseException will be thrown and the test will fail
FastDateParserTest.checkParse(locale, cal, sdf, fdf);
}