Skip to content

Make Finance provider's UnionPay test more readable, especially on failure#1643

Merged
kingthorin merged 2 commits intodatafaker-net:mainfrom
Fishbowler:finance-test
Sep 5, 2025
Merged

Make Finance provider's UnionPay test more readable, especially on failure#1643
kingthorin merged 2 commits intodatafaker-net:mainfrom
Fishbowler:finance-test

Conversation

@Fishbowler
Copy link
Copy Markdown
Contributor

Makes a test in the Finance provider easier to read, and gives actionable feedback to the developer when it fails.

Addresses the comment left on the previous PR.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Sep 4, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.42%. Comparing base (7b78b84) to head (145ef25).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1643      +/-   ##
============================================
+ Coverage     92.38%   92.42%   +0.04%     
- Complexity     3382     3383       +1     
============================================
  Files           333      333              
  Lines          6681     6681              
  Branches        664      664              
============================================
+ Hits           6172     6175       +3     
+ Misses          349      347       -2     
+ Partials        160      159       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

assertThat(creditCard).hasSize(16);
assertThat(creditCard.startsWith("62") || creditCard.startsWith("64") || creditCard.startsWith("65") || creditCard.startsWith("81")).isTrue();
assertThat(creditCard.startsWith("62") || creditCard.startsWith("64") || creditCard.startsWith("65") || creditCard.startsWith("81"))
.as("UnionPay credit card number begins with the correct digits")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you concatenation credit card here so the actual generated value is visible?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fishbowler Something like this:

assertThat(creditCard.startsWith("62") || creditCard.startsWith("64") || creditCard.startsWith("65") || creditCard.startsWith("81"))
            .as(() -> "UnionPay credit card number begins with the correct digits, but received: " + creditCard)
            .isTrue();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh, that's even better! ❤️

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

org.opentest4j.AssertionFailedError: [Expected UnionPay credit card number to begin with the correct digits (62, 64, 65, 81), but received: 1221262098276253]
Expecting value to be true but was false
Expected :true
Actual :false

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to propose:

    @RepeatedTest(100)
    void unionpayCard() {
        List<String> startingDigits = List.of("62", "64", "65", "81");
        String creditCard = finance.creditCard(CreditCardType.UNIONPAY).replace("-", "");
        assertThat(creditCard).hasSize(16);
        assertThat(startingDigits.contains(creditCard.subString(0,2))
            .as(() -> "Expected UnionPay credit card number to begin with the correct digits " + startingDigits + ", but received: " + creditCard)
            .isTrue();
    }

@asolntsev asolntsev added this to the 2.4.5 milestone Sep 5, 2025
Copy link
Copy Markdown
Collaborator

@kingthorin kingthorin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@kingthorin kingthorin merged commit 6329317 into datafaker-net:main Sep 5, 2025
13 checks passed
@Fishbowler Fishbowler deleted the finance-test branch September 7, 2025 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants