package com.ruoyi.web.modules.news.service;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
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.web.modules.news.FarmingNewsTestSamples;
import com.ruoyi.web.modules.news.domain.FarmingNewsQuery;
import com.ruoyi.web.modules.news.mapper.FarmingNewsMapper;
import com.ruoyi.web.modules.news.service.impl.FarmingNewsServiceImpl;

@ExtendWith(MockitoExtension.class)
@DisplayName("养殖资讯 Service")
class FarmingNewsServiceImplTest
{
    @Mock
    private FarmingNewsMapper farmingNewsMapper;

    @InjectMocks
    private FarmingNewsServiceImpl farmingNewsService;

    @Test
    @DisplayName("按 type 查询并映射列表项")
    void selectList_mapsVo()
    {
        when(farmingNewsMapper.selectFarmingNewsList(any(FarmingNewsQuery.class)))
                .thenReturn(Collections.singletonList(FarmingNewsTestSamples.sampleRow()));
        assertEquals(1, farmingNewsService.selectFarmingNewsList(FarmingNewsTestSamples.listQuery()).size());
    }

    @Test
    @DisplayName("无数据返回空列表")
    void selectList_empty()
    {
        when(farmingNewsMapper.selectFarmingNewsList(any(FarmingNewsQuery.class)))
                .thenReturn(Collections.emptyList());
        assertTrue(farmingNewsService.selectFarmingNewsList(FarmingNewsTestSamples.listQuery()).isEmpty());
    }
}
