yeg
2026-09-05 68156d14934ffb7d7b6e0dca63d3dcf3ed43c995
ruoyi-admin/src/test/java/com/battery/business/service/impl/TDetectionCabinetServiceImplTest.java
@@ -228,6 +228,23 @@
        assertEquals(8, devices.get(0).getChannelCount());
    }
    @Test
    void offlineCabinetRemainsDiscoverableAndCanBeRegistered()
    {
        var store = new InMemoryDeviceDiscoveryCandidateStore();
        store.recordCabinets(List.of(candidate("CABINET-001", false, DeviceWorkStatus.UNOBSERVABLE)));
        var service = new TDetectionCabinetServiceImpl(detectionCabinetMapper, store);
        when(detectionCabinetMapper.selectRegisteredCabinetCodes()).thenReturn(List.of());
        var devices = service.selectDiscoveredCabinetList();
        assertEquals(1, devices.size());
        assertEquals("离线", devices.get(0).getOnlineStatus());
        when(detectionCabinetMapper.insertDetectionCabinet(any(TDetectionCabinet.class))).thenReturn(1);
        assertEquals(1, service.insertDetectionCabinet(detectionCabinet));
        assertEquals("OFFLINE", detectionCabinet.getOnlineStatus());
        when(detectionCabinetMapper.selectRegisteredCabinetCodes()).thenReturn(List.of("CABINET-001"));
        assertEquals(0, service.selectDiscoveredCabinetList().size());
    }
    /**
     * 验证重复设备编码会阻止新增且不会执行写库操作。
     */
@@ -255,7 +272,7 @@
        ServiceException exception = assertThrows(ServiceException.class,
                () -> detectionCabinetService.insertDetectionCabinet(detectionCabinet));
        assertEquals("请先选择在线的发现候选设备", exception.getMessage());
        assertEquals("请先选择有效的发现候选设备", exception.getMessage());
        verify(detectionCabinetMapper, never()).insertDetectionCabinet(any());
    }