GeezerVison is showing github.com — Simplify AssertJ `==` and `!=` assertions into one recipe by timtebeek · Pull Request #1067 · openrewrite/rewrite-testing-frameworks
Conversation
timtebeek
commented
Jul 26, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Error Prone Support 0.31.0 guards AssertJObjectRules.AssertThatIs{,Not}SameAs with Error Prone's @NotMatches and deletes AssertThatIs{,Not}Null, and RefasterTemplateProcessor skips annotated rules entirely, so those four generated recipes vanish once we bump — taking the correct isSameAs coverage with them.
-
This replaces them with SimplifyAssertJEqualityAssertion, which dispatches on what == actually compares: the null literal to isNull, a primitive value comparison to isEqualTo, and two reference operands to isSameAs, with !=, .isFalse(), ! and .isEqualTo(true|false) each inverting the assertion. The Refaster rules were unsound because generation erases T to any(java.lang.Object): assertThat(a != b).isTrue() on two longs became isNotSameAs, which holds for any two equal values outside the Long cache, so the assertion stopped verifying anything (testng-team/testng#3278).
-
I first tried the intended org.openrewrite.java.template.@Matches approach, but a per-parameter Matcher<Expression> only sees one operand, so it cannot tell that assertThat((byte) 3).isNotEqualTo(3) binds to isEqualTo(Object) and passes vacuously (verified against assertj-core 3.27.3) — the imperative visitor checks the operand pair and bails out instead. This also subsumes SimplifyAssertJNullRelatedAssertion (AssertJ recipes should not change assertThat(null== a).isEqualTo(true) to assertThat(null).isSameAs(a) #868), which is deleted outright rather than aliased; that name shipped in 3.40.0, so anyone referencing it directly will need to switch to the new one.
Verified by simulating the bump — removing Picnic's whole AssertJObjectRulesRecipes leaves only a hasSameHashCodeAs failure, from a rule that survives 0.31.0 — and the Assertj aggregate still converges in a single rewriteRun. Note recipes.csv also picks up two counts that were already stale on main.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Error Prone Support 0.31.0 guards `AssertJObjectRules.AssertThatIs{,Not}SameAs`
with Error Prone's `@NotMatches` and deletes `AssertThatIs{,Not}Null`, so those
four generated recipes disappear once we bump. Replace that coverage with
`SimplifyAssertJEqualityAssertion`, which dispatches on what `==` actually
compares: the `null` literal to `isNull`, a primitive value comparison to
`isEqualTo`, and two reference operands to `isSameAs`.
The Refaster rules were unsound because generation erases `T` to
`any(java.lang.Object)`: `assertThat(a != b).isTrue()` on two `long`s became
`isNotSameAs`, which holds for any two equal values outside the `Long` cache,
so the assertion stopped verifying anything (testng-team/testng#3278). A
per-parameter matcher cannot see both operands, so it also cannot tell that
`assertThat((byte) 3).isNotEqualTo(3)` binds to `isEqualTo(Object)` and passes
vacuously; the imperative visitor checks the operand pair and bails out instead.
This subsumes `SimplifyAssertJNullRelatedAssertion`, whose recipe name is kept
resolving by a declarative alias.
The comment credited firing before the Refaster rules "that have already
produced an `isSameAs`", but those are `AssertJObjectRules.AssertThatIs{,Not}SameAs`,
which 0.31.0 removes -- so that half describes a hazard this change eliminates.
`AssertJBooleanRulesRecipes` is unaffected by the bump and is the rule that
actually matters here: it normalizes `isEqualTo(true|false)` to
`isTrue()`/`isFalse()`, but only later in the same cycle, once we have visited.
Pin the convergence this buys with two aggregate cases, including
`assertThat(null == x).isEqualTo(true)`.
Remove the declarative recipe that kept the SimplifyAssertJNullRelatedAssertion
name resolving; the rename stands on its own.
Trim assertj.yml from 47 comment lines to 28. The "we override the picnic
recipes" rationale was duplicated verbatim above both `type:` and
`preconditions:`; keep one copy, next to the recipes it describes. The ten
section labels (`# String Assertions`, `# File Assertions`, ...) restated the
`requiredType` on the very next line. What is left is ordering constraints and
their issue links.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Jul 27, 2026
mergify Bot
added a commit
to robfrank/linklift
that referenced
this pull request
Aug 4, 2026
Uh oh!
There was an error while loading. Please reload this page.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|