Skip to content

Handle non-@Rule TemporaryFolder fields #720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 4, 2025

Conversation

amishra-u
Copy link
Contributor

What's changed?

The TemporaryFolderToTempDir recipe did not correctly handle TemporaryFolder instances that were not annotated with @rule.
Issue: When the recipe made other changes, the ChangeType incorrectly migrates new TemporaryFolder() to new File().

This PR updates the recipe to properly handle TemporaryFolder instances that are not explicitly annotated with @rule,

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

github-actions[bot]

This comment was marked as outdated.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@timtebeek
Copy link
Member

That's some interesting usage patterns you're uncovering there @amishra-u ; thanks for reporting them all here in the form of pull requests. I've asked colleagues to help out with reviews as it's at times a bit much to keep up, but know it's appreciated! 😅

@timtebeek timtebeek self-requested a review May 4, 2025 16:17
@timtebeek timtebeek moved this from In Progress to Ready to Review in OpenRewrite May 4, 2025
@timtebeek timtebeek added enhancement New feature or request recipe Recipe request junit labels May 4, 2025
github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as duplicate.

@amishra-u
Copy link
Contributor Author

That's some interesting usage patterns you're uncovering there @amishra-u ; thanks for reporting them all here in the form of pull requests. I've asked colleagues to help out with reviews as it's at times a bit much to keep up, but know it's appreciated! 😅

Thanks! I’m running these recipes on a repository with around 50k test classes, so they’re definitely getting battle-tested. By the time we're done, these should be rock-solid. Appreciate you looping others in for reviews—it really helps!

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/main/resources/META-INF/rewrite/examples.yml
    • lines 1011-1013
    • lines 2443-2503
    • lines 2576-2575

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.

Good to have this odd bit of usage cleared out as well; thanks!

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/main/resources/META-INF/rewrite/examples.yml
    • lines 2443-2503
    • lines 2576-2575

@timtebeek timtebeek merged commit ef96c01 into openrewrite:main May 4, 2025
2 checks passed
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite May 4, 2025
}).visit(a.getTree(), ctx, a.getCursor().getParentOrThrow()))
.visit(mv, ctx, getCursor().getParentOrThrow());
return (J.VariableDeclarations) annotated("@org.junit.*Rule")
.asVisitor(a -> JavaTemplate.builder("@TempDir")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@amishra-u amishra-u deleted the temp_dir_1 branch May 5, 2025 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request junit recipe Recipe request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants