Skip to content

Support Kotlin in three JUnit testing recipes (fix crashes/no-ops)#1065

Merged
timtebeek merged 3 commits into
mainfrom
tim/triage-kotlin-test-failures
Jul 24, 2026
Merged

Support Kotlin in three JUnit testing recipes (fix crashes/no-ops)#1065
timtebeek merged 3 commits into
mainfrom
tim/triage-kotlin-test-failures

Conversation

@timtebeek

@timtebeek timtebeek commented Jul 24, 2026

Copy link
Copy Markdown
Member
  • Fixes three testing recipes that crashed or silently no-op'd on Kotlin sources (surfaced by a mass-run against Kotlin repos; see moderneinc/customer-requests#2861).

  • AssertTrueNullToAssertNull: replaced the contextSensitive JavaTemplate (which generated 0 statements on Kotlin) with direct LST manipulation — rename to assertNull, rewrite the first argument, and fix the method type — so it works on both Java and Kotlin.

  • CsvSourceToValueSource: the @ValueSource JavaTemplate could not be spliced into a Kotlin compilation unit ("Could not parse as Java"), so single-String @CsvSource now uses KotlinTemplate with Kotlin [...] array syntax; non-String Kotlin @CsvSource is left unchanged (no crash) because the Annotated/Literal traits don't resolve Kotlin array attributes.

  • UpdateTestAnnotation: the body-wrapping JavaTemplate produced an empty Kotlin body and threw IndexOutOfBounds, so @Test(expected/timeout) is now left intact on Kotlin rather than crashing or dropping the arguments.

Each recipe gains a Kotlin test covering the fixed behavior.

Replace the contextSensitive JavaTemplate, which generated 0 statements on a
Kotlin LST, with direct LST manipulation (rename to assertNull, rewrite the
first argument, and fix the method type). This works on both Java and Kotlin.
The JavaTemplate building @valuesource could not be spliced into a Kotlin
compilation unit ("Could not parse as Java"). Use KotlinTemplate with Kotlin
array syntax on Kotlin sources. Non-String Kotlin @CsvSource is left unchanged
(no crash) as the Annotated trait does not resolve Kotlin array attributes.
The JavaTemplate that wraps the body in assertThrows produced an empty body on
Kotlin, throwing IndexOutOfBounds on getStatements().get(0). Leave the JUnit 4
@test(expected = ..., timeout = ...) intact on Kotlin rather than crashing or
dropping the arguments.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Jul 24, 2026
@timtebeek
timtebeek marked this pull request as ready for review July 24, 2026 15:45
@timtebeek
timtebeek merged commit 5fe4cad into main Jul 24, 2026
1 check passed
@timtebeek
timtebeek deleted the tim/triage-kotlin-test-failures branch July 24, 2026 15:49
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Jul 24, 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.

1 participant