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("TechResourceCourseTopicValidator")
class TechResourceCourseTopicValidatorTest
{
    @Mock
    private IBizInformationCategoryService bizInformationCategoryService;

    @InjectMocks
    private TechResourceCourseTopicValidator validator;

    @Test
    @DisplayName("合法课程主题编码通过")
    void allowedCode()
    {
        when(bizInformationCategoryService.selectChildren("005", "8"))
                .thenReturn(Collections.singletonList(new InformationCategoryItemVo("005001", "基础养殖")));
        assertDoesNotThrow(() -> validator.assertAllowed("005001"));
    }

    @Test
    @DisplayName("非法编码拒绝")
    void invalidCode()
    {
        when(bizInformationCategoryService.selectChildren("005", "8"))
                .thenReturn(Collections.singletonList(new InformationCategoryItemVo("005001", "基础养殖")));
        assertThrows(ServiceException.class, () -> validator.assertAllowed("基础养殖"));
    }
}
