Skip to content

Conversation

@amishra-u
Copy link
Contributor

Implements HandleExternalResourceRules recipe to migrate JUnit 4 ExternalResource-based @rule and @ClassRule fields to JUnit 5 by adding @ExtendWith(ExternalResourceSupport.class) from
junit-jupiter-migrationsupport. This provides a migration path for rules like TemporaryFolder and GrpcCleanupRule that extend ExternalResource but don't have direct JUnit 5 equivalents.

Changes:

  • Add HandleExternalResourceRules recipe to detect ExternalResource-based rules
  • Add helper methods to Junit4Utils for checking @Rule/@ClassRule annotations
  • Add junit-jupiter-migrationsupport and grpc-testing dependencies for testing
  • Add comprehensive test coverage for field and method-based rules

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

…gration support

  Implements HandleExternalResourceRules recipe to migrate JUnit 4 ExternalResource-based @rule and @ClassRule fields to JUnit 5 by adding @ExtendWith(ExternalResourceSupport.class) from
  junit-jupiter-migrationsupport. This provides a migration path for rules like TemporaryFolder and GrpcCleanupRule that extend ExternalResource but don't have direct JUnit 5 equivalents.

  Changes:
  - Add HandleExternalResourceRules recipe to detect ExternalResource-based rules
  - Add helper methods to Junit4Utils for checking @Rule/@ClassRule annotations
  - Add junit-jupiter-migrationsupport and grpc-testing dependencies for testing
  - Add comprehensive test coverage for field and method-based rules
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
amishra-u and others added 2 commits December 21, 2025 15:51
github suggestions

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@timtebeek timtebeek added recipe Recipe request junit labels Dec 22, 2025
@timtebeek timtebeek self-requested a review December 22, 2025 09:18
Copy link
Member

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Thanks a lot @amishra-u ; good to see these rules flow back to the project to convert any left over cases beyond what was covered already.

I've applied a few small changes, mostly to add preconditions and reduce the usage of Annotated.Matcher when service(AnnotationService) ought to be enough.

@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Dec 22, 2025
@timtebeek timtebeek merged commit 9cd08b2 into openrewrite:main Dec 22, 2025
2 checks passed
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

junit recipe Recipe request

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants