Skip to content

Only convert Java sources in UseAssertSame - #1223

Merged
timtebeek merged 1 commit into
mainfrom
tim/use-assert-same-skip-kotlin
Oct 24, 2026
Merged

timtebeek merged 1 commit into
mainfrom
tim/use-assert-same-skip-kotlin

Conversation

@timtebeek

Copy link
Copy Markdown
Member

In Kotlin (and Groovy) == calls equals; identity is ===. UseAssertSame still treated == as identity there, so JupiterBestPractices turned a passing equality check into a failing identity check:

assertTrue(listOf(1) == listOf(1))   // before
assertSame(listOf(1), listOf(1))     // after: fails

The recipe now only visits Java compilation units, using the same JavaFileChecker precondition as #1219. I did not map Kotlin === to assertSame; that would need a separate K.Binary path, and leaving Kotlin alone is the safe default.

Verified with ./gradlew test --tests 'org.openrewrite.java.testing.junit5.*' --tests 'org.openrewrite.java.testing.cleanup.AssertTrueComparisonToAssertEqualsTest': 479 tests, 0 failures (4 skipped). The new kotlinEqualityIsNotIdentity test fails without the fix.

Fixes item C12 of #1211.

In Kotlin (and Groovy) `==` calls `equals`, so turning `assertTrue(listOf(1) == listOf(1))` into `assertSame(listOf(1), listOf(1))` changed a passing equality check into a failing identity check. Kotlin tests reach this recipe through `JupiterBestPractices`, so restrict it to Java compilation units with a `JavaFileChecker` precondition.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Oct 24, 2026
@timtebeek
timtebeek merged commit 765ce39 into main Oct 24, 2026
2 checks passed
@timtebeek
timtebeek deleted the tim/use-assert-same-skip-kotlin branch October 24, 2026 13:39
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant