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 d7b6e81d Warn if IBAN registry is old
d7b6e81d is described below

commit d7b6e81da5d31604e17ec3750ac5add42ebc889a
Author: Sebb <s...@apache.org>
AuthorDate: Sun Dec 29 15:49:46 2024 +0000

    Warn if IBAN registry is old
---
 .../validator/routines/IBANValidatorTest.java      | 27 +++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git 
a/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java 
b/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java
index 2490277d..5abf3d97 100644
--- a/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java
+++ b/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java
@@ -32,7 +32,9 @@ import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Date;
 import java.util.List;
+import java.util.Locale;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
@@ -76,6 +78,10 @@ public class IBANValidatorTest {
      */
     private static final String IBAN_REGISTRY = "iban_registry_v99.txt";
     private static final Charset IBAN_REGISTRY_CHARSET = 
Charset.forName("windows-1252");
+    private static final int MS_PER_DAY = 1000*60*60*24;
+    private static final long MAX_AGE_DAYS = 180; // how old registry can get 
(approx 6 months)
+    
+
 
     // It's not clear whether IBANs can contain lower case characters
     // so we test for both where possible
@@ -329,6 +335,7 @@ public class IBANValidatorTest {
 
         CSVRecord country = null;
         CSVRecord electronicExample = null;
+        CSVRecord lastUpdateDate = null;
 
         try (CSVParser p = new CSVParser(rdr, format)) {
             for (final CSVRecord o : p) {
@@ -340,6 +347,9 @@ public class IBANValidatorTest {
                     case "IBAN electronic format example":
                         electronicExample = o;
                         break;
+                    case "Last update date":
+                        lastUpdateDate = o;
+                        break;
                     default:
                         break;
                 }
@@ -347,13 +357,28 @@ public class IBANValidatorTest {
         }
 
         assertNotNull(country);
+        final int arraySize = country.size();
         assertNotNull(electronicExample);
+        assertEquals(arraySize, electronicExample.size());
+        assertNotNull(lastUpdateDate);
+        assertEquals(arraySize, lastUpdateDate.size());
 
         final Collection<Arguments> result = new ArrayList<>();
+        Date lastDate = new Date(0);
+        String lastUpdated = null;
         for (int i = 1; i < country.size(); i++) {
             result.add(Arguments.of(country.get(i), electronicExample.get(i)));
+            final String mmyy = lastUpdateDate.get(i);
+            final Date dt = 
DateValidator.getInstance().validate(mmyy,"MMM-yy",Locale.ROOT);
+            if (dt.after(lastDate)) {
+                lastDate = dt;
+                lastUpdated = mmyy;
+            }
+        }
+        final long age = (new Date().getTime() - 
lastDate.getTime())/MS_PER_DAY;
+        if (age > MAX_AGE_DAYS) { // not necessarily a failure
+            System.out.println("WARNING: expected recent last update date, but 
found: " + lastUpdated);
         }
-
         return result;
     }
 

Reply via email to