yeg
2026-09-05 acfb83068486766f63284b479d30f78e3ec17dca
ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/TTestServiceImplTest.java
@@ -3,12 +3,14 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.times;
@@ -22,10 +24,6 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import com.ruoyi.device.bts.BtsDevelopmentSimulator;
import com.ruoyi.device.simulator.DevelopmentCollectorSimulation.CollectorRealtimeSnapshot;
import com.ruoyi.device.simulator.BtsSimulatorStateStore.CollectorRealtimeMeasurement;
import org.springframework.dao.DuplicateKeyException;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.system.domain.TTest;
import com.ruoyi.system.domain.TTestBattery;
@@ -35,7 +33,6 @@
import com.ruoyi.system.domain.TTestPlanStep;
import com.ruoyi.system.domain.TTestWarningThreshold;
import com.ruoyi.system.domain.TDetectionChannel;
import com.ruoyi.system.domain.TTestReceptionInterval;
import com.ruoyi.system.mapper.TTestMapper;
import com.ruoyi.system.service.ISharedFieldSnapshotService;
@@ -49,9 +46,6 @@
    @Mock
    private ISharedFieldSnapshotService sharedFieldSnapshotService;
    @Mock
    private BtsDevelopmentSimulator collectorSimulator;
    @InjectMocks
    private TTestServiceImpl testService;
@@ -60,7 +54,6 @@
    {
        TTest test = validTest();
        mockEnabledOptions();
        mockGroupSnapshot();
        when(testMapper.insertTest(any(TTest.class))).thenAnswer(invocation -> {
            invocation.<TTest>getArgument(0).setTestId(10L);
            return 1;
@@ -74,12 +67,12 @@
        assertEquals("WAITING", test.getTestStatus());
        assertEquals("NOT_STARTED", test.getReceptionStatus());
        assertEquals(7L, test.getCreatorId());
        verify(testMapper).insertTestPlanStep(any(TTestPlanStep.class));
        verify(testMapper, never()).insertTestPlanStep(any(TTestPlanStep.class));
        verify(testMapper).insertTestChannelBinding(any(TTestChannelBinding.class));
        verify(testMapper, times(3)).insertTestCollectorChannel(any(TTestCollectorChannel.class));
        verify(sharedFieldSnapshotService).saveForTest(eq(10L), any());
        verify(sharedFieldSnapshotService, never()).saveForTest(anyLong(), any());
        verify(testMapper).insertTestThreshold(any(TTestWarningThreshold.class));
        verify(testMapper).insertTestAudit(anyLong(), any(), anyLong(), any(), isNull(), any());
        verify(testMapper, never()).insertTestAudit(anyLong(), any(), anyLong(), any(), isNull(), any());
    }
    @Test
@@ -139,7 +132,6 @@
        TTest test = validTest();
        test.setPlanSteps(Collections.emptyList());
        mockEnabledOptions();
        mockGroupSnapshot();
        when(testMapper.insertTest(any(TTest.class))).thenAnswer(invocation -> {
            invocation.<TTest>getArgument(0).setTestId(10L);
            return 1;
@@ -232,6 +224,20 @@
    }
    @Test
    void createShouldRejectCaseInsensitiveDuplicateCollectorMeasurement()
    {
        TTest test = validTest();
        test.getBatteries().get(0).getCollectorChannels()
                .add(collectorChannel("primary_temperature", "主温度重复", "S-04"));
        mockEnabledOptions();
        ServiceException exception = assertThrows(ServiceException.class, () -> testService.createTest(test));
        assertEquals("同一电池号的采集器测量项不可重复", exception.getMessage());
        verify(testMapper, never()).insertTest(any(TTest.class));
    }
    @Test
    void createShouldRejectBatteriesFromDifferentGroups()
    {
        TTest test = validTest();
@@ -296,9 +302,6 @@
        current.setMonitorTimeoutMinutes(30);
        when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
        when(testMapper.selectTestBatteries(10L)).thenReturn(current.getBatteries());
        when(sharedFieldSnapshotService.selectByTestId(10L)).thenReturn(java.util.List.of());
        when(sharedFieldSnapshotService.resolveForUpdate(1L, 1L, java.util.List.of()))
                .thenReturn(java.util.List.of());
        mockEnabledOptions();
        when(testMapper.updateTest(request)).thenReturn(1);
        doAnswer(invocation -> {
@@ -309,8 +312,8 @@
        assertEquals(1, testService.updateTest(request));
        assertEquals(45, request.getMonitorTimeoutMinutes());
        verify(testMapper).deleteTestBindingsByTestId(10L);
        verify(testMapper).deleteTestPlanStepsByTestId(10L);
        verify(testMapper).insertTestAudit(anyLong(), any(), anyLong(), any(), any(), any());
        verify(testMapper, never()).deleteTestPlanStepsByTestId(10L);
        verify(testMapper, never()).insertTestAudit(anyLong(), any(), anyLong(), any(), any(), any());
    }
    @Test
@@ -330,9 +333,6 @@
        when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
        when(testMapper.selectTestBatteries(10L)).thenReturn(current.getBatteries());
        when(sharedFieldSnapshotService.selectByTestId(10L)).thenReturn(java.util.List.of(originalSnapshot));
        when(sharedFieldSnapshotService.resolveForUpdate(1L, 1L, java.util.List.of(originalSnapshot)))
                .thenReturn(java.util.List.of(originalSnapshot));
        mockEnabledOptions();
        when(testMapper.updateTest(request)).thenReturn(1);
        doAnswer(invocation -> {
@@ -342,9 +342,7 @@
        assertEquals(1, testService.updateTest(request));
        verify(sharedFieldSnapshotService).resolveForUpdate(1L, 1L, java.util.List.of(originalSnapshot));
        verify(sharedFieldSnapshotService).saveForTest(eq(10L), org.mockito.ArgumentMatchers.argThat(snapshots ->
                snapshots.size() == 1 && "72".equals(snapshots.get(0).getFieldValue())));
        verifyNoInteractions(sharedFieldSnapshotService);
    }
    @Test
@@ -358,14 +356,31 @@
        assertEquals(1, testService.deleteTestByIds(new Long[] { 10L }, 7L, "operator"));
        verify(testMapper).insertTestAudit(eq(10L), eq("TEST_DELETED"), eq(7L), eq("operator"), any(), isNull());
        verify(testMapper, never()).insertTestAudit(anyLong(), any(), anyLong(), any(), any(), any());
    }
    @Test
    void startReceptionShouldOpenAllSourceIntervalsAtomically()
    void deleteShouldRejectMismatchedTestAndReceptionStates()
    {
        TTest current = validTest();
        current.setTestId(10L);
        current.setTestStatus("RUNNING");
        current.setReceptionStatus("NOT_STARTED");
        when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
        ServiceException exception = assertThrows(ServiceException.class,
                () -> testService.deleteTestByIds(new Long[] { 10L }, 7L, "operator"));
        assertEquals("开始接收后不能删除测试", exception.getMessage());
        verify(testMapper, never()).deleteTestById(anyLong(), any(String.class));
    }
    @Test
    void startReceptionShouldPersistReceptionWithoutLegacyIntervals()
    {
        TTest current = validTest();
        current.setTestId(10L);
        current.setTestStatus("WAITING");
        current.setReceptionStatus("NOT_STARTED");
        current.getBatteries().get(0).getBinding().setBindingId(30L);
        when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
@@ -376,13 +391,9 @@
        when(testMapper.selectReceptionChannelForUpdate(100L)).thenReturn(channel);
        when(testMapper.countCollectorEnabled(8L)).thenReturn(1);
        when(testMapper.selectCollectorChannelCount(8L)).thenReturn(4);
        when(testMapper.collectorOnline(8L)).thenReturn(true);
        when(testMapper.updateReceptionStarted(eq(10L), any(), eq("operator"))).thenReturn(1);
        when(testMapper.updateReceptionStarted(eq(10L), any(), anyBoolean(), eq("operator"))).thenReturn(1);
        assertEquals(1, testService.startReception(10L, 7L, "operator"));
        verify(testMapper).insertChannelLease(eq(100L), eq(10L), eq(30L), eq(7L), any());
        verify(testMapper, times(3)).insertCollectorChannelLease(eq(8L), any(), eq(10L), eq(30L), eq(7L), any());
        verify(testMapper, times(4)).insertReceptionInterval(any());
        verify(testMapper).insertTestAudit(eq(10L), eq("RECEPTION_STARTED"), eq(7L), eq("operator"), isNull(), any());
    }
@@ -391,6 +402,7 @@
    {
        TTest current = validTest();
        current.setTestId(10L);
        current.setTestStatus("WAITING");
        current.setReceptionStatus("NOT_STARTED");
        current.getBatteries().get(0).getBinding().setBindingId(30L);
        when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
@@ -402,20 +414,20 @@
        when(testMapper.selectReceptionChannelForUpdate(100L)).thenReturn(channel);
        when(testMapper.countCollectorEnabled(8L)).thenReturn(1);
        when(testMapper.selectCollectorChannelCount(8L)).thenReturn(4);
        when(testMapper.collectorOnline(8L)).thenReturn(true);
        when(testMapper.updateReceptionStarted(eq(10L), any(), eq("operator"))).thenReturn(1);
        when(testMapper.updateReceptionStarted(eq(10L), any(), anyBoolean(), eq("operator"))).thenReturn(1);
        assertEquals(1, testService.startReception(10L, 7L, "operator"));
        verify(testMapper).insertTestAudit(eq(10L), eq("RECEPTION_STARTED"), eq(7L), eq("operator"), isNull(),
                org.mockito.ArgumentMatchers.argThat(value -> value != null && value.contains("runtimeAttach")
                        && value.contains("运行中接入")));
                        && value.contains("true")));
    }
    @Test
    void startReceptionShouldRollbackWhenDatabaseLeaseIsTaken()
    void startReceptionShouldNotDependOnDatabaseLease()
    {
        TTest current = validTest();
        current.setTestId(10L);
        current.setTestStatus("WAITING");
        current.setReceptionStatus("NOT_STARTED");
        current.getBatteries().get(0).getBinding().setBindingId(30L);
        when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
@@ -426,38 +438,50 @@
        when(testMapper.selectReceptionChannelForUpdate(100L)).thenReturn(channel);
        when(testMapper.countCollectorEnabled(8L)).thenReturn(1);
        when(testMapper.selectCollectorChannelCount(8L)).thenReturn(4);
        when(testMapper.collectorOnline(8L)).thenReturn(true);
        when(testMapper.insertChannelLease(any(), any(), any(), any(), any()))
                .thenThrow(new DuplicateKeyException("lease already exists"));
        when(testMapper.updateReceptionStarted(eq(10L), any(), anyBoolean(), eq("operator"))).thenReturn(1);
        ServiceException exception = assertThrows(ServiceException.class,
                () -> testService.startReception(10L, 7L, "operator"));
        assertEquals(1, testService.startReception(10L, 7L, "operator"));
        assertEquals("数据来源已被其他测试占用,请刷新后重试", exception.getMessage());
        verify(testMapper, never()).insertReceptionInterval(any());
        verify(testMapper, never()).updateReceptionStarted(any(), any(), any());
        verify(testMapper, never()).insertTestAudit(anyLong(), any(), anyLong(), any(), any(), any());
    }
    @Test
    void startReceptionShouldRejectOfflineSourceWithoutWritingAnything()
    void startReceptionShouldAllowOfflineSourcesWithoutBlockingReception()
    {
        TTest current = validTest();
        current.setTestId(10L);
        current.setTestStatus("WAITING");
        current.setReceptionStatus("NOT_STARTED");
        current.getBatteries().get(0).getBinding().setBindingId(30L);
        when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
        TDetectionChannel channel = new TDetectionChannel();
        channel.setChannelId(100L);
        channel.setOnlineStatus("OFFLINE");
        when(testMapper.selectReceptionChannelForUpdate(100L)).thenReturn(channel);
        when(testMapper.countCollectorEnabled(8L)).thenReturn(1);
        when(testMapper.selectCollectorChannelCount(8L)).thenReturn(4);
        when(testMapper.updateReceptionStarted(eq(10L), any(), anyBoolean(), eq("operator"))).thenReturn(1);
        ServiceException exception = assertThrows(ServiceException.class,
                () -> testService.startReception(10L, 7L, "operator"));
        assertEquals(1, testService.startReception(10L, 7L, "operator"));
    }
        assertEquals("检测柜通道 100 当前离线或不可观测", exception.getMessage());
        verify(testMapper, never()).insertChannelLease(any(), any(), any(), any(), any());
        verify(testMapper, never()).insertReceptionInterval(any());
        verify(testMapper, never()).updateReceptionStarted(any(), any(), any());
    @Test
    void startReceptionShouldAllowOfflineCollectorWithoutBlockingReception()
    {
        TTest current = validTest();
        current.setTestId(10L);
        current.setTestStatus("WAITING");
        current.setReceptionStatus("NOT_STARTED");
        current.getBatteries().get(0).getBinding().setBindingId(30L);
        when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
        TDetectionChannel channel = new TDetectionChannel();
        channel.setChannelId(100L);
        channel.setOnlineStatus("ONLINE");
        when(testMapper.selectReceptionChannelForUpdate(100L)).thenReturn(channel);
        when(testMapper.countCollectorEnabled(8L)).thenReturn(1);
        when(testMapper.selectCollectorChannelCount(8L)).thenReturn(4);
        when(testMapper.updateReceptionStarted(eq(10L), any(), anyBoolean(), eq("operator"))).thenReturn(1);
        assertEquals(1, testService.startReception(10L, 7L, "operator"));
    }
    @Test
@@ -465,6 +489,7 @@
    {
        TTest current = validTest();
        current.setTestId(10L);
        current.setTestStatus("WAITING");
        current.setReceptionStatus("NOT_STARTED");
        current.getBatteries().get(0).getBinding().setBindingId(30L);
        current.getBatteries().get(0).setCollectorChannels(Collections.emptyList());
@@ -475,15 +500,13 @@
        channel.setLastSeenAtUtc(Instant.parse("2026-08-29T12:00:00Z"));
        when(testMapper.selectReceptionChannelForUpdate(100L)).thenReturn(channel);
        when(testMapper.countCollectorEnabled(8L)).thenReturn(1);
        when(testMapper.collectorOnline(8L)).thenReturn(true);
        when(testMapper.selectCollectorChannelCount(8L)).thenReturn(4);
        ServiceException exception = assertThrows(ServiceException.class,
                () -> testService.startReception(10L, 7L, "operator"));
        assertEquals("每个电池号必须绑定主温度、正电位主通道和负电位主通道", exception.getMessage());
        verify(testMapper, never()).insertChannelLease(any(), any(), any(), any(), any());
        verify(testMapper, never()).updateReceptionStarted(any(), any(), any());
        verify(testMapper, never()).updateReceptionStarted(any(), any(), anyBoolean(), any());
    }
    @Test
@@ -497,88 +520,103 @@
    }
    @Test
    void pauseReceptionShouldCloseAllOpenIntervalsAndAppendAudit()
    void startReceptionShouldRejectMismatchedTestAndReceptionStates()
    {
        TTest current = validTest();
        current.setTestId(10L);
        current.setReceptionStatus("RECEIVING");
        current.setTestStatus("COMPLETED");
        current.setReceptionStatus("NOT_STARTED");
        when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
        TTestReceptionInterval cabinet = receptionInterval(1L, "CABINET_CHANNEL", 100L, null);
        TTestReceptionInterval collector = receptionInterval(2L, "COLLECTOR_CHANNEL", 8L, "S-01");
        when(testMapper.selectOpenReceptionIntervalsForUpdate(10L)).thenReturn(List.of(cabinet, collector));
        TDetectionChannel channel = new TDetectionChannel();
        channel.setChannelId(100L); channel.setOnlineStatus("ONLINE"); channel.setLastSeenAtUtc(Instant.parse("2026-08-29T12:00:00Z"));
        when(testMapper.selectReceptionChannelForUpdate(100L)).thenReturn(channel);
        when(testMapper.collectorOnline(8L)).thenReturn(true);
        mockCollectorBoundary();
        when(testMapper.closeReceptionInterval(anyLong(), any(), any())).thenReturn(1);
        when(testMapper.updateReceptionPaused(eq(10L), eq("operator"), any())).thenReturn(1);
        assertEquals(1, testService.pauseReception(10L, 7L, "operator"));
        verify(testMapper, times(2)).closeReceptionInterval(anyLong(), any(), any());
        verify(testMapper).updateReceptionPaused(eq(10L), eq("operator"), any());
        verify(testMapper).insertTestAudit(eq(10L), eq("RECEPTION_PAUSED"), eq(7L), eq("operator"), isNull(), any());
        ServiceException exception = assertThrows(ServiceException.class,
                () -> testService.startReception(10L, 7L, "operator"));
        assertEquals("当前测试不是未开始接收状态", exception.getMessage());
        verify(testMapper, never()).updateReceptionStarted(any(), any(), anyBoolean(), any());
    }
    @Test
    void pauseReceptionShouldFailBeforeWritesWhenBoundaryUnavailable()
    void pauseReceptionShouldRejectMismatchedTestAndReceptionStates()
    {
        TTest current = validTest();
        current.setTestId(10L); current.setReceptionStatus("RECEIVING");
        current.setTestId(10L);
        current.setTestStatus("PAUSED");
        current.setReceptionStatus("RECEIVING");
        when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
        TTestReceptionInterval interval = receptionInterval(1L, "CABINET_CHANNEL", 100L, null);
        when(testMapper.selectOpenReceptionIntervalsForUpdate(10L)).thenReturn(List.of(interval));
        when(testMapper.selectReceptionChannelForUpdate(100L)).thenReturn(null);
        ServiceException exception = assertThrows(ServiceException.class,
                () -> testService.pauseReception(10L, 7L, "operator"));
        assertEquals("检测柜通道 100 当前无法确认暂停接收边界", exception.getMessage());
        verify(testMapper, never()).closeReceptionInterval(anyLong(), any(), any());
        verify(testMapper, never()).updateReceptionPaused(anyLong(), any(), any());
        assertEquals("当前测试不是接收中状态", exception.getMessage());
        verify(testMapper, never()).updateReceptionPaused(any(), any(), any());
    }
    @Test
    void resumeReceptionShouldOpenNewIntervalsAndAppendAudit()
    void pauseReceptionShouldStopPollingAndAppendAudit()
    {
        TTest current = validTest();
        current.setTestId(10L); current.setReceptionStatus("PAUSED");
        current.getBatteries().get(0).getBinding().setBindingId(30L);
        current.setTestId(10L);
        current.setTestStatus("RUNNING");
        current.setReceptionStatus("RECEIVING");
        when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
        TDetectionChannel channel = new TDetectionChannel();
        channel.setChannelId(100L); channel.setOnlineStatus("ONLINE"); channel.setLastSeenAtUtc(Instant.parse("2026-08-29T12:00:00Z"));
        when(testMapper.selectReceptionChannelForUpdate(100L)).thenReturn(channel);
        when(testMapper.countCollectorEnabled(8L)).thenReturn(1);
        when(testMapper.collectorOnline(8L)).thenReturn(true);
        when(testMapper.selectCollectorChannelCount(8L)).thenReturn(4);
        mockCollectorBoundary();
        when(testMapper.updateReceptionPaused(eq(10L), eq("operator"), any())).thenReturn(1);
        assertEquals(1, testService.pauseReception(10L, 7L, "operator"));
        verify(testMapper).updateReceptionPaused(eq(10L), eq("operator"), any());
        verify(testMapper).insertTestAudit(eq(10L), eq("RECEPTION_PAUSED"), eq(7L), eq("operator"), isNull(),
                org.mockito.ArgumentMatchers.argThat(value -> value != null && value.contains("STOPPED")));
    }
    @Test
    void resumeReceptionShouldRestartPollingAndAppendAudit()
    {
        TTest current = validTest();
        current.setTestId(10L);
        current.setTestStatus("PAUSED");
        current.setReceptionStatus("PAUSED");
        List<TTestBattery> configuredBatteries = current.getBatteries();
        current.setBatteries(null);
        when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
        when(testMapper.selectTestBatteries(10L)).thenReturn(configuredBatteries);
        when(testMapper.updateReceptionResumed(eq(10L), eq("operator"), any())).thenReturn(1);
        assertEquals(1, testService.resumeReception(10L, 7L, "operator"));
        verify(testMapper, times(4)).insertReceptionInterval(any());
        verify(testMapper).updateReceptionResumed(eq(10L), eq("operator"), any());
        verify(testMapper).insertTestAudit(eq(10L), eq("RECEPTION_RESUMED"), eq(7L), eq("operator"), isNull(), any());
        verify(testMapper).insertTestAudit(eq(10L), eq("RECEPTION_RESUMED"), eq(7L), eq("operator"), isNull(),
                org.mockito.ArgumentMatchers.argThat(value -> value != null && value.contains("RESUMED")));
    }
    private TTestReceptionInterval receptionInterval(Long id, String sourceType, Long sourceId, String channelCode)
    @Test
    void stopTestShouldCompleteWithoutLegacyLeaseCleanup()
    {
        TTestReceptionInterval interval = new TTestReceptionInterval();
        interval.setIntervalId(id); interval.setTestId(10L); interval.setSourceType(sourceType);
        interval.setSourceId(sourceId); interval.setSourceChannelCode(channelCode); interval.setIntervalStatus("OPEN");
        return interval;
        TTest current = validTest();
        current.setTestId(10L);
        current.setTestStatus("PAUSED");
        current.setReceptionStatus("PAUSED");
        when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
        when(testMapper.updateReceptionStopped(eq(10L), eq("operator"), any())).thenReturn(1);
        assertEquals(1, testService.stopTest(10L, 7L, "operator"));
        verify(testMapper).updateReceptionStopped(eq(10L), eq("operator"), any());
        verify(testMapper).insertTestAudit(eq(10L), eq("TEST_STOPPED"), eq(7L), eq("operator"), isNull(),
                org.mockito.ArgumentMatchers.argThat(value -> value != null && value.contains("COMPLETED")));
    }
    private void mockCollectorBoundary()
    @Test
    void stopTestShouldAuditImmediateStop()
    {
        Instant deviceTime = Instant.parse("2026-08-29T12:00:00Z");
        CollectorRealtimeMeasurement measurement = new CollectorRealtimeMeasurement("dev-sim", "collector-8", "S-01",
                1L, deviceTime, "2026-08-29 20:00:00", deviceTime, "PRIMARY_TEMPERATURE", new BigDecimal("25"), "℃");
        CollectorRealtimeMeasurement positive = new CollectorRealtimeMeasurement("dev-sim", "collector-8", "S-02",
                1L, deviceTime, "2026-08-29 20:00:00", deviceTime, "PRIMARY_POSITIVE_POTENTIAL", new BigDecimal("1"), "V");
        CollectorRealtimeMeasurement negative = new CollectorRealtimeMeasurement("dev-sim", "collector-8", "S-03",
                1L, deviceTime, "2026-08-29 20:00:00", deviceTime, "PRIMARY_NEGATIVE_POTENTIAL", new BigDecimal("1"), "V");
        when(collectorSimulator.collectorRealtime(8)).thenReturn(
                new CollectorRealtimeSnapshot("collector-8", true, 1000,
                        List.of(measurement, positive, negative)));
        TTest current = validTest();
        current.setTestId(10L);
        current.setTestStatus("RUNNING");
        current.setReceptionStatus("RECEIVING");
        when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current);
        when(testMapper.updateReceptionStopped(eq(10L), eq("operator"), any())).thenReturn(1);
        testService.stopTest(10L, 7L, "operator");
        verify(testMapper).insertTestAudit(eq(10L), eq("TEST_STOPPED"), eq(7L), eq("operator"), isNull(),
                org.mockito.ArgumentMatchers.argThat(value -> value != null
                        && value.contains("IMMEDIATE")));
    }
    private void mockEnabledOptions()
@@ -635,6 +673,8 @@
        test.setPrincipalId(9L);
        test.setTestTypeId(3L);
        test.setTestPurpose("验证低温循环性能");
        test.setTestStatus("WAITING");
        test.setReceptionStatus("NOT_STARTED");
        test.setMonitorTimeoutMinutes(30);
        test.setBatteries(Collections.singletonList(validBattery("BAT-001", 1L, 100L)));
        test.setPlanSteps(Collections.singletonList(step));