Excavator: Migrate Groovy nebula test PalantirJavaFormatPluginTest to the new Java Junit framework
#1479
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 have successfully migrated the test class from
PalantirJavaFormatPluginTest.groovytoPalantirJavaFormatPluginTest.java.Summary of Changes
Key Migration Steps:
Added delineator comments to the original Groovy test file to help with human review
Converted the test from Groovy/Spock to Java/JUnit 5:
IntegrationTestKitSpec) to JUnit 5 with@GradlePluginTestsannotation@Unrollwith Spock'swhere:block to@ParameterizedTestwith@CsvSourceformat_diff_updates_only_lines_changed_in_git_diffFile Operations:
rootProject.gradlePropertiesFile().appendProperty()for setting propertiesrootProject.buildGradle().plugins().add()for plugin managementrootProject.mainSourceSet().java().writeClass()for creating Java source filesfileByClassName()to access and modify Java filesGit Commands:
executeGitCommand()using Java'sProcessBuildersince the framework doesn't provide built-in git supportAssertions:
GradlePluginTestAssertions.assertThat()for build results.assertThat()on file objects for file content assertionsFixed compilation errors:
append("%s", variable)to satisfy Error Prone checksappendProperty()for properties files as recommended in the testing guideThe migrated test compiles successfully and follows all best practices outlined in the testing-guide.md. A detailed error log has been created at
/repo/test-migration-errors.mddocumenting all issues encountered and how they were resolved.Claude Code Metrics
Migration Notes
Test Migration Errors and Fixes
Migration: PalantirJavaFormatPluginTest.groovy → PalantirJavaFormatPluginTest.java
Initial Compilation Errors
Error 1: Incorrect assertion syntax for file content
Error Message:
Problem:
I tried to use
assertThat(rootProject.mainSourceSet().java().fileByClassName("Main"))directly from the GradlePluginTestAssertions class, but there's no overload for JavaFile.Solution:
According to the testing-guide.md, file assertions should be done by calling
.assertThat()on the file object itself, not by passing the file to the assertThat method. Changed:to:
Reference: testing-guide.md section "File Assertions"
Error 2: Error Prone check GradleTestStringFormatting failure
Error Message:
Problem:
Used
.append(extraGradleProperties)whereextraGradlePropertiesis a parameter variable. The Error Prone check expects String.format() style parameters when passing variables.Solution:
Changed from:
to:
Reference: testing-guide.md mentions "All methods support
String.format()syntax for dynamic values" and the Error Prone check enforces this pattern.Review Pass: Best Practices
Issue 1: Using append() for properties instead of appendProperty()
Problem:
Originally used
.append("%s", extraGradleProperties)to add a property to gradle.properties file.Solution:
According to testing-guide.md, properties files should use
appendProperty(key, value)for key-value pairs. Since the parameter value is "palantir.native.formatter=true", I changed to:Reference: testing-guide.md section "Properties Files" states "Use
appendProperty(key, value)for properties files, notappend()"Issue 2: Unused import
Problem:
Import
java.util.Collectionswas not used in the Java version.Solution:
Removed the unused import.
Migration Strategy Notes
Test Name Convention: Changed from Spock string test name
'formatDiff updates only lines changed in git diff'to snake_caseformat_diff_updates_only_lines_changed_in_git_diff.Parameterized Tests: Used JUnit 5's
@ParameterizedTestwith@CsvSourceinstead of Spock's@Unrollwithwhere:block. The framework automatically handles multi-Gradle-version testing, so this parameterization is only for the test-specific parameters (extraGradleProperties and expectedOutput).Git Commands: Since the framework doesn't provide built-in git support, I created a helper method
executeGitCommand()that uses Java'sProcessBuilderto run git commands in the project directory.Build File Setup: Converted the Groovy variable
standardBuildFileto a helper method that returnsGradleFilefor fluent chaining, as recommended in the instructions.File Operations:
rootProject.mainSourceSet().java().writeClass()for creating Java filesfileByClassName("Main")to access the created file by its class name.overwrite()to replace file contentsAssertions: Used the fluent assertion API from
GradlePluginTestAssertions.assertThat()for result assertions and.assertThat()on file objects for file assertions.Final State
The test compiles successfully and follows all the best practices outlined in testing-guide.md.
To enable or disable this check, please contact the maintainers of Excavator.