MCPcopy Create free account
hub / github.com/DiUS/java-faker / creditCard

Method creditCard

src/main/java/com/github/javafaker/Finance.java:22–43  ·  view source on GitHub ↗
(CreditCardType creditCardType)

Source from the content-addressed store, hash-verified

20 createCountryCodeToBasicBankAccountNumberPatternMap();
21
22 public String creditCard(CreditCardType creditCardType) {
23 final String key = String.format("finance.credit_card.%s", creditCardType.toString().toLowerCase());
24 String value = faker.fakeValuesService().resolve(key, this, faker);
25 final String template = faker.numerify(value);
26
27 String[] split = template.replaceAll("[^0-9]", "").split("");
28 List<Integer> reversedAsInt = new ArrayList<Integer>();
29 for (int i = 0; i < split.length; i++) {
30 final String current = split[split.length - 1 - i];
31 if (!current.isEmpty()) {
32 reversedAsInt.add(Integer.valueOf(current));
33 }
34 }
35 int luhnSum = 0;
36 int multiplier = 1;
37 for (Integer digit : reversedAsInt) {
38 multiplier = (multiplier == 2 ? 1 : 2);
39 luhnSum += sum(String.valueOf(digit * multiplier).split(""));
40 }
41 int luhnDigit = (10 - (luhnSum % 10)) % 10;
42 return template.replace('\\', ' ').replace('/', ' ').trim().replace('L', String.valueOf(luhnDigit).charAt(0));
43 }
44
45 public String creditCard() {
46 CreditCardType type = randomCreditCardType();

Callers

nothing calls this directly

Calls 7

sumMethod · 0.95
randomCreditCardTypeMethod · 0.95
toStringMethod · 0.80
fakeValuesServiceMethod · 0.80
addMethod · 0.80
resolveMethod · 0.45
numerifyMethod · 0.45

Tested by

no test coverage detected