From 4b9eb65f087806cf8240a34bd4dc9756bf274575 Mon Sep 17 00:00:00 2001 From: manosbatsis Date: Fri, 27 Oct 2023 11:31:16 +0300 Subject: [PATCH] fix(finance): fix #767 --- src/main/java/com/github/javafaker/Finance.java | 10 ++++++---- .../java/com/github/javafaker/FinanceTest.java | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/github/javafaker/Finance.java b/src/main/java/com/github/javafaker/Finance.java index c4eeddf54..554dc42f5 100644 --- a/src/main/java/com/github/javafaker/Finance.java +++ b/src/main/java/com/github/javafaker/Finance.java @@ -3,10 +3,7 @@ import org.apache.commons.lang3.StringUtils; import java.math.BigInteger; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class Finance { private final Faker faker; @@ -66,6 +63,11 @@ public String iban(String countryCode) { return countryCode + checkSum + basicBankAccountNumber; } + /** Get the set of country codes supported for IBAN generation */ + public Set ibanCountryCodes() { + return countryCodeToBasicBankAccountNumberPattern.keySet(); + } + private CreditCardType randomCreditCardType() { return CreditCardType.values()[this.faker.random().nextInt(CreditCardType.values().length)]; } diff --git a/src/test/java/com/github/javafaker/FinanceTest.java b/src/test/java/com/github/javafaker/FinanceTest.java index 3eca2208e..1a1317259 100644 --- a/src/test/java/com/github/javafaker/FinanceTest.java +++ b/src/test/java/com/github/javafaker/FinanceTest.java @@ -3,8 +3,10 @@ import org.apache.commons.validator.routines.checkdigit.LuhnCheckDigit; import org.junit.Test; +import java.util.Set; + import static com.github.javafaker.matchers.MatchesRegularExpression.matchesRegularExpression; -import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.*; import static org.junit.Assert.assertThat; public class FinanceTest extends AbstractFakerTest { @@ -37,6 +39,19 @@ public void ibanWithCountryCode() { assertThat(faker.finance().iban("DE"), matchesRegularExpression("DE\\d{20}")); } + @Test + public void ibanWithAllCountryCodes() { + Set ibanCountryCodes = faker.finance().ibanCountryCodes(); + for (String countryCode : ibanCountryCodes) { + assertThat( + "IBAN for " + countryCode + " must not be null or empty", + faker.finance().iban(countryCode), + not(isEmptyString()) + ); + } + assertThat(faker.finance().iban("DE"), matchesRegularExpression("DE\\d{20}")); + } + @Test public void creditCardWithType() { for(CreditCardType type : CreditCardType.values()) {