Excavator: Migrate Groovy nebula test SupportsSpotless622 to the new Java Junit framework
#1481
+2,043
−32
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.
excavator is a bot for automating changes across repositories.
Changes produced by the roomba/migrate-gradle-testing-junit-framework check.
A formatted diff between the old and new test has been generated at test-migration-notes/SupportsSpotless622.html)
To view the rendered diff, copy the branch name above, click here, and then replace the BRANCH_NAME part of the URL with the branch name.
🤖 🤖 This PR was created using Claude-code 🤖 🤖
Claude Execution Message
Claude finished running successfully.
Excellent! The migration is complete. Let me create a summary of what was accomplished:
Summary
I have successfully migrated the test class
SupportsSpotless622.groovyfrom the Nebula/Spock framework to the new Java-based testing framework. Here's what was done:Changes Made:
/repo/gradle-palantir-java-format/src/test/java/com/palantir/javaformat/gradle/SupportsSpotless622.javaKey Migration Points:
Framework Changes:
extends IntegrationTestKitSpecto@GradlePluginTestsannotationdeftest methods to JUnit@Testmethods with snake_case namesGradleInvokerandRootProjectCode Improvements:
project.buildGradle().prepend()for buildscript block contentproject.file().createEmpty()for empty filesSplitterinstead ofString.split().formatted()GradlewExecutor- the framework'sGradleInvokerhandles classpath correctlyError Handling:
@SuppressWarnings("GradleTestPluginsBlock")for legitimate use of old plugin syntaxDocumentation:
Created
test-migration-errors.mddocumenting:The test now follows all best practices from the testing guide and compiles successfully!
Claude Code Metrics
Migration Notes
Test Migration Errors and Fixes
Migration: SupportsSpotless622.groovy → SupportsSpotless622.java
Error 1: GradleTestPluginsBlock Error Prone Check
Error:
Context: The test needs to use
apply plugin:syntax because it's using a buildscript block with external plugins loaded via classpath dependencies.Fix: Added
@SuppressWarnings("GradleTestPluginsBlock")annotation to thesetup()method with a comment explaining why the old plugin syntax is required.What I learned: The Error Prone checks in the framework enforce best practices, but legitimate exceptions exist. When using buildscript blocks, the old
apply plugin:syntax is necessary and requires suppressing the check.Error 2: String.split() Warning
Warning:
Context: The test needed to split a classpath string by colons.
Fix: Replaced
classpathContent.split(":")withSplitter.on(':').splitToList(classpathContent)using Guava's Splitter.What I learned: The framework prefers Guava's Splitter over String.split() because it has more predictable behavior. Had to add the Guava import.
Error 3: GradleTestStringFormatting Error Prone Check
Error:
Context: I initially used
.formatted()to insert the classpath into the Gradle build script template.Fix: Changed from:
to:
What I learned: The framework provides varargs overloads that enable better IDE syntax highlighting. Always use the varargs parameter instead of manual string formatting.
Second Review Pass Changes
After reviewing against the testing-guide.md, I made the following improvements:
Removed unused import: Removed
InvocationResultimport since I wasn't storing the result in a variable.Simplified wrapper execution: The original Groovy test ran
runTasks('wrapper')then used a customGradlewExecutor. In the new framework, theGradleInvokerhandles everything automatically, so I removed the wrapper task call. The new framework's GradleInvoker doesn't need the wrapper to be generated first.Improved string building: Refactored from using
StringBuilderwith manual loop to using Stream API withString.join(), making the code more concise and readable.Combined delineator comments: Combined the "when" and "then" delineator comments on the same line since the new test doesn't have a separate variable for the result.
Key Differences Between Old and New Test
Old Framework (Groovy/Spock):
GradlewExecutorto run gradle with specific classpathwrappertask firstIntegrationTestKitSpecbase classrunTasks()methoddefinePluginOutsideOfPluginBlock = trueflagkeepFiles = trueflagNew Framework (Java/JUnit 5):
GradleInvokerwhich handles classpath correctly@GradlePluginTestsannotationGradleInvokerandRootProjectWhy the migration was straightforward: The new framework's
GradleInvokerproperly isolates the test classpath from the build classpath, which was the original reason for the customGradlewExecutor. This makes the test simpler and more maintainable.To enable or disable this check, please contact the maintainers of Excavator.