Skip to content

Commit

Permalink
fix(finance): fix DiUS#767
Browse files Browse the repository at this point in the history
  • Loading branch information
manosbatsis committed Oct 27, 2023
1 parent a8b8ff0 commit 4b9eb65
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/main/java/com/github/javafaker/Finance.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> ibanCountryCodes() {
return countryCodeToBasicBankAccountNumberPattern.keySet();
}

private CreditCardType randomCreditCardType() {
return CreditCardType.values()[this.faker.random().nextInt(CreditCardType.values().length)];
}
Expand Down
17 changes: 16 additions & 1 deletion src/test/java/com/github/javafaker/FinanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -37,6 +39,19 @@ public void ibanWithCountryCode() {
assertThat(faker.finance().iban("DE"), matchesRegularExpression("DE\\d{20}"));
}

@Test
public void ibanWithAllCountryCodes() {
Set<String> 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()) {
Expand Down

0 comments on commit 4b9eb65

Please sign in to comment.