Skip to content

Migrate 33 Kotlin data-driven tests to @ObjectSource #271

@em3s

Description

@em3s

Background

#268 codified: if a test is data-driven, use @ObjectSource.

#273 adds a companion annotation, @TableSource, for dense primitive matrices — same Jackson pipeline, same name-based parameter binding, CSV-like density. Together they form the data-driven family:

  • @ObjectSource — nested / heterogeneous / single-case data
  • @TableSource — dense primitive matrices (state machines, combinatorial tables)

An automated audit of all 145 test files found 72 convertible and 49 not (Graph/HBase fixtures, contract suites, Spring/E2E, mocks).

Scope limited to Kotlin

@ObjectSource/@TableSource both use kotlin.reflect.full.memberFunctions to map YAML keys to parameter names, and the project does not compile Java with -parameters, so Java parameter names are erased to arg0, arg1, … at runtime.

This issue therefore tracks 33 Kotlin files only. The remaining 39 Java files (core-java 34, codec-java 5) wait for a separate infrastructure PR that extends the annotations to Java (enable -parameters and add Java-reflection fallback).

Prerequisite

Phases

Each phase is one PR (<500 LOC diff target). Tick files off as they land.

Phase 1 — Kotlin already-parameterized (5)

Migrate existing @CsvSource / @MethodSource to @TableSource (or @ObjectSource for non-tabular shapes). The density stays CSV-like and test bodies can drop string-parsing helpers (toBooleanFlexible, toStateValue, toEventType, toEventSequence, handleSpecialValue) once a Jackson module is registered for the domain types.

  • core/src/test/kotlin/.../state/ComplexTransitionTest.kt (@MethodSource@TableSource or @ObjectSource)
  • core/src/test/kotlin/.../state/ProcessingOrderTest.kt (@CsvSource 41 × 14 → @TableSource)
  • core/src/test/kotlin/.../state/SingleTransitionTest.kt (@CsvSource 41 × 32 → @TableSource)
  • core/src/test/kotlin/.../test/state/CombinatoricsTest.kt (@CsvSource@TableSource or @MethodSource if cases are computed)
  • server/src/test/kotlin/.../filter/ReadOnlyRequestFilterTest.kt (@MethodSource — may stay if cases are computed from endpoint sets)

Alongside this phase, register Jackson deserializers for State, StateValue, EventType, and any other domain types touched by the migrated tests. This is what enables the helper removal above.

Phase 2 — core module non-parameterized (17)

Serialization, mutation builder, mapper, payload tests. Currently multi-@Test with similar assertion shape; convert to a single @ObjectSource (nested payloads) or @TableSource (primitive matrix) method per group.

  • core/.../KotlinCoreJvmRuntimeTest.kt
  • core/bulkload/V2MultiEdgeBulkLoadTest.kt
  • core/edge/mapper/EdgeCacheRecordMapperTest.kt
  • core/edge/mutation/EdgeMutationBuilderTest.kt (31 tests)
  • core/edge/mutation/EdgeMutationStrategyTest.kt (15 tests)
  • core/metadata/AliasSerializationTest.kt
  • core/metadata/DatabaseSerializationTest.kt
  • core/metadata/DatastoreSerializationTest.kt
  • core/metadata/TableSerializationTest.kt
  • core/metadata/common/EdgeSchemaSerializationTest.kt
  • core/payload/EdgeBulkMutationRequestTest.kt
  • core/v2/metadata/V2AliasSerializationTest.kt
  • core/v2/metadata/V2LabelSerializationTest.kt
  • core/v2/metadata/V2ServiceSerializationTest.kt
  • core/v2/metadata/V2StorageSerializationTest.kt
  • core/test/ApiTestExtensionsTest.kt
  • core/test/json/PrettyObjectWriterTest.kt (18 tests)

Phase 3 — engine + server stragglers (11)

Engine non-fixture tests and the one remaining server unit. Four Kotest Spec files under v2/engine/v3/query/ are included — migrating them also removes Kotest from that subdirectory.

  • engine/core/time/TimestampUtilTest.kt
  • engine/experiments/reactor/RetryBehaviorExperimentTest.kt
  • engine/util/ReactorExtensionsTest.kt
  • engine/v2/engine/compat/DefaultHBaseClusterTest.kt
  • engine/v2/engine/v3/V2BackedMessageBindingTest.kt
  • engine/v2/engine/v3/V2BackedTableBindingTest.kt (18 tests)
  • engine/v2/engine/v3/query/ActionbaseQueryExecutorAggregatorSpec.kt (Kotest)
  • engine/v2/engine/v3/query/ActionbaseQueryExecutorPostProcessJsonObjectSpec.kt (Kotest)
  • engine/v2/engine/v3/query/ActionbaseQueryExecutorPostProcessSplitExplodeSpec.kt (Kotest)
  • engine/v2/engine/v3/query/ActionbaseQueryParserSpec.kt (Kotest)
  • server/api/graph/v3/metadata/MetadataStatusTest.kt

Guidance: @ObjectSource vs @TableSource

Shape Use
Heterogeneous / nested payloads, single scenario, shared fields @ObjectSource
Dense primitive matrix (≥ ~5 columns), state machines, combinatorial tables @TableSource
Cases must be generated at runtime (combinatorics, config-derived) @ParameterizedTest + @MethodSource (escape hatch)

Acceptance

  • All 33 Kotlin files migrated
  • rg "@CsvSource|@ValueSource" core engine server (Kotlin-only paths) returns 0
  • ./gradlew test green
  • Test count preserved per PR (document before: N / after: N in each PR body)
  • String-parsing helpers in state-transition tests (toBooleanFlexible, toStateValue, toEventType, toEventSequence, handleSpecialValue) removed when no longer referenced

Out of scope (separate issues)

  • 39 Java files (core-java 34, codec-java 5). Requires extending @ObjectSource/@TableSource to support Java reflection (enable -parameters project-wide and add a Java-reflection fallback in ObjectSourceExtension). Follow-up issue after that PR lands.
  • The 49 non-convertible files (Graph/HBase fixtures, contract suites, Spring/E2E). Separate pattern TBD.
  • Kotest removal from fixture-heavy engine Spec files (separate track).
  • AssertJ removal from server tests (separate track).
  • *Spec.kt*Test.kt renaming (separate cleanup).
  • Rename of ObjectSourceExtension now that it handles both sources (separate PR).

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions