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-beanutils.git


The following commit(s) were added to refs/heads/master by this push:
     new 0b200f06 Fix sql time and timestamp locale tests on java 20+ (#410)
0b200f06 is described below

commit 0b200f0651024c5ea03f7406da792a716bbfe652
Author: Dexter.k <[email protected]>
AuthorDate: Thu Jul 2 19:34:03 2026 +0000

    Fix sql time and timestamp locale tests on java 20+ (#410)
    
    The US SHORT time format switched the AM/PM separator to a narrow
    no-break space (U+202F) in CLDR (JDK 20+), so the locale converter
    parses that separator while the tests hard-coded a regular space.
    Derive the separator from the JVM's own format so the tests pass on
    both old and new JDKs.
    
    Signed-off-by: Naveed Khan <[email protected]>
---
 .../beanutils2/sql/converters/SqlTimeConverterTest.java | 15 +++++++++++++--
 .../sql/converters/SqlTimestampConverterTest.java       | 17 +++++++++++++----
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git 
a/src/test/java/org/apache/commons/beanutils2/sql/converters/SqlTimeConverterTest.java
 
b/src/test/java/org/apache/commons/beanutils2/sql/converters/SqlTimeConverterTest.java
index 95498cfc..ca7e7854 100644
--- 
a/src/test/java/org/apache/commons/beanutils2/sql/converters/SqlTimeConverterTest.java
+++ 
b/src/test/java/org/apache/commons/beanutils2/sql/converters/SqlTimeConverterTest.java
@@ -18,7 +18,9 @@
 package org.apache.commons.beanutils2.sql.converters;
 
 import java.sql.Time;
+import java.text.DateFormat;
 import java.util.Calendar;
+import java.util.Date;
 import java.util.Locale;
 
 import org.apache.commons.beanutils2.converters.AbstractDateConverterTest;
@@ -29,6 +31,15 @@ import org.junit.jupiter.api.Test;
  */
 class SqlTimeConverterTest extends AbstractDateConverterTest<Time> {
 
+    /**
+     * Gets the separator that precedes the AM/PM field in the US SHORT time 
format. Java 20 and up (CLDR) use a narrow no-break space (U+202F) here,
+     * earlier versions use a regular space.
+     */
+    private static String amPmSeparator() {
+        final String formatted = DateFormat.getTimeInstance(DateFormat.SHORT, 
Locale.US).format(new Date());
+        return formatted.contains("\u202f") ? "\u202f" : " ";
+    }
+
     /**
      * Gets the expected type
      *
@@ -89,14 +100,14 @@ class SqlTimeConverterTest extends 
AbstractDateConverterTest<Time> {
         final Locale defaultLocale = Locale.getDefault();
         Locale.setDefault(Locale.US);
 
-        final String pattern = "h:mm a"; // SHORT style time format for US 
Locale
+        final String pattern = "h:mm" + amPmSeparator() + "a"; // SHORT style 
time format for US Locale
 
         // Create & Configure the Converter
         final SqlTimeConverter converter = makeConverter();
         converter.setUseLocaleFormat(true);
 
         // Valid String --> Type Conversion
-        final String testString = "3:06 pm";
+        final String testString = "3:06" + amPmSeparator() + "pm";
         final Object expected = toType(testString, pattern, null);
         validConversion(converter, expected, testString);
 
diff --git 
a/src/test/java/org/apache/commons/beanutils2/sql/converters/SqlTimestampConverterTest.java
 
b/src/test/java/org/apache/commons/beanutils2/sql/converters/SqlTimestampConverterTest.java
index 6aaa9512..c8247263 100644
--- 
a/src/test/java/org/apache/commons/beanutils2/sql/converters/SqlTimestampConverterTest.java
+++ 
b/src/test/java/org/apache/commons/beanutils2/sql/converters/SqlTimestampConverterTest.java
@@ -31,6 +31,15 @@ import org.junit.jupiter.api.Test;
  */
 class SqlTimestampConverterTest extends AbstractDateConverterTest<Timestamp> {
 
+    /**
+     * Gets the separator that precedes the AM/PM field in the US SHORT time 
format. Java 20 and up (CLDR) use a narrow no-break space (U+202F) here,
+     * earlier versions use a regular space.
+     */
+    private static String amPmSeparator() {
+        final String formatted = DateFormat.getTimeInstance(DateFormat.SHORT, 
Locale.US).format(new Date());
+        return formatted.contains("\u202f") ? "\u202f" : " ";
+    }
+
     /**
      * Gets the expected type
      *
@@ -108,12 +117,12 @@ class SqlTimestampConverterTest extends 
AbstractDateConverterTest<Timestamp> {
         String pattern; // SHORT style Date & Time format for US Locale
         String testString;
         if (isUSFormatWithComma()) {
-            pattern = "M/d/yy, h:mm a";
-            testString = "3/21/06, 3:06 PM";
+            pattern = "M/d/yy, h:mm" + amPmSeparator() + "a";
+            testString = "3/21/06, 3:06" + amPmSeparator() + "PM";
         } else {
             // More regular pattern for Java 8 and earlier
-            pattern = "M/d/yy h:mm a";
-            testString = "3/21/06 3:06 PM";
+            pattern = "M/d/yy h:mm" + amPmSeparator() + "a";
+            testString = "3/21/06 3:06" + amPmSeparator() + "PM";
         }
 
         // Valid String --> Type Conversion

Reply via email to