You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2020/08/03 11:23:44 UTC

[commons-validator] branch master updated: systemPropertyVariables set too late in Surefire

This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-validator.git


The following commit(s) were added to refs/heads/master by this push:
     new dc618fb  systemPropertyVariables set too late in Surefire
dc618fb is described below

commit dc618fb1d11f1b14a1ccd249ce599be0dc98618b
Author: Sebb <se...@apache.org>
AuthorDate: Mon Aug 3 12:23:34 2020 +0100

    systemPropertyVariables set too late in Surefire
---
 pom.xml                                                  |  9 ++++++---
 .../commons/validator/routines/DateValidatorTest.java    | 16 ++++++++++++++++
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/pom.xml b/pom.xml
index 381303e..9b2d233 100644
--- a/pom.xml
+++ b/pom.xml
@@ -314,9 +314,12 @@
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-surefire-plugin</artifactId>
             <configuration>
-                <systemPropertyVariables>
-                    <java.locale.providers>COMPAT,CLDR</java.locale.providers>
-                </systemPropertyVariables>
+              <!--
+                systemPropertyVariables are set too late in Surefire
+                versions after 2.21.0 and before 3.0-M4 (but only on Windows!)
+                Use the command-line instead to ensure the property is set early enough
+              -->
+              <argLine>-Djava.locale.providers=COMPAT,SPI</argLine>
             </configuration>
           </plugin>
         </plugins>
diff --git a/src/test/java/org/apache/commons/validator/routines/DateValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/DateValidatorTest.java
index a17f6b0..43de6b2 100644
--- a/src/test/java/org/apache/commons/validator/routines/DateValidatorTest.java
+++ b/src/test/java/org/apache/commons/validator/routines/DateValidatorTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.validator.routines;
 
+import java.text.DateFormat;
 import java.util.Date;
 import java.util.Locale;
 import java.util.TimeZone;
@@ -49,6 +50,21 @@ public class DateValidatorTest extends AbstractCalendarValidatorTest {
     }
 
     /**
+     * Check that locale providers are set up correctly
+     * If not, the parse will fail
+     */
+    public void testLocaleProviders() throws Exception {
+        String localeProviders = System.getProperty("java.locale.providers");
+        if (localeProviders != null) { // may be null before Java 9
+            assertTrue("java.locale.providers must start with COMPAT", localeProviders.startsWith("COMPAT"));
+        }
+        String txt = "3/20/15 10:59:00 PM";  // This relies on the locale format prior to Java 9 to parse correctly
+        DateFormat dateformat= DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, Locale.US); 
+        dateformat.setTimeZone(TimeZone.getTimeZone("GMT"));
+        Date date = dateformat.parse(txt);
+        assertNotNull(date);
+    }
+    /**
      * Test DateValidator validate Methods
      */
     public void testDateValidatorMethods() {