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

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
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.category.domain.vo.InformationCategoryItemVo;
import com.ruoyi.web.modules.category.service.IBizInformationCategoryService;

@ExtendWith(MockitoExtension.class)
@DisplayName("TechProjectGuideTypeValidator")
class TechProjectGuideTypeValidatorTest
{
    @Mock
    private IBizInformationCategoryService bizInformationCategoryService;

    @InjectMocks
    private TechProjectGuideTypeValidator validator;

    @Test
    @DisplayName("KJXM-UT-001 合法资讯子类编码通过")
    void allowedCode()
    {
        when(bizInformationCategoryService.selectChildren("002", null))
                .thenReturn(Collections.singletonList(new InformationCategoryItemVo("002002", "农业科技")));
        assertDoesNotThrow(() -> validator.assertAllowed("002002"));
    }

    @Test
    @DisplayName("非法编码拒绝")
    void invalidCode()
    {
        when(bizInformationCategoryService.selectChildren("002", null))
                .thenReturn(Collections.singletonList(new InformationCategoryItemVo("002001", "高新技术")));
        assertThrows(ServiceException.class, () -> validator.assertAllowed("999999"));
    }
}
