ruoyi-admin/src/test/java/com/battery/business/service/impl/TestWarningExceptionServiceTest.java
@@ -3,11 +3,13 @@
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import org.junit.jupiter.api.Test;
import com.ruoyi.common.exception.ServiceException;
import com.battery.business.domain.TTest;
import com.battery.business.domain.TTestWarningException;
import com.battery.business.domain.TTestWarningThreshold;
@@ -68,18 +70,24 @@
    }
    @Test
    void closesOpenExceptionAndAppendsAuditInServiceOperation() {
    void closesOpenExceptionOnlyForTestPrincipalWithHandlingNote() {
        TTestMapper mapper = mock(TTestMapper.class);
        TestWarningExceptionService service = new TestWarningExceptionService(mapper);
        TTestWarningException exception = new TTestWarningException();
        exception.setExceptionId(7L);
        exception.setTestId(1L);
        TTest test = new TTest();
        test.setTestId(1L);
        test.setPrincipalId(22L);
        when(mapper.selectWarningExceptionById(7L)).thenReturn(exception);
        when(mapper.selectTestById(1L)).thenReturn(test);
        when(mapper.closeWarningException(eq(7L), eq(22L), eq("负责人"), any(Date.class), eq("已核实"))).thenReturn(1);
        int rows = service.close(7L, 22L, "负责人", "已核实");
        assertEquals(exception, service.closeByPrincipal(7L, 22L, "负责人", "已核实"));
        assertEquals(1, rows);
        // 归属校验与处理结果必填都由服务层负责,Controller 不再判断业务规则。
        assertThrows(ServiceException.class, () -> service.closeByPrincipal(7L, 23L, "其他人", "已核实"));
        assertThrows(ServiceException.class, () -> service.closeByPrincipal(7L, 22L, "负责人", " "));
    }
    private static TTest testWithThreshold(String metric, BigDecimal min, BigDecimal max) {