Skip to content

Migrate deprecated AssertionsForClassTypes/InterfaceTypes to Assertions#1010

Merged
timtebeek merged 1 commit into
mainfrom
tim/assertj-pr-recipe-automation
Jun 1, 2026
Merged

Migrate deprecated AssertionsForClassTypes/InterfaceTypes to Assertions#1010
timtebeek merged 1 commit into
mainfrom
tim/assertj-pr-recipe-automation

Conversation

@timtebeek
Copy link
Copy Markdown
Member

@timtebeek timtebeek commented May 30, 2026

  • AssertJ deprecated AssertionsForClassTypes and AssertionsForInterfaceTypes in favor of the unified Assertions entry point (assertj/assertj#4268), so this adds MigrateAssertionsForClassAndInterfaceTypes to retarget all static methods of both classes to Assertions (enabling the long-disabled handling from Code does not compile after AssertionsForClassTypes import is replaced by Assertions #664). The hazard is the generic AssertionsForClassTypes.assertThat(T) (returns ObjectAssert): since Assertions also has more-specific overloads, a naive swap would re-bind an Iterable/Map/Comparable/... argument to e.g. IterableAssert and stop compiling. The new type-aware MigrateAssertionsForClassTypes recipe routes only those colliding arguments to assertThatObject, leaving plain objects and typed overloads on assertThat. The recipe is wired into the top-level Assertj recipe, the superseded @Disabled StaticImportsTest case is replaced by a dedicated test class, and recipes.csv is updated. Everything is verified against AssertJ 3.27 (all migration targets already exist), so it works today even though the upstream PR is still a draft targeting 3.28.0.

  • Fixes Code does not compile after AssertionsForClassTypes import is replaced by Assertions #664

…tions

AssertJ deprecated `AssertionsForClassTypes` and `AssertionsForInterfaceTypes`
in favor of the unified `Assertions` entry point (assertj/assertj#4268).

This adds `MigrateAssertionsForClassAndInterfaceTypes`, which retargets all
static methods of both classes to `Assertions`. The generic
`AssertionsForClassTypes.assertThat(T)` returns an `ObjectAssert`, but the
unified `Assertions` also offers more specific overloads, so a naive swap would
re-bind an `Iterable`/`Map`/`Comparable`/... argument to e.g. `IterableAssert`
and stop compiling. The new type-aware `MigrateAssertionsForClassTypes` recipe
routes only those colliding arguments to `assertThatObject`, resolving #664.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite May 30, 2026
@timtebeek timtebeek added recipe Recipe request assertj labels May 30, 2026
@timtebeek timtebeek marked this pull request as ready for review May 30, 2026 14:24
@timtebeek timtebeek moved this from In Progress to Ready to Review in OpenRewrite May 30, 2026
@timtebeek timtebeek merged commit 4d31fbb into main Jun 1, 2026
1 check passed
@timtebeek timtebeek deleted the tim/assertj-pr-recipe-automation branch June 1, 2026 08:20
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

assertj recipe Recipe request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Code does not compile after AssertionsForClassTypes import is replaced by Assertions

1 participant