Excavator: Migrate Groovy nebula test PalantirJavaFormatIdeaPluginTest to the new Java Junit framework
#1480
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/PalantirJavaFormatIdeaPluginTest.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 provide a summary of what was accomplished:
Migration Summary
I have successfully migrated the test class
PalantirJavaFormatIdeaPluginTestfrom the Nebula/Groovy testing framework to the new Java-based testing framework. Here's what was done:Files Modified/Created:
Original Groovy test file (
gradle-palantir-java-format/src/test/groovy/com/palantir/javaformat/gradle/PalantirJavaFormatIdeaPluginTest.groovy):New Java test file (
gradle-palantir-java-format/src/test/java/com/palantir/javaformat/gradle/PalantirJavaFormatIdeaPluginTest.java):@GradlePluginTestsannotation@ParameterizedTestwith@CsvSourcefor data-driven testingGradleInvokerandRootProjectMigration errors documentation (
test-migration-errors.md):Key Changes Made:
"idea_configuresXmlFiles"()(Groovy string) toidea_configures_xml_files()(Java snake_case)where:block to JUnit 5's@CsvSourceplugins().add()API and varargsappend()methodstandardBuildFile()helper matching the original test's structureCompilation Status:
✅ The new test compiles successfully with no errors or warnings
The migrated test maintains complete feature parity with the original Groovy test while following all best practices of the new testing framework.
Claude Code Metrics
Migration Notes
Test Migration Errors and Learnings
Migration of PalantirJavaFormatIdeaPluginTest
First Pass: Initial Migration
Error 1: Incorrect method name for accessing project directory
Error:
cannot find symbol: method projectDir()Cause: Used
rootProject.projectDir()instead of the correct APIFix: Changed to
rootProject.path()- the RootProject is a record with apathfield, not a method calledprojectDir()Learning: Always check the actual API of the testing framework objects. RootProject is a Java record with a
path()accessor method.Error 2: Wrong GPathResult import
Error:
incompatible types: groovy.util.slurpersupport.GPathResult cannot be converted to groovy.xml.slurpersupport.GPathResultCause: Used the wrong import for
GPathResultfromgroovy.xmlinstead ofgroovy.utilFix: Changed import to
groovy.util.slurpersupport.GPathResultLearning: Groovy has multiple GPathResult classes in different packages - need to use the correct one from groovy.util.slurpersupport
Error 3: Wrong assertThat for boolean values
Error:
no suitable method found for assertThat(boolean)- GradlePluginTestAssertions doesn't have assertThat for primitivesCause: Used the framework's assertion API which only supports TaskOutcome and InvocationResult
Fix: Changed to use standard AssertJ:
import static org.assertj.core.api.Assertions.assertThat;Learning: The framework's assertion API is specialized for Gradle testing results. For general assertions like booleans, use standard AssertJ.
Error 4: Cannot use getAt() with String parameter on GPathResult
Error:
no suitable method found for getAt(String)- GPathResult.getAt() only accepts int or IntRangeCause: Tried to use
getAt("@name")to access XML attributes, which doesn't work in JavaFix: Switched from XmlSlurper to XmlParser and used Node-based traversal with
((Map<?, ?>) node.attributes()).get("name")Learning: XmlSlurper's GPath syntax (like
it.@name) that works in Groovy doesn't translate well to Java. XmlParser with Node-based iteration is more Java-friendly.Error 5: Cannot use lambda with Groovy Closure methods
Error:
incompatible types: Closure is not a functional interfaceCause: Tried to use Java lambdas with Groovy's
findAll()andfind()methodsFix: Switched from using closures to explicit iteration with for loops and Node-based XML parsing
Learning: Groovy's closure-based APIs like
findAll()andfind()don't accept Java lambdas. Need to use traditional iteration in Java.Second Pass: Error Prone Check Fixes
Error 6: GradleTestStringFormatting check violation
Error:
Use the varargs overload of methods to get syntax highlighting, rather than manually formatting stringsCause: Used
String.format()to build NATIVE_CONFIG constant and passed it toappend()Fix: Removed the constant and used
append()with varargs directly:append("palantirJavaFormatNative files(\"%s\")", NATIVE_IMAGE_FILE.toPath())Learning: The framework encourages using varargs overloads for better IDE support. Don't pre-format strings, pass format arguments directly.
Error 7: Deprecated XmlParser usage
Error:
groovy.util.XmlParser is deprecatedCause: XmlParser is deprecated but still needed for Java-friendly XML parsing
Fix: Added
@SuppressWarnings("deprecation")annotation on the xmlParser variableLearning: Sometimes deprecated APIs are still the best option for Java code working with Groovy libraries. Use @SuppressWarnings appropriately.
Error 8: GradleTestPluginsBlock check violation
Error:
Plugins must be added using .plugins().add() methodCause: Used
apply plugin: 'idea'in the append() call within the helper methodFix: Changed to use
plugins().add("idea")instead of applying plugins in the append() blockLearning: The framework strongly enforces using the structured plugins() API. Never use
apply plugin:in append() calls - always use the plugins().add() API.Third Pass: Style Improvements
Improvement 1: Removed unused imports
Action: Removed
import java.util.List;which was not usedLearning: Keep imports clean - remove unused imports.
Improvement 2: Chained plugin additions
Action: Changed from two separate calls to chained calls:
Learning: Chain fluent API calls for better readability.
Summary of Key Learnings
path()notprojectDir()apply plugin:in append() callsTest Coverage Note
The migrated test maintains the same coverage as the original:
To enable or disable this check, please contact the maintainers of Excavator.