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 2026/06/07 12:31:33 UTC
(commons-lang) 02/02: Refactor some tests
This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
commit b10be28d248ee40442bb718bb64d26be1ac82454
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jun 7 08:31:25 2026 -0400
Refactor some tests
---
.../time/FastDateParser_TimeZoneStrategyTest.java | 82 ++++++++++++----------
.../lang3/time/FastDatePrinterTimeZonesTest.java | 8 ++-
2 files changed, 49 insertions(+), 41 deletions(-)
diff --git a/src/test/java/org/apache/commons/lang3/time/FastDateParser_TimeZoneStrategyTest.java b/src/test/java/org/apache/commons/lang3/time/FastDateParser_TimeZoneStrategyTest.java
index 61f3cd540..3a73dea64 100644
--- a/src/test/java/org/apache/commons/lang3/time/FastDateParser_TimeZoneStrategyTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/FastDateParser_TimeZoneStrategyTest.java
@@ -63,17 +63,18 @@
/* Make test reproducible */ @ReadsDefaultTimeZone
class FastDateParser_TimeZoneStrategyTest extends AbstractLangTest {
- private static final List<Locale> Java11Failures = new ArrayList<>();
- private static final List<Locale> Java17Failures = new ArrayList<>();
- private static final AtomicInteger fails = new AtomicInteger();
+ private static final String UTC_FULL_NAME = "Coordinated Universal Time";
+ private static final List<Locale> JAVA_11_FAILURES = new ArrayList<>();
+ private static final List<Locale> JAVA_17_FAILURES = new ArrayList<>();
+ private static final AtomicInteger FAILS = new AtomicInteger();
@AfterAll
public static void afterAll() {
- if (!Java17Failures.isEmpty()) {
- System.err.printf("Actual failures on Java 17+: %,d%n%s%n", Java17Failures.size(), Java17Failures);
+ if (!JAVA_17_FAILURES.isEmpty()) {
+ System.err.printf("Actual failures on Java 17+: %,d%n%s%n", JAVA_17_FAILURES.size(), JAVA_17_FAILURES);
}
- if (!Java11Failures.isEmpty()) {
- System.err.printf("Actual failures on Java 11: %,d%n%s%n", Java11Failures.size(), Java11Failures);
+ if (!JAVA_11_FAILURES.isEmpty()) {
+ System.err.printf("Actual failures on Java 11: %,d%n%s%n", JAVA_11_FAILURES.size(), JAVA_11_FAILURES);
}
}
@@ -133,12 +134,35 @@ void testLang1219() throws ParseException {
void testTimeZoneStrategy_DateFormatSymbols(final Locale locale) {
testTimeZoneStrategyPattern_DateFormatSymbols_getZoneStrings(locale);
}
+
@ParameterizedTest
@MethodSource("org.apache.commons.lang3.LocaleUtils#availableLocaleList()")
void testTimeZoneStrategy_TimeZone(final Locale locale) {
testTimeZoneStrategyPattern_TimeZone_getAvailableIDs(locale);
}
+ private void testTimeZoneStrategyPattern(final Locale locale, final String timeZoneId) {
+ final TimeZone timeZone = TimeZones.getTimeZone(timeZoneId);
+ final String displayName = timeZone.getDisplayName(locale);
+ final FastDateParser parser = new FastDateParser("z", timeZone, locale);
+ try {
+ parser.parse(displayName);
+ } catch (final ParseException e) {
+ final StringBuilder sb = new StringBuilder("chars: [");
+ displayName.chars().forEach(c -> sb.append(c).append(", "));
+ sb.append("], code points: [");
+ displayName.codePoints().forEach(c -> sb.append(c).append(", "));
+ sb.append("]");
+ if (displayName.contains("\uFFFD")) {
+ System.err.printf("TimeZone ID %s displayName contains Unicode character 'REPLACEMENT CHARACTER' (U+FFFD) in '%s'%n", timeZoneId, displayName);
+ } else {
+ // Missing "Zulu" or something else in broken JDK's GH builds?
+ fail(String.format("displayName: '%s' for id: '%s', %s, exception: %s, %s, parser = %s", displayName, timeZoneId, sb.toString(), e,
+ toFailureMessage(locale, null, timeZone), parser.toStringAll()));
+ }
+ }
+ }
+
private void testTimeZoneStrategyPattern(final String languageTag, final String source) throws ParseException {
final Locale locale = Locale.forLanguageTag(languageTag);
final TimeZone timeZone = TimeZones.getTimeZone("Etc/UTC");
@@ -153,7 +177,6 @@ private void testTimeZoneStrategyPattern_DateFormatSymbols_getZoneStrings(final
Objects.requireNonNull(locale, "locale");
assumeFalse(LocaleUtils.isLanguageUndetermined(locale), () -> toFailureMessage(locale, null, null));
assumeTrue(LocaleUtils.isAvailableLocale(locale), () -> toFailureMessage(locale, null, null));
-
final String[][] zones = getZoneStringsSorted(locale);
for (final String[] zone : zones) {
for (int zIndex = 1; zIndex < zone.length; ++zIndex) {
@@ -171,37 +194,38 @@ private void testTimeZoneStrategyPattern_DateFormatSymbols_getZoneStrings(final
// See failures on GitHub Actions builds for Java 17.
final String localeStr = locale.toString();
if (SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_17)
- && (localeStr.contains("_") || "Coordinated Universal Time".equals(tzDisplay)
- || "sommartid – Atyrau".equals(tzDisplay))) {
- Java17Failures.add(locale);
+ && (localeStr.contains("_") || UTC_FULL_NAME.equals(tzDisplay) || "sommartid – Atyrau".equals(tzDisplay))) {
+ JAVA_17_FAILURES.add(locale);
// Mark as an assumption failure instead of a hard fail
+ // @formatter:off
System.err.printf(
"[%,d][%s] Java %s %s - Mark as an assumption failure instead of a hard fail: locale = '%s', parse = '%s'%n",
- fails.incrementAndGet(),
+ FAILS.incrementAndGet(),
Thread.currentThread().getName(),
SystemUtils.JAVA_VENDOR,
SystemUtils.JAVA_VM_VERSION,
localeStr, tzDisplay);
+ // @formatter:on
assumeTrue(false, localeStr);
continue;
}
- if (SystemUtils.IS_JAVA_11
- && (localeStr.contains("_") || "Coordinated Universal Time".equals(tzDisplay))) {
- Java11Failures.add(locale);
+ if (SystemUtils.IS_JAVA_11 && (localeStr.contains("_") || UTC_FULL_NAME.equals(tzDisplay))) {
+ JAVA_11_FAILURES.add(locale);
// Mark as an assumption failure instead of a hard fail
+ // @formatter:off
System.err.printf(
"[%,d][%s] Java %s %s - Mark as an assumption failure instead of a hard fail: locale = '%s', parse = '%s'%n",
- fails.incrementAndGet(),
+ FAILS.incrementAndGet(),
Thread.currentThread().getName(),
SystemUtils.JAVA_VENDOR,
SystemUtils.JAVA_VM_VERSION,
localeStr, tzDisplay);
+ // @formatter:on
assumeTrue(false, localeStr);
continue;
}
// Hack End
- fail(String.format("%s: with locale = %s, zIndex = %,d, tzDisplay = '%s', parser = '%s'", e,
- localeStr, zIndex, tzDisplay, parser), e);
+ fail(String.format("%s: with locale = %s, zIndex = %,d, tzDisplay = '%s', parser = '%s'", e, localeStr, zIndex, tzDisplay, parser), e);
}
}
}
@@ -216,26 +240,8 @@ private void testTimeZoneStrategyPattern_TimeZone_getAvailableIDs(final Locale l
Objects.requireNonNull(locale, "locale");
assumeFalse(LocaleUtils.isLanguageUndetermined(locale), () -> toFailureMessage(locale, null, null));
assumeTrue(LocaleUtils.isAvailableLocale(locale), () -> toFailureMessage(locale, null, null));
- for (final String id : TimeZones.SORTED_AVAILABLE_IDS) {
- final TimeZone timeZone = TimeZones.getTimeZone(id);
- final String displayName = timeZone.getDisplayName(locale);
- final FastDateParser parser = new FastDateParser("z", timeZone, locale);
- try {
- parser.parse(displayName);
- } catch (final ParseException e) {
- final StringBuilder sb = new StringBuilder("chars: [");
- displayName.chars().forEach(c -> sb.append(c).append(", "));
- sb.append("], code points: [");
- displayName.codePoints().forEach(c -> sb.append(c).append(", "));
- sb.append("]");
- if (displayName.contains("\uFFFD")) {
- System.err.printf("TimeZone ID %s displayName contains Unicode character 'REPLACEMENT CHARACTER' (U+FFFD) in '%s'%n", id, displayName);
- } else {
- // Missing "Zulu" or something else in broken JDK's GH builds?
- fail(String.format("displayName: '%s' for id: '%s', %s, exception: %s, %s, parser = %s", displayName, id, sb.toString(), e,
- toFailureMessage(locale, null, timeZone), parser.toStringAll()));
- }
- }
+ for (final String timeZoneId : TimeZones.SORTED_AVAILABLE_IDS) {
+ testTimeZoneStrategyPattern(locale, timeZoneId);
}
}
diff --git a/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTimeZonesTest.java b/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTimeZonesTest.java
index 8dd3e9f11..58b2c39cc 100644
--- a/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTimeZonesTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTimeZonesTest.java
@@ -31,15 +31,17 @@ class FastDatePrinterTimeZonesTest extends AbstractLangTest {
private static final String PATTERN = "h:mma z";
- public static Stream<TimeZone> data() {
+ /*
+ * A @MethodSource.
+ */
+ static Stream<TimeZone> getTimeZonesSorted() {
return Stream.of(TimeZones.SORTED_AVAILABLE_IDS).map(TimeZones::getTimeZone);
}
@ParameterizedTest
- @MethodSource("data")
+ @MethodSource("getTimeZonesSorted")
void testCalendarTimezoneRespected(final TimeZone timeZone) {
final Calendar cal = Calendar.getInstance(timeZone);
-
final SimpleDateFormat sdf = new SimpleDateFormat(PATTERN);
sdf.setTimeZone(timeZone);
final String expectedValue = sdf.format(cal.getTime());