Backport: Add withFormatter() for Duration assertions#4024
Merged
Conversation
withFormatter() for Duration assertions (backport)
798c34d to
7d89a07
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds a withFormatter() method to Duration assertions, allowing developers to customize how Duration objects are formatted in assertion failure messages. This is a backport addressing issue #4017.
- Introduces
withFormatter(Function<Duration, String>)method toAbstractDurationAssert - Changes visibility of
StandardRepresentation.toStringOf(Duration)fromprivatetoprotectedto enable custom formatting - Adds comprehensive test coverage for the new formatter functionality
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| AbstractDurationAssert.java | Adds the withFormatter() method with full JavaDoc documentation and validation |
| StandardRepresentation.java | Changes visibility of toStringOf(Duration) from private to protected to support custom representations |
| DurationAssert_withFormatter_Test.java | Adds tests for null validation and formatter functionality |
| DurationAssert_isCloseTo_Test.java | Fixes typo in test annotation: "close" to "be close" |
Comments suppressed due to low confidence (3)
assertj-core/src/main/java/org/assertj/core/api/AbstractDurationAssert.java:1
- Syntax error: semicolon after
.withFormatter(formatter)on line 321 should be removed. The correct syntax should chain the method calls without an intermediate semicolon.
/*
assertj-core/src/main/java/org/assertj/core/api/AbstractDurationAssert.java:1
- The JavaDoc example is incomplete and misleading. The comment states 'this assertion succeeds' but the code has a placeholder
.inhasDays(.)on line 328 and a semicolon after line 327. This should either show a complete, valid example with an actual value (e.g.,.hasDays(3)) or be removed if it doesn't add value beyond the first example.
/*
assertj-core/src/main/java/org/assertj/core/presentation/StandardRepresentation.java:211
- Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
Method StandardRepresentation.toStringOf(..) could be confused with overloaded method toStringOf, since dispatch depends on static types.
public String toStringOf(Object object) {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
scordio
reviewed
Nov 22, 2025
…onAssert.java Co-authored-by: Stefano Cordio <stefano.cordio@gmail.com>
…onAssert.java Co-authored-by: Stefano Cordio <stefano.cordio@gmail.com>
scordio
approved these changes
Nov 22, 2025
withFormatter() for Duration assertions (backport)withFormatter() for Duration assertions
Member
|
Congratulations on your first contribution, @dajoropo! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.