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

    @InjectMocks
    private FeedingStandardTypeValidator validator;

    @Test
    @DisplayName("合法资讯子类编码通过")
    void allowedCode()
    {
        when(bizInformationCategoryService.selectChildren("001", "2"))
                .thenReturn(Collections.singletonList(new InformationCategoryItemVo("001005", "饲料配方")));
        assertDoesNotThrow(() -> validator.assertAllowed("001005"));
    }

    @Test
    @DisplayName("非法编码拒绝")
    void invalidCode()
    {
        when(bizInformationCategoryService.selectChildren("001", "2"))
                .thenReturn(Collections.singletonList(new InformationCategoryItemVo("001005", "饲料配方")));
        assertThrows(ServiceException.class, () -> validator.assertAllowed("999999"));
    }
}
