Migrate TestNG Assertion (instance) to AssertJ#1064
Merged
timtebeek merged 8 commits intoJul 24, 2026
Merged
Conversation
juherr
force-pushed
the
juherr/migrate-testng-assertion-to-assertj
branch
from
July 24, 2026 11:05
3f61c49 to
c9ec528
Compare
juherr
force-pushed
the
juherr/migrate-testng-assertion-to-assertj
branch
from
July 24, 2026 11:13
c9ec528 to
010662d
Compare
timtebeek
self-requested a review
July 24, 2026 12:44
timtebeek
approved these changes
Jul 24, 2026
timtebeek
left a comment
Member
There was a problem hiding this comment.
Thanks again! With a slight bit of polish I'll merge as soon as CI passes.
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.
What's changed
Adds
TestNgAssertionToAssertJ, wired into theTestNgToAssertjaggregate, to migrate TestNG's hard, instance-based assertion classorg.testng.asserts.Assertionto static AssertJassertThat(...). BecauseAssertionfails immediately (unlikeSoftAssert), it maps to the staticassertThatentry point — the same target asorg.testng.Assert.The recipe
assertThat(...), scoped by exact receiver type (TypeUtils.isOfClassType(..., "org.testng.asserts.Assertion")), so customAssertionsubclasses are left untouched and it stays disjoint fromSoftAssert extends Assertion.visitBlockpass removes the now-unused localAssertioninstance once its calls are rewritten (single-cycle; only when the variable has no remaining references). Fields are left in place.assertEquals/assertNotEquals(TestNG(actual, expected)order, plus message →.as(...)and floating-point delta →isCloseTo(..., within(...))/isNotCloseTo(...)),assertTrue/assertFalse,assertNull/assertNotNull,assertSame/assertNotSame,assertEqualsNoOrder→containsExactlyInAnyOrder, andfail(...)→ staticAssertions.fail(...)(no-argfail()→fail(""), matchingJUnitFailToAssertJFail).Shared helper
Extracts the duplicated
isFloatingPointTypeinto a package-privateTestNgAssertsand points every caller at it:TestNgAssertEqualsToAssertThat,TestNgAssertNotEqualsToAssertThat,TestNgSoftAssertToAssertJ, and the new recipe.Test change worth noting
TestNgToAssertJTest#hardAssertionIsNotChangedis removed: it asserted that the aggregate leaves a hardorg.testng.asserts.Assertioninstance unchanged, which is no longer true now that this recipe migrates it. Its replacement,assertionInstanceMigratedViaAggregate, pins the new behaviour, andcustomAssertionSubclassIsNotChangedkeeps the subclass-is-left-alone guarantee.Tests cover every overload branch, the dead-local removal (plus retention-when-referenced and field-not-removed), and the
failvariants.