From 3bb4fb15c664d29d179083698fdad35a661b1d7f Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期四, 28 八月 2025 14:57:40 +0800 Subject: [PATCH] 2025.8.28 1. 添加走航季度报告相关统计功能(待完成) --- src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/MissionServiceImplTest.kt | 85 +++++++++++++++++++++++++++++++++++++++--- 1 files changed, 79 insertions(+), 6 deletions(-) diff --git a/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/MissionServiceImplTest.kt b/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/MissionServiceImplTest.kt index a5b4ef3..f21cc8c 100644 --- a/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/MissionServiceImplTest.kt +++ b/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/MissionServiceImplTest.kt @@ -1,28 +1,101 @@ package com.flightfeather.uav.lightshare.service.impl +import com.flightfeather.uav.biz.FactorFilter import com.flightfeather.uav.biz.report.MissionReport +import com.flightfeather.uav.common.exception.BizException +import com.flightfeather.uav.domain.repository.MissionRep import com.flightfeather.uav.lightshare.service.MissionService -import org.junit.Test -import org.junit.Assert.* -import org.junit.runner.RunWith import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest import org.springframework.test.context.junit4.SpringRunner import javax.servlet.http.HttpServletResponse -@RunWith(SpringRunner::class) -@SpringBootTest +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.runner.RunWith + +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify + class MissionServiceImplTest { @Autowired lateinit var missionService: MissionService + + private var missionRep: MissionRep = mockk() @Autowired lateinit var missionReport: MissionReport @Test fun getReport() { - missionReport.execute("SH-CN-20240514") + missionReport.execute("SH-CN-20240723-01", FactorFilter.default()) + missionReport.execute("SH-CN-20240723-02", FactorFilter.default()) + } + + @Test + fun `calMissionInfo should throw BizException when mission not found`() { + // Arrange + val missionCode = "M001" + every { missionRep.findOne(missionCode) } returns null + + // Act & Assert + val exception = assertThrows<BizException> { + missionService.calMissionInfo(missionCode) + } + assertEquals("璧拌埅浠诲姟涓嶅瓨鍦�", exception.message) + } + + @Test + fun `calMissionInfo should calculate and update mission info successfully`() { + // Arrange + val missionCode = "M001" + val mission = Mission(missionCode) + val data = listOf<RealTimeData>() + + every { missionRep.findOne(missionCode) } returns mission + every { realTimeDataRep.fetchData(mission) } returns data + every { missionUtil.calKilometres(data) } returns 100.0 + every { missionUtil.calRegion(data) } returns "Center" + every { missionRep.updateMission(mission) } returns true + + // Act + val result = missionService.calMissionInfo(missionCode) + + // Assert + assertTrue(result) + assertEquals(100.0f, mission.kilometres) + assertEquals("Center", mission.region) + + verify { + missionRep.findOne(missionCode) + realTimeDataRep.fetchData(mission) + missionUtil.calKilometres(data) + missionUtil.calRegion(data) + missionRep.updateMission(mission) + } + } + + @Test + fun `calMissionInfo should return false when update fails`() { + // Arrange + val missionCode = "M001" + val mission = Mission(missionCode) + val data = listOf<RealTimeData>() + + every { missionRep.findOne(missionCode) } returns mission + every { realTimeDataRep.fetchData(mission) } returns data + every { missionUtil.calKilometres(data) } returns 100.0 + every { missionUtil.calRegion(data) } returns "Center" + every { missionRep.updateMission(mission) } returns false + + // Act + val result = missionService.calMissionInfo(missionCode) + + // Assert + assertFalse(result) } } \ No newline at end of file -- Gitblit v1.9.3