package com.battery.business.report; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; import java.util.*; import com.battery.business.domain.*; import com.battery.business.service.*; import org.junit.jupiter.api.Test; class CompareMergedSourcesTest { @Test void selectingSourcesUsesSavedMergeAndPreviewIncludesItsActualSteps() { var tests = mock(ITTestService.class); var data = mock(ITestDataQueryService.class); var battery = new TTestBattery(); battery.setTestBatteryId(5L); battery.setGroupId(9L); battery.setBatteryNo("1号"); battery.setFields(List.of()); var test = new TTest(); test.setTestId(1L); test.setTestStatus("COMPLETED"); test.setBatteries(List.of(battery)); test.setLogicStepMappings(List.of()); when(tests.selectTestList(any())).thenReturn(List.of(test)); when(tests.selectTestById(1L)).thenReturn(test); var records = List.of(Map.of("batteryNo", "1号", "cycleNo", 3, "stepNo", 10, "deviceTime", 1000L), Map.of("batteryNo", "1号", "cycleNo", 3, "stepNo", 11, "deviceTime", 2000L)); when(data.records(1L)).thenReturn(records); var service = new CompareReportService(tests, data, null); var actual = service.sources(); assertEquals(2, actual.size()); var mapping = new TTestLogicStepMapping(); mapping.setLogicalNo(1); mapping.setLogicalName("合并充电"); mapping.setStartStepNo(1); mapping.setEndStepNo(2); test.setLogicStepMappings(List.of(mapping)); var merged = service.sources(); assertEquals(1, merged.size()); assertEquals(1, merged.get(0).selection().logicalNo()); assertNull(merged.get(0).selection().stepNo()); assertTrue(merged.get(0).process().contains("合并充电")); var preview = service.preview(List.of(merged.get(0).selection())); assertEquals(records, preview.get(0).records()); assertEquals(1000, preview.get(0).zeroTime()); assertEquals(1, service.preview(List.of(actual.get(0).selection())).get(0).records().size(), "旧版来源仍可明确刷新原实际工步"); } }