Skip to content

Only migrate the two-argument InvocationInterceptor.interceptDynamicTest in RemoveInterceptDynamicTest - #1221

Merged
timtebeek merged 2 commits into
mainfrom
tim/remove-intercept-dynamic-test-two-arg-only
Oct 24, 2026
Merged

timtebeek merged 2 commits into
mainfrom
tim/remove-intercept-dynamic-test-two-arg-only

Conversation

@timtebeek

Copy link
Copy Markdown
Member

RemoveInterceptDynamicTest matched interceptDynamicTest(..), so it also deleted overrides of the three-argument interceptDynamicTest(Invocation, DynamicTestInvocationContext, ExtensionContext), which JUnit 6 still has (checked against junit-jupiter-api 6.1.3 in classpath.tsv.gz). User interceptors lost their logic without any warning. Deleting the removed two-argument override also threw away its body, even though under JUnit 5 the default three-argument method delegated to it.

The recipe now only matches the two-argument signature. Instead of deleting it, it adds a DynamicTestInvocationContext parameter in the middle (with a fresh name if invocationContext is taken) and keeps the body:

// before
public void interceptDynamicTest(Invocation<Void> invocation, ExtensionContext extensionContext)
// after
public void interceptDynamicTest(Invocation<Void> invocation, DynamicTestInvocationContext invocationContext, ExtensionContext extensionContext)

When the class already overrides the three-argument method, or the source isn't Java (for example Kotlin), the two-argument override is still removed, same as before. The display name and description are updated to match. The existing test no longer uses a stub Method class: the no-change test imports java.lang.reflect.Method from the real JDK.

Verified with ./gradlew test --tests 'org.openrewrite.java.testing.junit6.*' (90 tests, 0 failures). All 4 RemoveInterceptDynamicTestTest cases fail against the recipe on main.

Fixes item C11 of #1211.

…Test` in `RemoveInterceptDynamicTest`

The recipe matched `interceptDynamicTest(..)`, so it also deleted overrides of the three-argument `interceptDynamicTest(Invocation, DynamicTestInvocationContext, ExtensionContext)` that JUnit 6 still has, silently dropping user interceptor logic. It now only matches the removed two-argument signature, and rather than deleting that override it adds a `DynamicTestInvocationContext` parameter so the body keeps running under JUnit 6, as it did through the JUnit 5 default delegation. The two-argument override is still removed when the class already overrides the three-argument one, or for non-Java sources.
@timtebeek
timtebeek merged commit 8720326 into main Oct 24, 2026
2 checks passed
@timtebeek
timtebeek deleted the tim/remove-intercept-dynamic-test-two-arg-only branch October 24, 2026 13:48
@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