yeg
2026-09-05 7259e265b9237286996b09da03038ea5a133e1e0
ruoyi-admin/src/test/java/com/battery/business/service/impl/TTestLiveServiceImplTest.java
@@ -38,6 +38,38 @@
class TTestLiveServiceImplTest
{
    @Test
    void nonReceivingConsoleReadsCollectorStatusWithoutRequestingMeasurements() throws Exception
    {
        try (var simulator = new com.battery.device.simulator.BtsDevelopmentSimulator(0))
        {
            TTest test = test("RECEIVING");
            test.getBatteries().get(0).setCollectorId(7L);
            var tests = mock(ITTestService.class);
            when(tests.selectTestById(10L)).thenReturn(test);
            var mapper = mock(TTestMapper.class);
            when(mapper.selectCollectorCode(7L)).thenReturn("dev-sim-collector-1");
            var candidates = new com.battery.device.api.discovery.InMemoryDeviceDiscoveryCandidateStore();
            Instant now = Instant.now();
            candidates.replaceCollectors("dev-sim", List.of(new DeviceDiscoveryCandidateStore.CollectorCandidate(
                    "dev-sim", "dev-sim-collector-1", "127.0.1.2", null, "模拟采集器", null, null,
                    4, true, now, now.plusSeconds(30))));
            var service = new TTestLiveServiceImpl(tests, candidates, simulator, mapper);
            service.current(10L);
            var received = simulator.snapshot().recentRequests();
            assertTrue(received.stream().anyMatch(item -> item.command().equals("collector-realtime")));
            for (String status : List.of("PAUSED", "ENDED", "NOT_STARTED"))
            {
                test.setReceptionStatus(status);
                var source = service.current(10L).sources().stream()
                        .filter(item -> item.sourceType().equals("COLLECTOR")).findFirst().orElseThrow();
                assertEquals("ONLINE", source.deviceStatus());
                assertTrue(source.latestSnapshot().isEmpty());
                assertEquals(received, simulator.snapshot().recentRequests());
            }
        }
    }
    @Test
    void notStartedShouldNotExposePreTestDeviceSnapshot()
    {
        Instant now = Instant.parse("2026-09-02T06:00:00Z");