Skip to content

Add CreditCard faker with comprehensive test data generation - #25

Merged
TheJavaGuy merged 1 commit into
masterfrom
creditcard-faker
Feb 9, 2026
Merged

TheJavaGuy merged 1 commit into
masterfrom
creditcard-faker

Conversation

@TheJavaGuy

Copy link
Copy Markdown
Owner

Summary

Introduces a new CreditCard faker that generates realistic credit card test data for e-commerce checkout testing, payment gateway integration, and PCI compliance scenarios.

Key features:

  • Card numbers with valid Luhn checksums for all major card types (Visa, Mastercard, Amex, Discover, Diners Club, JCB, etc.)
  • CVV codes (3 digits standard, 4 for American Express)
  • Expiration dates (both future and expired)
  • Cardholder names in uppercase format
  • Issuing bank names (Chase, Bank of America, Wells Fargo, etc.)
  • Masked card numbers for display (**** **** **** 1234)
  • Plain (no dashes) and formatted number outputs
  • Network name lookup

Implementation approach:

  • Delegates to existing Finance.creditCard() for Luhn validation
  • Provides dedicated API with expanded functionality beyond Finance methods
  • Follows existing project patterns and conventions
  • Registered in EnFile.java for YAML data loading

Files changed:

  • New CreditCard.java provider class (224 lines)
  • New credit_card.yml data file with card patterns and bank names
  • New CreditCardTest.java with 18 comprehensive tests
  • Updated Faker.java to register the provider
  • Updated EnFile.java to load YAML data
  • Added LEARNINGS.md documenting common mistakes for future contributors
  • Added CREDITCARD_FAKER_SPEC.md with full feature specification

Test plan

  • All 18 CreditCard tests pass
  • Full test suite passes (85,165 tests, 0 failures)
  • All generated card numbers pass Luhn validation
  • CVV codes are correct length per card type (3 or 4 digits)
  • Expiration dates are correctly formatted and in future
  • Expired dates are correctly in the past
  • Cardholder names are uppercase with space separator
  • Bank names are fetched from YAML data
  • Masked numbers follow correct format
  • Network names match card types

Example usage:

Faker faker = new Faker();

faker.creditCard().number()                    // "4532-1234-5678-9012"
faker.creditCard().number(CreditCardType.VISA) // "4111-2222-3333-4444"
faker.creditCard().cvv()                       // "123"
faker.creditCard().expirationDate()            // "03/27"
faker.creditCard().cardholderName()            // "JOHN SMITH"
faker.creditCard().bank()                      // "Chase"
faker.creditCard().maskedNumber()              // "**** **** **** 4532"

Introduces a new CreditCard faker that generates realistic credit card test data including:
- Card numbers with valid Luhn checksums for all major card types
- CVV codes (3 digits standard, 4 for Amex)
- Expiration dates (future and expired)
- Cardholder names in uppercase format
- Issuing bank names
- Masked card numbers for display
- Network name lookup

The implementation delegates to Finance.creditCard() for Luhn validation while
providing a dedicated API with expanded functionality beyond the existing
Finance methods.

All 18 tests pass. Includes specification documentation and learnings from
implementation mistakes to help future contributors.
@coveralls

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 21816642455

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.5%) to 96.506%

Files with Coverage Reduction New Missed Lines %
org/thejavaguy/javafaker/Commerce.java 1 92.86%
Totals Coverage Status
Change from base Build 21816009898: -0.5%
Covered Lines: 1812
Relevant Lines: 1857

💛 - Coveralls

@TheJavaGuy
TheJavaGuy merged commit f18be07 into master Feb 9, 2026
2 checks passed
@TheJavaGuy
TheJavaGuy deleted the creditcard-faker branch February 9, 2026 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants