yeg
2026-09-05 78f53edb9542a83d9579714cf4e1e8133fc89ee9
ruoyi-admin/src/test/java/com/battery/business/service/impl/TestWarningExceptionServiceTest.java
@@ -13,9 +13,33 @@
import com.battery.business.domain.TTestWarningThreshold;
import com.battery.business.mapper.TTestMapper;
/** 测试预警仅由成功接收测量值触发,并通过持久层原子聚合。 */
/** 阈值异常与接收中的离线异常分别判定,并通过持久层原子聚合。 */
class TestWarningExceptionServiceTest {
    @Test
    void recordsOfflineSourcesOnlyWhileReceivingWithoutInventingMeasurements() {
        TTestMapper mapper = mock(TTestMapper.class);
        var service = new TestWarningExceptionService(mapper);
        TTest test = new TTest();
        test.setTestId(1L);
        test.setTestStatus("RUNNING");
        test.setReceptionStatus("RECEIVING");
        Date now = new Date();
        when(mapper.selectOfflineTestSources(1L)).thenReturn(List.of(
                new com.battery.business.domain.vo.OfflineTestSource("CABINET_CHANNEL", "sim:22:1:1:1"),
                new com.battery.business.domain.vo.OfflineTestSource("COLLECTOR", "9")));
        service.recordOfflineSources(test, now);
        verify(mapper).upsertOfflineException(1L, "CABINET_CHANNEL", "sim:22:1:1:1", now);
        verify(mapper).upsertOfflineException(1L, "COLLECTOR", "9", now);
        clearInvocations(mapper);
        for (String state : List.of("PAUSED", "ENDED", "NOT_STARTED")) {
            test.setReceptionStatus(state);
            service.recordOfflineSources(test, now);
        }
        verifyNoInteractions(mapper);
    }
    @Test
    void evaluatesOnlyOutOfRangeValues() {
        TTestMapper mapper = mock(TTestMapper.class);
        TestWarningExceptionService service = new TestWarningExceptionService(mapper);