Skip to content

Commit

Permalink
Warn if IBAN registry is old
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbASF committed Dec 29, 2024
1 parent 575a10a commit d7b6e81
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -329,6 +335,7 @@ static Collection<Arguments> ibanRegistrySourceExamples() throws Exception {

CSVRecord country = null;
CSVRecord electronicExample = null;
CSVRecord lastUpdateDate = null;

try (CSVParser p = new CSVParser(rdr, format)) {
for (final CSVRecord o : p) {
Expand All @@ -340,20 +347,38 @@ static Collection<Arguments> ibanRegistrySourceExamples() throws Exception {
case "IBAN electronic format example":
electronicExample = o;
break;
case "Last update date":
lastUpdateDate = o;
break;
default:
break;
}
}
}

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;
}

Expand Down

0 comments on commit d7b6e81

Please sign in to comment.