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/12/19 23:49:16 UTC
(commons-lang) 08/08: Make test Java15BugFastDateParserTest more lenient on Java 26-ea
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 1c05980f3d73efa1829b00f54b87eae520e65097
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Dec 19 18:49:01 2025 -0500
Make test Java15BugFastDateParserTest more lenient on Java 26-ea
---
.../java/org/apache/commons/lang3/SystemUtils.java | 2 +-
.../org/apache/commons/lang3/LocaleProblems.java | 75 ++++++++++++++++++++++
.../commons/lang3/time/FastDateParserTest.java | 11 ++--
.../lang3/time/Java15BugFastDateParserTest.java | 23 ++++---
4 files changed, 98 insertions(+), 13 deletions(-)
diff --git a/src/main/java/org/apache/commons/lang3/SystemUtils.java b/src/main/java/org/apache/commons/lang3/SystemUtils.java
index 074384145..519a5560a 100644
--- a/src/main/java/org/apache/commons/lang3/SystemUtils.java
+++ b/src/main/java/org/apache/commons/lang3/SystemUtils.java
@@ -383,7 +383,7 @@ public class SystemUtils {
/**
* A constant for the Java version, may be null.
*/
- private static final JavaVersion JAVA_SPECIFICATION_VERSION_ENUM = JavaVersion.get(JAVA_SPECIFICATION_VERSION);
+ static final JavaVersion JAVA_SPECIFICATION_VERSION_ENUM = JavaVersion.get(JAVA_SPECIFICATION_VERSION);
/**
* A constant for the System Property {@code java.util.prefs.PreferencesFactory}. A class name.
diff --git a/src/test/java/org/apache/commons/lang3/LocaleProblems.java b/src/test/java/org/apache/commons/lang3/LocaleProblems.java
new file mode 100644
index 000000000..1c73211f5
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/LocaleProblems.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3;
+
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import java.text.ParseException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * Offers tests a way to skip problematic Locales with a JUnit assumption.
+ */
+public class LocaleProblems {
+
+ // needs a better name.
+ private static final Map<JavaVersion, List<String>> UNSUPPORTED_CAT_A;
+ static {
+ UNSUPPORTED_CAT_A = new HashMap<>();
+ // "cv_RU" is a problem on Java version: 26-beta, vendor: Eclipse Adoptium, runtime: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/26.0.0-ea.27.0.ea/x64
+ // Same for "cv"
+ UNSUPPORTED_CAT_A.put(JavaVersion.JAVA_26, Arrays.asList("cv", "cv_RU"));
+ }
+
+ // needs a better name.
+ private static final Map<JavaVersion, List<String>> UNSUPPORTED_CAT_B;
+ static {
+ UNSUPPORTED_CAT_B = new HashMap<>();
+ // "cv_RU_#Cyrl" is a problem on Java version: 26-beta, vendor: Eclipse Adoptium, runtime: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/26.0.0-ea.27.0.ea/x64
+ UNSUPPORTED_CAT_B.put(JavaVersion.JAVA_26, Arrays.asList("cv", "cv_RU", "cv_RU_#Cyrl"));
+ }
+
+ private static void assumeLocaleSupported(final Locale locale, final Map<JavaVersion, List<String>> unsupportedCatA, final ParseException e) {
+ final boolean supported = isSupported(locale, unsupportedCatA);
+ if (!supported) {
+ System.out.printf("Failing test assumption for locale '%s' on Java version %s.%n", locale, SystemUtils.JAVA_SPECIFICATION_VERSION_ENUM);
+ if (e != null) {
+ // Not the whole stack trace, just the exception message.
+ System.out.printf("\t%s%n", e);
+ }
+ }
+ assumeTrue(supported);
+ }
+
+ public static void assumeLocaleSupportedA(final Locale locale) {
+ assumeLocaleSupported(locale, UNSUPPORTED_CAT_A, null);
+ }
+
+ public static void assumeLocaleSupportedB(final Locale locale, final ParseException e) {
+ assumeLocaleSupported(locale, UNSUPPORTED_CAT_B, e);
+ }
+
+ private static boolean isSupported(final Locale locale, final Map<JavaVersion, List<String>> unsupported) {
+ final List<String> list = unsupported.get(SystemUtils.JAVA_SPECIFICATION_VERSION_ENUM);
+ return list == null || !list.contains(locale.toString());
+ }
+}
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 3c6ecf011..c8b9099a2 100644
--- a/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java
@@ -39,6 +39,7 @@
import java.util.stream.Stream;
import org.apache.commons.lang3.AbstractLangTest;
+import org.apache.commons.lang3.LocaleProblems;
import org.apache.commons.lang3.LocaleUtils;
import org.apache.commons.lang3.SerializationUtils;
import org.apache.commons.lang3.SystemUtils;
@@ -55,6 +56,7 @@
import org.junitpioneer.jupiter.ReadsDefaultTimeZone;
import org.junitpioneer.jupiter.cartesian.ArgumentSets;
import org.junitpioneer.jupiter.cartesian.CartesianTest;
+import org.opentest4j.AssertionFailedError;
/**
* Tests {@link org.apache.commons.lang3.time.FastDateParser}.
@@ -724,7 +726,7 @@ void testTzParses(final Locale locale) throws Exception {
}
private void validateSdfFormatFdpParseEquality(final String formatStr, final Locale locale, final TimeZone timeZone,
- final FastDateParser dateParser, final Date inDate, final int year, final Date csDate) throws ParseException {
+ final FastDateParser fastDateParser, final Date inDate, final int year, final Date csDate) throws ParseException {
final SimpleDateFormat sdf = new SimpleDateFormat(formatStr, locale);
sdf.setTimeZone(timeZone);
if (formatStr.equals(SHORT_FORMAT)) {
@@ -734,13 +736,14 @@ private void validateSdfFormatFdpParseEquality(final String formatStr, final Loc
// System.out.printf("[Java %s] Date: '%s' formatted with '%s' -> '%s'%n", SystemUtils.JAVA_RUNTIME_VERSION, inDate,
// formatStr, fmt);
try {
- final Date out = dateParser.parse(fmt);
+ final Date out = fastDateParser.parse(fmt);
assertEquals(inDate, out, "format: '" + formatStr + "', locale: '" + locale + "', time zone: '"
+ timeZone.getID() + "', year: " + year + ", parse: '" + fmt);
- } catch (final ParseException pe) {
+ } catch (final ParseException e) {
+ LocaleProblems.assumeLocaleSupportedB(locale, e);
if (year >= 1868 || !locale.getCountry().equals("JP")) {
// LANG-978
- throw pe;
+ throw new AssertionFailedError("locale " + locale, e);
}
}
}
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 ce4986d54..f89860be2 100644
--- a/src/test/java/org/apache/commons/lang3/time/Java15BugFastDateParserTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/Java15BugFastDateParserTest.java
@@ -25,6 +25,7 @@
import java.util.TimeZone;
import org.apache.commons.lang3.AbstractLangTest;
+import org.apache.commons.lang3.LocaleProblems;
import org.apache.commons.lang3.LocaleUtils;
import org.apache.commons.lang3.function.TriFunction;
import org.junit.jupiter.api.Test;
@@ -65,6 +66,19 @@ void testJava15BuggyLocaleTestAll(final Locale locale) throws ParseException {
testSingleLocale(locale);
}
+ private void testLocale(final TriFunction<String, TimeZone, Locale, DateParser> dbProvider, final String format, final boolean eraBC, final Calendar cal,
+ final Locale locale) {
+ LocaleProblems.assumeLocaleSupportedA(locale);
+ // ja_JP_JP cannot handle dates before 1868 properly
+ if (eraBC && locale.equals(FastDateParser.JAPANESE_IMPERIAL)) {
+ return;
+ }
+ 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);
+ }
+
private void testLocales(final TriFunction<String, TimeZone, Locale, DateParser> dbProvider, final String format,
final boolean eraBC) throws Exception {
final Calendar cal = Calendar.getInstance(TimeZones.GMT);
@@ -74,14 +88,7 @@ private void testLocales(final TriFunction<String, TimeZone, Locale, DateParser>
cal.set(Calendar.ERA, GregorianCalendar.BC);
}
for (final Locale locale : LocaleUtils.availableLocaleList()) {
- // ja_JP_JP cannot handle dates before 1868 properly
- if (eraBC && locale.equals(FastDateParser.JAPANESE_IMPERIAL)) {
- continue;
- }
- 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);
+ testLocale(dbProvider, format, eraBC, cal, locale);
}
}