Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions MIGRATION_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Test Migration Summary

## Overview
Successfully migrated `PalantirJavaFormatSpotlessPluginTest` from Groovy/Spock to Java/JUnit 5 using the new gradle-plugin-testing framework.

## Files Changed

### Original File
- **Path**: `/repo/gradle-palantir-java-format/src/test/groovy/com/palantir/javaformat/gradle/PalantirJavaFormatSpotlessPluginTest.groovy`
- **Status**: Enhanced with delineator comments for review comparison
- **Action**: Can be deleted once the migration is approved

### Migrated File
- **Path**: `/repo/gradle-palantir-java-format/src/test/groovy/com/palantir/javaformat/gradle/PalantirJavaFormatSpotlessPluginTest.java`
- **Note**: The file is in the `groovy` directory (not `java`) because it needs to access `GradlewExecutor.java` which is also in the groovy directory

### Artifact Files
- **test-migration-errors.md**: Documents all errors encountered and fixes applied during migration
- **MIGRATION_SUMMARY.md**: This file - summary of the migration

## Key Changes

### 1. Test Framework
- **From**: Spock with `@Unroll` and `where` clauses
- **To**: JUnit 5 with `@ParameterizedTest` and `@MethodSource`

### 2. Test Structure
```java
// Old (Spock)
@Unroll
def "formats with spotless when spotless is applied"(String extraGradleProperties, String javaVersion, String expectedOutput) {
// ... test body ...
where:
extraGradleProperties | javaVersion | expectedOutput
"" | 21 | "Using the Java-based formatter"
"palantir.native.formatter=true" | 21 | "Using the Java-based formatter"
}

// New (JUnit 5)
@ParameterizedTest(name = "[{index}] extraGradleProperties={0}, javaVersion={1}, expectedOutput={2}")
@MethodSource("formatsWithSpotlessTestCases")
void formats_with_spotless_when_spotless_is_applied(
String extraGradleProperties, String javaVersion, String expectedOutput,
GradleInvoker gradle, RootProject rootProject) {
// ... test body ...
}

static Stream<Arguments> formatsWithSpotlessTestCases() {
return Stream.of(
Arguments.of("", "21", "Using the Java-based formatter"),
Arguments.of("palantir.native.formatter=true", "21", "Using the Java-based formatter"),
Arguments.of("palantir.native.formatter=true", "17", "Using the native-image formatter"));
}
```

### 3. File Operations
- **From**: Direct file manipulation (`settingsFile << '...'`, `buildFile << '...'`, `file('...').text = ...`)
- **To**: Fluent API (`rootProject.settingsGradle().append(...)`, `rootProject.buildGradle().append(...)`, `rootProject.file(...).overwrite(...)`)

### 4. Assertions
- **From**: Spock's built-in assertions
- **To**: AssertJ assertions (`assertThat(output).contains(...)`, `assertThat(formattedFile).isEqualTo(...)`)

### 5. Test Naming
- **From**: Spock string test names with spaces
- **To**: snake_case method names (`formats_with_spotless_when_spotless_is_applied`)

### 6. Setup Method
- **From**: `def setup()` with implicit projectDir access
- **To**: `@BeforeEach void setup(RootProject rootProject)` with parameter injection

## Important Notes

### Custom Executor Usage
This test uses a custom `GradlewExecutor` rather than the standard `GradleInvoker` because:
1. It needs special classpath handling to avoid loading formatter classes twice
2. It runs the actual `./gradlew` wrapper command (not Gradle TestKit)
3. The test calls `gradle.withArgs("wrapper").buildsSuccessfully()` to generate the wrapper first

### File Location Decision
The migrated Java test was placed in `src/test/groovy/` instead of `src/test/java/` because:
- Gradle's groovy plugin compiles `src/test/java/` before `src/test/groovy/`
- `GradlewExecutor.java` is located in `src/test/groovy/`
- Java files in `src/test/java/` cannot access classes in `src/test/groovy/` during compilation
- Both Java and Groovy files in the groovy directory compile together successfully

## Compilation Status
✅ **PASSED**: `./gradlew :gradle-palantir-java-format:compileTestGroovy`

The test compiles successfully and is ready for testing.

## Delineator Comments
Both the original Groovy file and the new Java file contain `***DELINEATOR FOR REVIEW` comments to help reviewers compare:
- Method boundaries
- Variable/field definitions
- Test method sections (setup/when/then)

These comments can be removed after the migration is approved.

This file was deleted.

Loading