Skip to content

MigrateJUnitTestCase: leave TestCase subclasses overriding run(TestResult) untouched - #1168

Merged
timtebeek merged 3 commits into
openrewrite:mainfrom
mohitduhan19:migrate-testcase-skip-run-override
Oct 5, 2026
Merged

timtebeek merged 3 commits into
openrewrite:mainfrom
mohitduhan19:migrate-testcase-skip-run-override

Conversation

@mohitduhan19

Copy link
Copy Markdown
Contributor

What's changed?

MigrateJUnitTestCase now leaves a source file untouched when it declares a method overriding junit.framework.TestCase#run(TestResult). This is done with a Preconditions.not(new DeclaresMethod<>(...)) guard (matching overrides) alongside the existing UsesType preconditions.

What's your motivation?

A TestCase that overrides run(TestResult) is hooking into the JUnit 3 execution model, which has no Jupiter equivalent (no TestResult, no run hook). Today the recipe half-migrates such a class: extends TestCase is dropped, and the TestCase → org.junit.Assert → Assertions type changes turn super.run(result) into Assertions.run(result), which does not exist, so the result no longer compiles. As suggested in the issue, skipping the class leaves code that still compiles and runs.

Anything in particular you'd like reviewers to focus on?

The guard is per source file, since the ChangeType / AssertToAssertions visitors this recipe schedules run on the whole compilation unit. migrateOtherTestCasesWhenOneOverridesRun shows that other TestCase subclasses in the same run are still migrated.

Have you considered any alternatives or workarounds?

Only skipping the super.run(..) rewrite. That would still leave a class that overrides a method it no longer inherits and has lost the behavior it relied on, so skipping the whole class seemed safer.

Any additional context

The secondary MigrateAssertionFailedError point from the issue is not addressed here, to keep this change focused.

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files
  • Ran MigrateJUnitTestCaseTest (16/16) and the rest of the junit5 package tests locally, all passing

@timtebeek timtebeek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for picking this up! Neat bit about JUnit 3 that I didn't know about yet.

@timtebeek
timtebeek merged commit 0d56576 into openrewrite:main Oct 5, 2026
1 check failed
@mohitduhan19

Copy link
Copy Markdown
Contributor Author

Thanks for the quick review and merge, @timtebeek! Happy to take a look at the MigrateAssertionFailedError point from #1114 next if that'd be useful.

@timtebeek

Copy link
Copy Markdown
Member

That'd be appreciated, thanks!

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.

MigrateJUnitTestCase rewrites super.run(TestResult) to Assertions.run(...), which does not exist

2 participants