Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #767: NPE for IBAN with country code #768

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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