You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .claude/skills/migrate-groovy-to-java/SKILL.md
+27-2Lines changed: 27 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,12 +13,37 @@ Migrate test Groovy files to Java using JUnit 5
13
13
14
14
When converting Groovy code to Java code, make sure that:
15
15
- The Java code generated is compatible with JDK 8
16
-
- When translating Spock tests, favor using `@CsvSource` with `|` delimiters
17
-
- When using `@MethodSource`, name the arguments method by appending `Arguments` using camelCase to the test method name (e.g. `testMethodArguments`) and return a `Stream` of arguments using `Stream.of(...)` and `arguments(...)` with static import.
16
+
- When translating Spock tests, favor using @TableTest. See detailed instructions in the "TableTest Usage" section of this document.
17
+
- When usage of `@TableTest` impossible, use `@MethodSource`, and name the arguments method by appending `Arguments` using camelCase to the test method name (e.g. `testMethodArguments`) and return a `Stream` of arguments using `Stream.of(...)` and `arguments(...)` with static import.
18
18
- Ensure parameterized test names are human-readable (i.e. no hashcodes); instead add a description string as the first `Arguments.arguments(...)` value or index the test case
19
19
- When converting tuples, create a light dedicated structure instead to keep the typing system
20
20
- Instead of checking a state and throwing an exception, use JUnit asserts
21
21
- Do not wrap checked exceptions and throw a Runtime exception; prefer adding a throws clause at method declaration
22
22
- Do not mark local variables `final`
23
23
- Ensure variables are human-readable; avoid single-letter names and pre-define variables that are referenced multiple times
24
24
- When translating Spock `Mock(...)` usage, use `libs.bundles.mockito` instead of writing manual recording/stub implementations
25
+
26
+
TableTest usage
27
+
Dependency, if missing add:
28
+
- Groovy: testImplementation libs.tabletest
29
+
- Kotlin: testImplementation(libs.tabletest)
30
+
31
+
Import: `import org.tabletest.junit.TableTest;`
32
+
33
+
JDK 8 rules:
34
+
- No text blocks.
35
+
- @TableTest must use String[] annotation array syntax: `@TableTest({ "a | b", "1 | 2" })`
36
+
37
+
Spock `where:` → @TableTest:
38
+
- First row = header (column names = method parameters).
39
+
- Add `scenario` column as first column (display name, not a method parameter).
40
+
- Use `|` delimiter; align columns so pipes line up vertically.
41
+
- Prefer single quotes for strings with special chars (e.g., `'a|b'`, `'[]'`).
description: Convert JUnit 5 @MethodSource/@CsvSource/@ValueSource parameterized tests to @TableTest (JDK8)
4
+
---
5
+
Goal: Migrate JUnit 5 parameterized tests using @MethodSource/@CsvSource/@ValueSource to @TableTest with minimal churn and passing tests.
6
+
7
+
Process (do in this order):
8
+
1) Locate targets via Grep (no agent subprocess). Search for: "@ParameterizedTest", "@MethodSource", "@CsvSource", "@ValueSource".
9
+
2) Read all matching files up front (parallel is OK).
10
+
3) Convert eligible tests to @TableTest.
11
+
4) Write each modified file once in full using Write (no incremental per-test edits).
12
+
5) Run module tests once and verify "BUILD SUCCESSFUL". If failed, inspect JUnit XML report.
13
+
14
+
Dependency:
15
+
- If missing, add:
16
+
- Groovy: testImplementation libs.tabletest
17
+
- Kotlin: testImplementation(libs.tabletest)
18
+
19
+
Import:
20
+
- Ensure: import org.tabletest.junit.TableTest;
21
+
22
+
JDK 8 rules:
23
+
- No text blocks.
24
+
-@TableTest must use String[] annotation array syntax:
25
+
@TableTest({ "a | b", "1 | 2" })
26
+
27
+
Table formatting rules (mandatory):
28
+
- Always include a header row (parameter names).
29
+
- Always add a "scenario" column; using common sense for naming; scenario is NOT a method parameter.
30
+
- Use '|' as delimiter.
31
+
- Align columns with spaces so pipes line up vertically.
32
+
- Prefer single quotes for strings requiring quotes (e.g., 'a|b', '[]', '{}', ' ').
33
+
34
+
Conversions:
35
+
A) @CsvSource
36
+
- Remove @ParameterizedTest and @CsvSource.
37
+
- If delimiter is '|': rows map directly to @TableTest.
38
+
- If delimiter is ',' (default): replace ',' with '|' in rows.
39
+
40
+
B) @ValueSource
41
+
- Convert to @TableTest with header from parameter name.
42
+
- Each value becomes one row.
43
+
- Add "scenario" column using common sense for name.
44
+
45
+
C) @MethodSource (convert only if values are representable as strings)
46
+
- Convert when argument values are primitives, strings, enums, booleans, nulls, and simple collection literals supported by TableTest:
47
+
- Array: [a, b, ...]
48
+
- List: [a, b, ...]
49
+
- Set: {a, b, ...}
50
+
- Map: [k: v, ...]
51
+
- Blank cell = null (non-primitive).
52
+
- '' = empty string.
53
+
- For String params that start with '[' or '{', quote to avoid collection parsing (prefer '[]'/'{}').
54
+
55
+
Scenario handling:
56
+
- If MethodSource includes a leading description string OR @ParameterizedTest(name=...) uses {0}, convert that to a scenario column and remove that parameter from method signature.
57
+
58
+
Cleanup:
59
+
- Delete now-unused @MethodSource provider methods and unused imports.
60
+
61
+
Mixed eligibility:
62
+
- If only a few cases need complex construction, split:
63
+
- Simple cases ⇒ @TableTest
64
+
- Complex cases ⇒ separate @Test(s) (descriptive names) OR keep a small @MethodSource.
65
+
66
+
Do NOT convert when:
67
+
- Most rows require complex builders/mocks.
68
+
- Parameters are arrays (String[], int[]) — keep @MethodSource (or refactor to List to convert).
0 commit comments