From ddaa44400aa478058ffe9349d59904a130b7ce9c Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期四, 28 八月 2025 17:33:11 +0800 Subject: [PATCH] 2025.8.28 1. 新增走航任务统计功能(待完成) --- src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/MissionServiceImplTest.kt | 88 +++++++------------------------------------ 1 files changed, 15 insertions(+), 73 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 f21cc8c..3d3dba5 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 @@ -2,30 +2,25 @@ 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.domain.entity.Mission +import com.flightfeather.uav.domain.mapper.MissionMapper import com.flightfeather.uav.lightshare.service.MissionService - +import org.junit.Test +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 +import tk.mybatis.mapper.entity.Example -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 - +@RunWith(SpringRunner::class) +@SpringBootTest class MissionServiceImplTest { @Autowired lateinit var missionService: MissionService - private var missionRep: MissionRep = mockk() + @Autowired + lateinit var missionMapper: MissionMapper @Autowired lateinit var missionReport: MissionReport @@ -37,65 +32,12 @@ } @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) + fun calMissionInfo() { + missionMapper.selectByExample(Example(Mission::class.java).apply { + createCriteria().andGreaterThanOrEqualTo("startTime", "2025-08-08 08:30:00") + }).forEach {mission -> + mission?.let { missionService.calMissionInfo(it.missionCode) } + Thread.sleep(1000) } - 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