package com.ruoyi.web.modules.epidemic.support;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.when;

import java.util.Collections;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.web.modules.circulation.domain.BizQuarantineStation;
import com.ruoyi.web.modules.circulation.mapper.BizQuarantineStationMapper;
import com.ruoyi.web.modules.circulation.support.QuarantineStationRules;

@ExtendWith(MockitoExtension.class)
@DisplayName("LabDetectionQuarantineStationSupport")
class LabDetectionQuarantineStationSupportTest
{

    @Mock
    private BizQuarantineStationMapper quarantineStationMapper;

    @InjectMocks
    private LabDetectionQuarantineStationSupport support;

    @Test
    @DisplayName("检疫点为空")
    void validateNull()
    {
        assertThrows(ServiceException.class, () -> support.validateQuarantineStationId(null));
    }

    @Test
    @DisplayName("检疫站不存在")
    void validateNotFound()
    {
        when(quarantineStationMapper.selectBizQuarantineStationById(9L)).thenReturn(null);
        assertThrows(ServiceException.class, () -> support.validateQuarantineStationId(9L));
    }

    @Test
    @DisplayName("运营状态非正常")
    void validateNotNormal()
    {
        BizQuarantineStation s = new BizQuarantineStation();
        s.setId(1L);
        s.setOperateStatus(QuarantineStationRules.OPERATE_STATUS_SUSPENDED);
        when(quarantineStationMapper.selectBizQuarantineStationById(1L)).thenReturn(s);
        assertThrows(ServiceException.class, () -> support.validateQuarantineStationId(1L));
    }

    @Test
    @DisplayName("下拉仅正常运营")
    void listOptions()
    {
        BizQuarantineStation s = new BizQuarantineStation();
        s.setId(2L);
        s.setStationName("甲检疫站");
        when(quarantineStationMapper.selectBizQuarantineStationList(org.mockito.ArgumentMatchers.any()))
                .thenReturn(Collections.singletonList(s));
        assertEquals(1, support.listNormalStationOptions().size());
        assertEquals("甲检疫站", support.listNormalStationOptions().get(0).getStationName());
    }
}
