单元测试--

mvn 命令:mvn clean verify -U -Dcheckstyle.skip -Dmaven.gitcommitid.skip=true

java 复制代码
import com.futures.busi.proxy.common.service.facade.response.GetDownLoadResultResponse;
import com.futures.busi.proxy.core.service.impl.download.DownLoadServiceImpl;
import com.kucoin.base.exception.BizException;
import lombok.extern.slf4j.Slf4j;
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 org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.when;

/**
 * @author : Timmy 2026/1/19 description :
 */
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
@Slf4j
public class DownLoadServiceImplTest {
    @InjectMocks
    private DownLoadServiceImpl downLoadServiceImpl;

    @Mock
    private StringRedisTemplate stringRedisTemplate;

    @Test
    void getDownLoadResultTest() {
        // 参数为空
        {
            assertThrows(BizException.class, () -> downLoadServiceImpl.getDownLoadResult(null));
        }

        // 如果状态是成功的,但是下载链接为空,则尝试再次获取  如果依然为空说明下载链接丢失
        {
            ValueOperations valueOperations = mock(ValueOperations.class);
            when(stringRedisTemplate.opsForValue()).thenReturn(valueOperations);
            when(valueOperations.get("busi_download_status_prefix_1")).thenReturn("2");
            when(valueOperations.get("busi_download_url_prefix_1")).thenReturn(null);
            GetDownLoadResultResponse downLoadResult = downLoadServiceImpl.getDownLoadResult("1");
            log.info("downLoadResult: {}", downLoadResult);
        }
        // 如果状态为空 但是下载链接非空 则说明文件生成成功
        {
            ValueOperations valueOperations = mock(ValueOperations.class);
            when(stringRedisTemplate.opsForValue()).thenReturn(valueOperations);
            when(valueOperations.get("busi_download_status_prefix_1")).thenReturn(null);
            when(valueOperations.get("busi_download_url_prefix_1")).thenReturn("http://test.com/download/1");
            GetDownLoadResultResponse downLoadResult = downLoadServiceImpl.getDownLoadResult("1");
            log.info("downLoadResult: {}", downLoadResult);
        }
    }

}
相关推荐
汽车仪器仪表相关领域1 天前
Kvaser Memorator Light HS v2:单通道 CAN FD 便携记录仪,即插即用的故障诊断利器
运维·服务器·数据库·人工智能·功能测试·单元测试
QH139292318802 天前
Rohde & Schwarz FSWX3044 FSWX3026信号与频谱分析仪
网络·功能测试·单元测试·集成测试·模块测试
川石课堂软件测试2 天前
AI如何赋能软件测试行业的发展
人工智能·python·功能测试·网络协议·单元测试·测试用例·prometheus
seabirdssss3 天前
以登录功能理解单元测试、集成测试、系统测试和用户测试
单元测试·集成测试
琪露诺大湿3 天前
VeloQueue-测试报告
java·开发语言·消息队列·单元测试·项目·测试报告
胡利光4 天前
Harness Engineering 02|Repo Harness:让仓库对 Agent 可读
java·junit·单元测试
Elastic 中国社区官方博客4 天前
使用 EDOT Browser 和 Kibana 进行 OpenTelemetry 浏览器端埋点
大数据·服务器·数据库·elasticsearch·搜索引擎·单元测试·可用性测试
姚青&4 天前
软件测试基础概念
单元测试·pytest
川石课堂软件测试5 天前
技术分享|JMeter接口与性能测试实战
数据库·功能测试·测试工具·jmeter·单元测试·postman·prometheus