package com.ruoyi.web.modules.farming.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("TechResourceTypeValidator")
class TechResourceTypeValidatorTest
{
    @Mock
    private IBizInformationCategoryService bizInformationCategoryService;

    @InjectMocks
    private TechResourceTypeValidator validator;

    @Test
    @DisplayName("合法资讯子类编码通过")
    void allowedCode()
    {
        when(bizInformationCategoryService.selectChildren("004", "7"))
                .thenReturn(Collections.singletonList(new InformationCategoryItemVo("004006", "技术成果")));
        assertDoesNotThrow(() -> validator.assertAllowed("004006"));
    }

    @Test
    @DisplayName("非法编码拒绝")
    void invalidCode()
    {
        when(bizInformationCategoryService.selectChildren("004", "7"))
                .thenReturn(Collections.singletonList(new InformationCategoryItemVo("004005", "专家")));
        assertThrows(ServiceException.class, () -> validator.assertAllowed("999999"));
    }
}
