Skip to content

Add test coverage for negative-day adjustment in DurationFormatUtils#1596

Merged
garydgregory merged 1 commit intoapache:masterfrom
nine0703:add-negative-days-test
Feb 13, 2026
Merged

Add test coverage for negative-day adjustment in DurationFormatUtils#1596
garydgregory merged 1 commit intoapache:masterfrom
nine0703:add-negative-days-test

Conversation

@nine0703
Copy link
Contributor

@nine0703 nine0703 commented Feb 13, 2026

Adds unit tests covering month-boundary and leap-year cases that trigger the internal negative-days borrowing logic in DurationFormatUtils.formatPeriod.

These tests improve coverage for scenarios previously noted by a TODO comment regarding missing JaCoCo coverage. The obsolete TODO comment has been removed since the relevant paths are now exercised by tests.

  • Read the contribution guidelines (CONTRIBUTING.md).
  • Read the ASF Generative Tooling Guidance.
  • Run a successful build using the default Maven goal (mvn).
  • Write unit tests that match the behavioral coverage improvement.
  • Write a pull request description explaining what and why.

AI usage disclosure:
Yes. ChatGPT (OpenAI) was used to discuss testing strategy and help draft the test cases and PR description. All code and tests were reviewed and validated manually before submission.

Copy link
Member

@raboof raboof left a comment

Choose a reason for hiding this comment

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

I think this is valuable test coverage. Two small comments.

Comment on lines 476 to 479
/** Covers negative-day borrowing across month boundary */
@Test
void testFormatPeriodISONegativeDaysBorrowAcrossMonth() {
final TimeZone tz = TimeZones.getTimeZone("GMT-3");
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a huge fan of having "negative borrowed days" so front-and-center in the test name, as that whole concept is part of the implementation details rather than part of the more abstract 'desired functionality'. I think I would prefer something like testFormatPeriodISOAcrossMonths for the test name, and only mentioning "this test covers the code path where the internal 'borrowed days' go negative" only in a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, that makes sense. I’ve renamed the test and moved the implementation detail to a comment. Thanks for the suggestion!


final Calendar start = Calendar.getInstance(tz);
start.set(2020, Calendar.JANUARY, 31, 0, 0, 0);
start.set(Calendar.MILLISECOND, 0);
Copy link
Member

Choose a reason for hiding this comment

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

I think these are not needed, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the test to use clear() before setting the date to avoid leftover time fields. Thanks for the suggestion.

Adds unit tests covering month-boundary and leap-year cases that
trigger the internal negative-days borrowing logic in
DurationFormatUtils.formatPeriod.

Removes obsolete TODO about missing JaCoCo coverage.
@nine0703 nine0703 force-pushed the add-negative-days-test branch from f68b952 to 269ecf9 Compare February 13, 2026 09:39
Copy link
Member

@raboof raboof left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@nine0703
Copy link
Contributor Author

LGTM, thanks!

Thanks a lot!

@garydgregory garydgregory merged commit da6d337 into apache:master Feb 13, 2026
20 checks passed
@garydgregory
Copy link
Member

@nine0703
Thank you for your PR, merged.

garydgregory added a commit that referenced this pull request Feb 13, 2026
DurationFormatUtils #1596

- Sort new methods
- Remove empty lines, use longer lines
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.

3 participants

Comments