Skip to content

Add junit-jupiter when only junit.framework.TestCase is used - #1117

Open
manduinca wants to merge 1 commit into
openrewrite:mainfrom
manduinca:fix/add-jupiter-for-junit3
Open

Add junit-jupiter when only junit.framework.TestCase is used#1117
manduinca wants to merge 1 commit into
openrewrite:mainfrom
manduinca:fix/add-jupiter-for-junit3

Conversation

@manduinca

@manduinca manduinca commented Sep 4, 2026

Copy link
Copy Markdown

What's changed?

AddJupiterDependencies now also scans for uses of junit.framework..*, next to org.junit..*, when deciding whether to add junit-jupiter. The two scanners share the accumulator, so either one marks the project as using JUnit and the scope logic is unchanged.

What's your motivation?

Fixes #1113. In a project whose tests only extend junit.framework.TestCase, JUnit4to5Migration removed junit:junit but never added Jupiter, because the scanner runs on the sources before MigrateJUnitTestCase rewrites them and no org.junit type is in use at that point. The migrated project didn't compile.

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

Whether broadening the guard here is the shape you want, versus making the RemoveDependency in the composite conditional. This one keeps AddJupiterDependencies correct on its own, which also covers running it standalone on a JUnit 3 codebase.

Have you considered any alternatives or workarounds?

A single glob covering both packages doesn't exist (org.junit and junit.framework share no prefix), and AddDependency takes one onlyIfUsing pattern, hence the two scanners.

Any additional context

Three tests: one on AddJupiterDependencies with a TestCase subclass in the test source set, a negative one with no JUnit at all (nothing is added), and one on the JUnit4to5Migration composite reproducing the issue (pom with junit:junit only), asserting junit-jupiter is added and junit removed. The two positive ones fail on main and pass with the change.

On building locally: since #1116 the build plugins resolve from the Code Genome repository, which asks for credentials I don't have, and latest.release (2.23.4) depends on rewrite 8.91.4, which isn't on Maven Central. With the plugins pinned to 2.23.1 locally (not part of this PR) ./gradlew build passes: 1859 tests, 0 failures, recipes.csv validated.

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 run ./gradlew build locally, and committed any resulting changes to recipes.csv (with the plugin pin described above; recipes.csv unchanged)
  • I've formatted the lines I changed, without reformatting code I didn't touch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

JUnit4to5Migration removes junit:junit without adding Jupiter when tests extend junit.framework.TestCase

1 participant