migrate-groovy-to-java

Converts Spock/Groovy test files in Gradle modules to JUnit 5 Java tests.

735|355|Updated Apr 24, 2017
One-click install
npx skills add https://github.com/DataDog/dd-trace-java --skill migrate-groovy-to-java
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: migrate-groovy-to-java
Source: https://github.com/DataDog/dd-trace-java/tree/main/.agents/skills/migrate-groovy-to-java
Command: npx skills add https://github.com/DataDog/dd-trace-java --skill migrate-groovy-to-java

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Migrating Spock/Groovy test suites to Java by hand is slow and error-prone: Spock interactions, where: blocks, and Groovy idioms like map literals and lazy initialization have no direct Java equivalents, and naive translations silently weaken assertions. This Skill automates the conversion while enforcing quality rules that preserve the original test semantics.

Core Features & Use Cases

  • Spock-to-JUnit 5 conversion: Translates Groovy test files into JDK 8-compatible JUnit 5 tests, mapping where: blocks to @TableTest or @MethodSource parameterized tests.
  • Assertion and mock modernization: Replaces Spock interactions with Mockito verifications or concrete collections, upgrades assertTrue(x instanceof Y) to assertInstanceOf, and prevents relaxed matchers like any() from weakening pinned assertions.
  • Quality rule enforcement: Applies a catalog of BLOCKER, WARNING, and STYLE rules covering imports, collection simplification, typed tag getters, @WithConfig usage, and test structure.
  • Use Case: A Gradle module in dd-trace-java still contains .groovy test files. Run the Skill to generate equivalent .java tests, verify the test count is unchanged and all tests pass, then delete the Groovy sources.

Quick Start

Migrate all Groovy test files in the current Gradle module to JUnit 5 Java tests and confirm the test count stays the same.

Frequently Asked Questions about migrate-groovy-to-java

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I convert Spock Groovy tests to JUnit 5 Java?

List the Groovy files in the Gradle module, translate each to a JDK 8-compatible JUnit 5 test, then run the suite to confirm all tests pass and the test count is unchanged before deleting the Groovy files. Spock `where:` blocks map to `@TableTest` or `@MethodSource` parameterized tests.

How to migrate Spock where blocks to JUnit parameterized tests?

Prefer `@TableTest` with a String array where the first row is the header and a `scenario` column provides display names. When most cases are tabular but some need programmatic setup, combine `@TableTest` with `@MethodSource` on the same `@ParameterizedTest`; use `@MethodSource` alone only when tabular form is impractical.

How do I translate Spock mocks and interactions to Mockito?

Use the Mockito bundle (`libs.bundles.mockito`) instead of manual stub implementations. Port `1 * mock.method(value)` to `verify(mock).method(value)` and `N *` to `verify(mock, times(N))`, never relaxing to `atLeastOnce()` with `any()` matchers, since that silently weakens the original assertion.

Does the generated Java code support JDK 8?

Yes, all generated Java must be JDK 8 compatible. That means no text blocks, so `@TableTest` uses String array annotation syntax, and checked exceptions are declared with `throws` rather than wrapped in runtime exceptions.

What are common mistakes when converting Groovy tests to Java?

Frequent errors include weakening pinned assertions into `any()` matchers, mocking Maps instead of using a real HashMap with size assertions, keeping `LinkedHashMap` where order is irrelevant, and using `int` instead of `byte` for sampling priority constants. The QUALITY_RULES.md catalog flags these as BLOCKER or WARNING rules.

When should @TableTest not be used for parameterized tests?

Avoid `@TableTest` when the majority of rows require complex objects or custom converters that do not fit a tabular string representation. In that case use `@MethodSource` only, with a `<testMethodName>Arguments` method returning `Stream<Arguments>`.