Repository navigation
Create a unique folder for no-argument TemporaryFolder#newFolder() - #1237
Merged
Merged
Conversation
A no-argument `folder.newFolder()` was rewritten to `newFolder(folder, "junit")` through the generated helper, so a second call in the same test failed `mkdirs()` with "Couldn't create folders". JUnit 4 creates a fresh directory on every call via `Files.createTempDirectory(root.toPath(), "junit")`, so emit exactly that instead, and add the `Files` import from the invocation so Groovy sources get it too.
Only a `new TemporaryFolder()` initializer was removed, so `@Rule TemporaryFolder f = TemporaryFolder.builder().assureDeletion().build();` kept its builder chain on the new `@TempDir File f` field, which does not compile. JUnit injects `@TempDir` fields, so drop whatever initializer a `@Rule` or `@ClassRule` field has.
The name identifier of a rewritten `newFolder(..)` or `newFile(..)` call was given the enclosing class type rather than the helper method type, leaving inconsistent type attribution for recipes that run afterwards.
23 of 76 tasks
timtebeek
enabled auto-merge (squash)
October 25, 2026 19:09
…ockUpVoidTest` `VariableReferences.findRhsReferences` now matches identifiers semantically rather than by name (openrewrite/rewrite-static-analysis#1122), so the `MockUpClass.Save.text` field access no longer counts as a use of the `text` parameter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TemporaryFolderToTempDirturned a no-argumentfolder.newFolder()intonewFolder(folder, "junit")through the generated helper. That helper callsmkdirs()on a fixed path, so a second call in the same test threwIOException: Couldn't create folders. JUnit 4 creates a fresh directory under the root on every call, and the recipe now emits the same thing JUnit 4 does internally:Two smaller fixes are in separate commits:
TemporaryFolder.builder().assureDeletion().build()kept that initializer on the new@TempDir Filefield, which doesn't compile. Any initializer on a@Ruleor@ClassRulefield that becomes@TempDiris now dropped.newFolder(..)ornewFile(..)call was attributed with the enclosing class type instead of the helper's method type.No-argument
newFile()already mapped toFile.createTempFile("junit", null, root), which matches JUnit 4, so it is unchanged. TheFilesimport for the new shape is added from the method invocation, because the visitor'svisitCompilationUnitnever runs for Groovy sources. A new Groovy test covers this.Verified locally on the final head:
./gradlew test --offline --tests 'org.openrewrite.java.testing.junit5.TemporaryFolderToTempDirTest'passed 22/22. A broader run overorg.openrewrite.java.testing.junit5.*,testcontainers.*andMockitoJUnitToMockitoExtensionTestpassed 521/534. The 13 failures were all Tooling API Gradle tests that could not fetch the Gradle model locally, so I'm leaving those to CI.Fixes item B3 of #1211.