Skip to content

Commit b9209ad

Browse files
committed
Replace mocked FixExecution with a real record in DataFixerEndpointTest
- Updated `DataFixerEndpointTest` to use a real `FixExecution` record instead of a mock, as records are final and cannot be mocked. - Populated the `FixExecution` with realistic field operations to improve test accuracy and coverage. Signed-off-by: Erik Pförtner <splatcrafter@splatgames.de>
1 parent e28800d commit b9209ad

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

aether-datafixers-spring-boot-starter/src/test/java/de/splatgames/aether/datafixers/spring/actuator/DataFixerEndpointTest.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,19 +238,38 @@ void includesDiagnosticsFromStore() {
238238
when(fixer.currentVersion()).thenReturn(new DataVersion(200));
239239
reg.register("game", fixer);
240240

241-
// Create a mock MigrationReport
241+
// Build a real FixExecution record (records are final, so they cannot be mocked)
242+
// carrying two field operations.
243+
RuleApplication ruleApp = new RuleApplication(
244+
"renameAndRemove",
245+
"player",
246+
Instant.now(),
247+
Duration.ofMillis(5),
248+
true,
249+
null,
250+
List.of(
251+
FieldOperation.rename("oldName", "newName"),
252+
FieldOperation.remove("deprecated")
253+
)
254+
);
255+
FixExecution fix = new FixExecution(
256+
"test_fix",
257+
new DataVersion(100),
258+
new DataVersion(200),
259+
Instant.now(),
260+
Duration.ofMillis(20),
261+
List.of(ruleApp),
262+
null,
263+
null
264+
);
265+
266+
// The MigrationReport interface is mockable; only the concrete records are not.
242267
MigrationReport report = mock(MigrationReport.class);
243268
when(report.fromVersion()).thenReturn(new DataVersion(100));
244269
when(report.toVersion()).thenReturn(new DataVersion(200));
245270
when(report.totalDuration()).thenReturn(Duration.ofMillis(42));
246271
when(report.fixCount()).thenReturn(1);
247272
when(report.totalFieldOperationCount()).thenReturn(2);
248-
249-
FixExecution fix = mock(FixExecution.class);
250-
when(fix.allFieldOperations()).thenReturn(List.of(
251-
FieldOperation.rename("oldName", "newName"),
252-
FieldOperation.remove("deprecated")
253-
));
254273
when(report.fixExecutions()).thenReturn(List.of(fix));
255274
store.store("game", report);
256275

0 commit comments

Comments
 (0)