Skip to content

Decompose assertThat(a && b).isTrue() into separate assertions#1042

Merged
timtebeek merged 7 commits into
mainfrom
tim/resolve-issue-387
Jun 20, 2026
Merged

Decompose assertThat(a && b).isTrue() into separate assertions#1042
timtebeek merged 7 commits into
mainfrom
tim/resolve-issue-387

Conversation

@timtebeek

@timtebeek timtebeek commented Jun 20, 2026

Copy link
Copy Markdown
Member
  • Resolves When migrating from JUnit to AssertJ, rely on context to provide better assertions #387 by adding DecomposeConjunctionAssertion, which splits assertThat(a && b).isTrue() into one assertThat(...).isTrue() statement per conjunct (recursively flattening nested &&), so each condition is asserted and reported on its own. This lets the existing dedicated-assertion recipes simplify each conjunct (e.g. isNotNull(), isGreaterThan(...)) and CollapseConsecutiveAssertThatStatements fuse same-subject results back into a single chain. isFalse() is deliberately left alone (negating a conjunction is not equivalent to negating each conjunct), and chains carrying .as()/.describedAs() descriptions are skipped. The recipe is registered first in the Assertj aggregate so its output flows through the rest of the pipeline. Covered by unit tests plus end-to-end tests in AssertJBestPracticesTest showing decomposition, the method-call side-effect-safe case, and collapse into a chain.

@timtebeek timtebeek merged commit e471570 into main Jun 20, 2026
@timtebeek timtebeek deleted the tim/resolve-issue-387 branch June 20, 2026 15:45
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

When migrating from JUnit to AssertJ, rely on context to provide better assertions

1 participant