Preserve comments before collapsed AssertJ chains - #1096
Draft
martinfrancois wants to merge 1 commit into
Draft
Conversation
4 tasks
martinfrancois
force-pushed
the
agent/repro-collapse-assertj-comment-boundary
branch
from
August 15, 2026 23:11
11c96d2 to
3f4d043
Compare
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.
Suggested review order: 25 of 52 (Score: 5)
Review first: openrewrite/rewrite-static-analysis#980
What's changed?
Keeps the first assertion's prefix and comments on the collapsed
assertThat(...)call. Comments between later compatible assertions remain attached to their corresponding chained assertion.What's your motivation?
Recipe:
org.openrewrite.java.testing.assertj.CollapseConsecutiveAssertThatStatements.I found this by running
org.openrewrite.java.testing.assertj.CollapseConsecutiveAssertThatStatementsfromorg.openrewrite.recipe:rewrite-testing-frameworks:3.42.0onTestConventionTest.javain Symphony-Trello ata8013f27. I reproduced the same result with the latest released recipe artifact,org.openrewrite.recipe:rewrite-testing-frameworks:3.44.0.Before
Actual after the recipe
Expected after the recipe
The
// thencomment marks the start of the assertion phase. Moving it inside the fluent chain attaches it to the first.contains(...)call instead of the assertion block.Confirmed real-world execution
TestConventionTest.javaata8013f27.martinfrancois/symphony-trello@a8013f27.Anything in particular you'd like reviewers to focus on?
Please review comment ownership at the collapse boundary and the behavior when later assertions also have comments.
Have you considered any alternatives or workarounds?
Leaving all commented sequences uncollapsed would avoid movement but would reject safe cases where only later assertion comments need to remain on their calls.
Any additional context
Pre-existing tests changed:
CollapseConsecutiveAssertThatStatementsTest.java.collapseIfMultipleConsecutiveAssertThatPresent(updated),CollapseConsecutiveAssertThatStatementsTest.java.preserveCommentsWhenCollapsingAssertions(updated).martinfrancois/symphony-trello@a8013f27org.openrewrite.recipe:rewrite-testing-frameworks:3.42.0org.openrewrite.recipe:rewrite-testing-frameworks:3.44.0openrewrite/rewrite-testing-frameworks@23a04efcCollapseConsecutiveAssertThatStatementsTest.preservesSectionCommentBeforeCollapsedChainThis change was prepared with AI assistance. I reviewed the target execution evidence, implementation, tests, and contribution text.
Checklist
./gradlew buildlocally, and committed any resulting changes torecipes.csv