Excavator: Migrate Groovy nebula test PalantirJavaFormatPluginTest to the new Java Junit framework
#1479
+3,106
−100
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/PalantirJavaFormatPluginTest.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.
Perfect! Let me create a summary of what was accomplished:
Migration Complete!
I've successfully migrated the
PalantirJavaFormatPluginTestfrom the Nebula/Spock testing framework to the new Java-based testing framework. Here's what was done:Key Changes:
Framework Migration:
IntegrationTestKitSpecbase class with@GradlePluginTestsannotation@Unrollparameterized test to JUnit 5's@ParameterizedTestwith@CsvSourceTest Structure:
'formatDiff updates only lines changed in git diff'toformatDiff_updates_only_lines_changed_in_git_diff(snake_case)GradleInvokerandRootProjectFile Operations:
buildFile <<withproject.buildGradle().append()file('gradle.properties') <<withproject.gradlePropertiesFile().append()project.mainSourceSet().java().writeClass()for creating Java files.plugins().add()API instead of inline plugin declarationsAssertions:
assertThat(result).output().contains()file.assertThat().content().isEqualTo()Error Handling:
GradleTestStringFormattingissues by using varargs overloadGradleTestPluginsBlockissues by using.plugins().add()APIFiles Modified:
/repo/gradle-palantir-java-format/src/test/groovy/com/palantir/javaformat/gradle/PalantirJavaFormatPluginTest.groovy/repo/gradle-palantir-java-format/src/test/java/com/palantir/javaformat/gradle/PalantirJavaFormatPluginTest.java/repo/test-migration-errors.mdVerification:
The migrated test maintains all the original functionality while leveraging the modern, type-safe Java testing framework with better IDE support and cleaner syntax.
Claude Code Metrics
Migration Notes
Test Migration Errors and Fixes
Initial Migration Issues
Issue 1: Incorrect assertThat usage for file content
Error:
no suitable method found for assertThat(JavaFile)Problem: Used the static
assertThat()fromGradlePluginTestAssertionson aJavaFileobject.Fix: Used the instance method
file.assertThat()instead of the static method. The correct pattern is:Learning: File objects have their own
assertThat()method that returns appropriate AssertJ assertions. Only use the staticassertThat()fromGradlePluginTestAssertionsforInvocationResultandTaskOutcome.Issue 2: Error Prone GradleTestStringFormatting check failure
Error: Error Prone NullPointerException in GradleTestStringFormatting check when using
append(extraGradleProperties)with a parameter variable.Problem: The Error Prone check expects formatted strings to use the varargs overload for better IDE syntax highlighting.
Fix: Changed from:
to:
Learning: Always use the varargs overload
append(String format, Object... args)instead ofappend(String)when working with dynamic content. This provides better IDE syntax highlighting support.Issue 3: Error Prone GradleTestStringFormatting check with .formatted()
Error:
Use the varargs overload of methods to get syntax highlighting, rather than manually formatting strings with .formatted() or String.format()Problem: Used
.formatted()on a text block:Fix: Used the varargs overload instead:
Learning: Never use
.formatted()orString.format()when calling framework methods. Always use the varargs overload directly.Issue 4: Error Prone GradleTestPluginsBlock check failure
Error:
Plugins must be added using .plugins().add() method. Use gradleFile.plugins().add("plugin-id") instead.Problem: Used
apply plugin: 'idea'inside anappend()call.Fix: Changed to use the structured
.plugins().add()API:Learning: Always use the
.plugins().add()API for adding plugins, never useapply plugin:syntax in append calls. The structured API ensures correct positioning and prevents duplicates.Review Pass Issues
Observation 1: Unused variable
Issue: The variable
classpathFilesContentinstandardBuildFile()is read but never used.Fix: Removed the unused variable:
Learning: Clean up unused code during migration. Don't carry over unnecessary operations from the original test.
Observation 2: Using properties file API correctly
Current code: Using
append()for gradle propertiesStatus: Correct usage. According to testing-guide.md,
appendProperty(key, value)should be used for key-value pairs in properties files. However, in this test we're appending complete property strings (including newlines in the jvm args case), soappend()is appropriate.Observation 3: Text block formatting
Current code: Text blocks are used consistently with newlines after the opening delimiter.
Status: Good. Follows the instruction to "Add a new line after a text block for clarity reasons."
Observation 4: Git command execution
Current approach: Using
ProcessBuilderdirectly in a helper method.Status: Acceptable. The framework doesn't provide built-in git support, so this is the appropriate way to execute git commands for tests that need them.
Second Review Pass - Cleanup
Fix 1: Removed unused variable and import
Issue: The variable
classpathFilesContentwas declared and assigned but never used. Also theFilesimport was no longer needed.Fix: Removed both:
String classpathFilesContent = Files.readString(new File(CLASSPATH_FILE).toPath());import java.nio.file.Files;throws IOExceptionfromstandardBuildFile()method signature since it was only needed for the removedFiles.readString()callLearning: Clean up unused code and imports during migration. Don't carry over unnecessary operations from exploratory coding or the original test.
Final Review Pass
Final Compilation Check
Status: ✅ Test compiles successfully with no errors or warnings from Error Prone checks.
Checklist Against Testing Guide
@GradlePluginTestsannotationGradleInvokerandRootProject.plugins().add()API for adding pluginsassertThat()formatDiff_updates_only_lines_changed_in_git_diffstandardBuildFile()returnsGradleFilefor fluent chainingMigration Summary
Successfully migrated
PalantirJavaFormatPluginTestfrom Nebula/Spock framework to the new Java-based testing framework. The test:@Unrollandwhere:clause to JUnit 5's@ParameterizedTestwith@CsvSourceTo enable or disable this check, please contact the maintainers of Excavator.