Skip to content

Commit 93ab934

Browse files
committed
Address review comments
1 parent 2f706c9 commit 93ab934

File tree

9 files changed

+119
-132
lines changed

9 files changed

+119
-132
lines changed

.claude/skills/migrate-groovy-to-java/SKILL.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ When converting Groovy code to Java code, make sure that:
3232
- When translating Spock `Mock(...)` usage, use `libs.bundles.mockito` instead of writing manual recording/stub implementations
3333

3434
TableTest usage
35-
Dependency, if missing add:
36-
- Groovy: testImplementation libs.tabletest
37-
- Kotlin: testImplementation(libs.tabletest)
38-
3935
Import: `import org.tabletest.junit.TableTest;`
4036

4137
JDK 8 rules:

.claude/skills/migrate-junit-source-to-tabletest/SKILL.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ Process (do in this order):
1111
4) Write each modified file once in full using Write (no incremental per-test edits).
1212
5) Run module tests once and verify "BUILD SUCCESSFUL". If failed, inspect JUnit XML report.
1313

14-
Dependency:
15-
- @TableTest should be in `gradle/java_deps.gradle` as `testImplementation libs.tabletest` where Java modules inherit it via `gradle/java.gradle`.
16-
- As a fallback, add module-specific `testImplementation(libs.tabletest)` or `testImplementation libs.tabletest`.
17-
1814
Import: `import org.tabletest.junit.TableTest;`
1915

2016
JDK 8 rules:
@@ -41,7 +37,8 @@ A) @CsvSource
4137
- If delimiter is ',' (default): replace ',' with '|' in rows.
4238

4339
B) @ValueSource
44-
- Convert to @TableTest with header from parameter name.
40+
- Keep single-parameter tests on `@ValueSource` (and `@NullSource` when null cases are needed).
41+
- Otherwise convert to @TableTest with header from parameter name.
4542
- Each value becomes one row.
4643
- Add "scenario" column using common sense for name.
4744

@@ -59,6 +56,11 @@ C) @MethodSource (convert only if values are representable as strings)
5956
- '' = empty string.
6057
- For String params that start with '[' or '{', quote to avoid collection parsing (prefer '[]'/'{}').
6158

59+
D) @TypeConverter
60+
- Use `@TypeConverter` for symbolic constants used by migrated table rows (e.g. `Long.MAX_VALUE`, `DDSpanId.MAX`).
61+
- Prefer explicit one-case-one-return mappings.
62+
- Prefer shared converter utilities (e.g. in `utils/test-utils`) when reuse across modules is likely.
63+
6264
Scenario handling:
6365
- 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.
6466

components/json/build.gradle.kts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,3 @@ apply(from = "$rootDir/gradle/java.gradle")
77
jmh {
88
jmhVersion = libs.versions.jmh.get()
99
}
10-
11-
dependencies {
12-
testImplementation(libs.tabletest)
13-
}

components/json/src/test/java/datadog/json/JsonMapperTest.java

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import org.junit.jupiter.params.ParameterizedTest;
1818
import org.junit.jupiter.params.provider.Arguments;
1919
import org.junit.jupiter.params.provider.MethodSource;
20+
import org.junit.jupiter.params.provider.NullSource;
21+
import org.junit.jupiter.params.provider.ValueSource;
2022
import org.tabletest.junit.Scenario;
2123
import org.tabletest.junit.TableTest;
2224

@@ -77,28 +79,16 @@ static Stream<Arguments> testMappingToJsonObjectArguments() {
7779
"{\"key1\":null,\"key2\":\"bar\",\"key3\":3,\"key4\":3456789123,\"key5\":3.142,\"key6\":3.141592653589793,\"key7\":true,\"key8\":\"toString\"}"));
7880
}
7981

80-
@TableTest({
81-
"Scenario | Json ",
82-
"null | ",
83-
"null string | 'null'",
84-
"empty string | '' ",
85-
"empty object | '{}' "
86-
})
8782
@ParameterizedTest(name = "test mapping to Map from empty JSON object: {0}")
83+
@NullSource
84+
@ValueSource(strings = {"null", "", "{}"})
8885
void testMappingToMapFromEmptyJsonObject(String json) throws IOException {
8986
Map<String, Object> parsed = JsonMapper.fromJsonToMap(json);
9087
assertEquals(emptyMap(), parsed);
9188
}
9289

93-
// temporary disable spotless, will open issue to fix this.
94-
// spotless:off
95-
@TableTest({
96-
"Scenario | Json ",
97-
"integer | 1 ",
98-
"array | [1, 2]"
99-
})
100-
// spotless:on
10190
@ParameterizedTest(name = "test mapping to Map from non-object JSON: {0}")
91+
@ValueSource(strings = {"1", "[1, 2]"})
10292
void testMappingToMapFromNonObjectJson(String json) {
10393
assertThrows(IOException.class, () -> JsonMapper.fromJsonToMap(json));
10494
}
@@ -138,14 +128,9 @@ void testMappingArrayToJsonArray(String ignoredScenario, String[] input, String
138128
assertArrayEquals(input != null ? input : new String[] {}, parsed);
139129
}
140130

141-
@TableTest({
142-
"Scenario | Json ",
143-
"null | ",
144-
"null string | 'null'",
145-
"empty string | '' ",
146-
"empty array | '[]' "
147-
})
148131
@ParameterizedTest(name = "test mapping to List from empty JSON object: {0}")
132+
@NullSource
133+
@ValueSource(strings = {"null", "", "[]"})
149134
void testMappingToListFromEmptyJsonObject(String json) throws IOException {
150135
List<String> parsed = JsonMapper.fromJsonToList(json);
151136
assertEquals(emptyList(), parsed);

dd-trace-api/src/test/java/datadog/trace/api/DDSpanIdTest.java

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,25 @@
77
import static org.junit.jupiter.api.Assertions.assertNull;
88
import static org.junit.jupiter.api.Assertions.assertThrows;
99

10+
import datadog.trace.test.util.TableTestTypeConverters;
1011
import java.util.HashSet;
1112
import java.util.Set;
1213
import org.junit.jupiter.params.ParameterizedTest;
14+
import org.junit.jupiter.params.provider.NullSource;
15+
import org.junit.jupiter.params.provider.ValueSource;
1316
import org.tabletest.junit.TableTest;
17+
import org.tabletest.junit.TypeConverterSources;
1418

19+
@TypeConverterSources(TableTestTypeConverters.class)
1520
class DDSpanIdTest {
1621

1722
@TableTest({
1823
"scenario | stringId | expectedId ",
1924
"zero | '0' | 0 ",
2025
"one | '1' | 1 ",
21-
"max | '18446744073709551615' | -1 ",
22-
"long max | '9223372036854775807' | 9223372036854775807 ",
23-
"long max plus one | '9223372036854775808' | -9223372036854775808"
26+
"max | '18446744073709551615' | DDSpanId.MAX ",
27+
"long max | '9223372036854775807' | Long.MAX_VALUE ",
28+
"long max plus one | '9223372036854775808' | Long.MIN_VALUE "
2429
})
2530
@ParameterizedTest
2631
void convertIdsFromToString(String stringId, long expectedId) {
@@ -30,18 +35,18 @@ void convertIdsFromToString(String stringId, long expectedId) {
3035
assertEquals(stringId, DDSpanId.toString(ddid));
3136
}
3237

33-
@TableTest({
34-
"scenario | stringId ",
35-
"null | ",
36-
"empty | '' ",
37-
"negative one | '-1' ",
38-
"too large | '18446744073709551616'",
39-
"too large variant | '18446744073709551625'",
40-
"too large long | '184467440737095516150'",
41-
"contains alpha first | '18446744073709551a1' ",
42-
"contains alpha last | '184467440737095511a' "
43-
})
4438
@ParameterizedTest
39+
@NullSource
40+
@ValueSource(
41+
strings = {
42+
"",
43+
"-1",
44+
"18446744073709551616",
45+
"18446744073709551625",
46+
"184467440737095516150",
47+
"18446744073709551a1",
48+
"184467440737095511a"
49+
})
4550
void failOnIllegalString(String stringId) {
4651
assertThrows(NumberFormatException.class, () -> DDSpanId.from(stringId));
4752
}
@@ -50,10 +55,10 @@ void failOnIllegalString(String stringId) {
5055
"scenario | hexId | expectedId ",
5156
"zero | '0' | 0 ",
5257
"one | '1' | 1 ",
53-
"max | 'ffffffffffffffff' | -1 ",
54-
"long max | '7fffffffffffffff' | 9223372036854775807 ",
55-
"long min | '8000000000000000' | -9223372036854775808",
56-
"long min with leading zeros | '00008000000000000000' | -9223372036854775808",
58+
"max | 'ffffffffffffffff' | DDSpanId.MAX ",
59+
"long max | '7fffffffffffffff' | Long.MAX_VALUE ",
60+
"long min | '8000000000000000' | Long.MIN_VALUE ",
61+
"long min with leading zeros | '00008000000000000000' | Long.MIN_VALUE ",
5762
"cafebabe | 'cafebabe' | 3405691582 ",
5863
"fifteen hex digits | '123456789abcdef' | 81985529216486895 "
5964
})
@@ -73,17 +78,17 @@ void convertIdsFromToHexString(String hexId, long expectedId) {
7378
}
7479

7580
@TableTest({
76-
"scenario | hexId | start | length | lowerCaseOnly | expectedId",
77-
"null input | | 1 | 1 | false | ",
78-
"empty input | '' | 1 | 1 | false | ",
79-
"negative start | '00' | -1 | 1 | false | ",
80-
"zero length | '00' | 0 | 0 | false | ",
81-
"single zero at index 0 | '00' | 0 | 1 | false | 0 ",
82-
"single zero at index 1 | '00' | 1 | 1 | false | 0 ",
83-
"single zero at index 1 duplicate | '00' | 1 | 1 | false | 0 ",
84-
"max lower-case | 'ffffffffffffffff' | 0 | 16 | true | -1 ",
85-
"upper-case rejected when lower-case only| 'ffffffffffffFfff' | 0 | 16 | true | ",
86-
"upper-case accepted when lower disabled | 'ffffffffffffFfff' | 0 | 16 | false | -1 "
81+
"scenario | hexId | start | length | lowerCaseOnly | expectedId ",
82+
"null input | | 1 | 1 | false | ",
83+
"empty input | '' | 1 | 1 | false | ",
84+
"negative start | '00' | -1 | 1 | false | ",
85+
"zero length | '00' | 0 | 0 | false | ",
86+
"single zero at index 0 | '00' | 0 | 1 | false | DDSpanId.ZERO",
87+
"single zero at index 1 | '00' | 1 | 1 | false | DDSpanId.ZERO",
88+
"single zero at index 1 duplicate | '00' | 1 | 1 | false | DDSpanId.ZERO",
89+
"max lower-case | 'ffffffffffffffff' | 0 | 16 | true | DDSpanId.MAX ",
90+
"upper-case rejected when lower-case only| 'ffffffffffffFfff' | 0 | 16 | true | ",
91+
"upper-case accepted when lower disabled | 'ffffffffffffFfff' | 0 | 16 | false | DDSpanId.MAX "
8792
})
8893
@ParameterizedTest
8994
void convertIdsFromPartOfHexString(
@@ -102,27 +107,15 @@ void convertIdsFromPartOfHexString(
102107
}
103108
}
104109

105-
@TableTest({
106-
"scenario | hexId ",
107-
"null | ",
108-
"empty | '' ",
109-
"negative one | '-1' ",
110-
"too long | '10000000000000000'",
111-
"invalid middle | 'ffffffffffffffzf' ",
112-
"invalid tail | 'fffffffffffffffz' "
113-
})
114110
@ParameterizedTest
111+
@NullSource
112+
@ValueSource(strings = {"", "-1", "10000000000000000", "ffffffffffffffzf", "fffffffffffffffz"})
115113
void failOnIllegalHexString(String hexId) {
116114
assertThrows(NumberFormatException.class, () -> DDSpanId.fromHex(hexId));
117115
}
118116

119-
@TableTest({
120-
"scenario | strategyName ",
121-
"random | RANDOM ",
122-
"sequential | SEQUENTIAL ",
123-
"secure random | SECURE_RANDOM"
124-
})
125117
@ParameterizedTest
118+
@ValueSource(strings = {"RANDOM", "SEQUENTIAL", "SECURE_RANDOM"})
126119
void generateIdWithStrategy(String strategyName) {
127120
IdGenerationStrategy strategy = IdGenerationStrategy.fromName(strategyName);
128121
Set<Long> checked = new HashSet<Long>();

0 commit comments

Comments
 (0)