Skip to content

MigrateAssertionFailedError: leave source files using junit.framework.TestResult untouched - #1175

Open
mohitduhan19 wants to merge 3 commits into
openrewrite:mainfrom
mohitduhan19:migrate-assertion-failed-error-skip-test-result
Open

mohitduhan19 wants to merge 3 commits into
openrewrite:mainfrom
mohitduhan19:migrate-assertion-failed-error-skip-test-result

Conversation

@mohitduhan19

Copy link
Copy Markdown
Contributor

What's changed?

MigrateAssertionFailedError now has a DoesNotUseType precondition (with includeImplicit: true) on junit.framework.TestResult, so source files that use it are left untouched.

What's your motivation?

Follow-up to #1114 (the secondary MigrateAssertionFailedError point), as discussed in #1168.

TestResult.addFailure(Test, junit.framework.AssertionFailedError) only accepts the JUnit 3 type. Today the recipe retargets junit.framework.AssertionFailedError to org.opentest4j.AssertionFailedError everywhere in the file, including the cast passed into addFailure(..), so the argument type no longer matches and the file stops compiling. A class that reports to a TestResult is participating in the JUnit 3 execution model, consistent with #1168 which now leaves such TestCase subclasses untouched in MigrateJUnitTestCase.

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

The guard is per source file, matching #1168. includeImplicit: true also covers files that only reach TestResult through a method return type (e.g. createResult().addFailure(..)) without importing it.

Have you considered any alternatives or workarounds?

Only skipping the AssertionFailedError references that flow into addFailure(..). That would leave a mix of both exception types in one file, so skipping the whole file seemed simpler and safer.

Any additional context

Tests added:

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 (no recipe names, descriptions or options changed, so recipes.csv should be unaffected; I ran the junit5 package tests locally and they pass, apart from the Gradle Tooling API tests that couldn't run in my environment)
  • 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.

1 participant