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

    @InjectMocks
    private GrowthSlaughterStandardTypeValidator validator;

    @Test
    @DisplayName("合法资讯子类编码通过")
    void allowedCode()
    {
        when(bizInformationCategoryService.selectChildren("001", "4"))
                .thenReturn(Collections.singletonList(new InformationCategoryItemVo("001011", "牦牛生长")));
        assertDoesNotThrow(() -> validator.assertAllowed("001011"));
    }

    @Test
    @DisplayName("非法编码拒绝")
    void invalidCode()
    {
        when(bizInformationCategoryService.selectChildren("001", "4"))
                .thenReturn(Collections.singletonList(new InformationCategoryItemVo("001011", "牦牛生长")));
        assertThrows(ServiceException.class, () -> validator.assertAllowed("999999"));
    }
}
