From 76742ed65a86000e4c142c7628c944643bb80869 Mon Sep 17 00:00:00 2001 From: developer Date: Thu, 9 Jul 2026 00:12:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=90=86=E6=B5=8B=E8=AF=95=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E5=AF=BC=E5=9B=BE=E7=9B=B8=E5=85=B3=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ReviewServiceImplTest.java | 98 ------------------- 1 file changed, 98 deletions(-) diff --git a/src/test/java/com/guo/learningprogresstracker/service/impl/ReviewServiceImplTest.java b/src/test/java/com/guo/learningprogresstracker/service/impl/ReviewServiceImplTest.java index 6a975cb..c2fed13 100644 --- a/src/test/java/com/guo/learningprogresstracker/service/impl/ReviewServiceImplTest.java +++ b/src/test/java/com/guo/learningprogresstracker/service/impl/ReviewServiceImplTest.java @@ -3,16 +3,11 @@ package com.guo.learningprogresstracker.service.impl; import com.baomidou.mybatisplus.core.MybatisConfiguration; import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; import com.guo.learningprogresstracker.dto.ReviewFeedItem; -import com.guo.learningprogresstracker.dto.request.UpsertReviewMindMapRequest; -import com.guo.learningprogresstracker.entity.ReviewMindMapEntity; import com.guo.learningprogresstracker.entity.ReviewRecallRecordEntity; import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity; import com.guo.learningprogresstracker.entity.StudyReportsEntity; import com.guo.learningprogresstracker.entity.StudySessionsEntity; import com.guo.learningprogresstracker.entity.TaskEntity; -import com.guo.learningprogresstracker.enums.ReviewMindMapFileFormatEnum; -import com.guo.learningprogresstracker.enums.ReviewMindMapParseStatusEnum; -import com.guo.learningprogresstracker.mapper.ReviewMindMapMapper; import com.guo.learningprogresstracker.mapper.ReviewRecallRecordMapper; import com.guo.learningprogresstracker.mapper.StudyReportFragmentsMapper; import com.guo.learningprogresstracker.mapper.StudyReportsMapper; @@ -25,17 +20,12 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.mock.web.MockMultipartFile; -import java.nio.file.Files; -import java.nio.file.Path; import java.time.LocalDateTime; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) @@ -48,7 +38,6 @@ class ReviewServiceImplTest { TableInfoHelper.initTableInfo(new MapperBuilderAssistant(configuration, ""), StudyReportFragmentsEntity.class); TableInfoHelper.initTableInfo(new MapperBuilderAssistant(configuration, ""), StudySessionsEntity.class); TableInfoHelper.initTableInfo(new MapperBuilderAssistant(configuration, ""), TaskEntity.class); - TableInfoHelper.initTableInfo(new MapperBuilderAssistant(configuration, ""), ReviewMindMapEntity.class); } @InjectMocks @@ -66,9 +55,6 @@ class ReviewServiceImplTest { @Mock private TasksMapper tasksMapper; - @Mock - private ReviewMindMapMapper reviewMindMapMapper; - @Mock private ReviewRecallRecordMapper reviewRecallRecordMapper; @@ -163,88 +149,4 @@ class ReviewServiceImplTest { assertEquals("Task", items.get(0).getTaskName()); } - @Test - void upsertMindMap_shouldCreateWhenMissing() throws Exception { - when(tasksMapper.exists(any())).thenReturn(true); - when(reviewMindMapMapper.selectOne(any())).thenReturn(null); - when(reviewMindMapMapper.insert(any())).thenAnswer(invocation -> { - ReviewMindMapEntity entity = invocation.getArgument(0); - entity.setId(3); - return 1; - }); - - UpsertReviewMindMapRequest request = new UpsertReviewMindMapRequest(); - request.setTitle("Map"); - request.setContent("root"); - request.setContentFormat("mermaid"); - - ReviewMindMapEntity entity = reviewService.upsertMindMap("T1", request); - - assertNotNull(entity.getId()); - assertEquals("T1", entity.getTaskNum()); - assertEquals("MERMAID", entity.getContentFormat()); - verify(reviewMindMapMapper).insert(any(ReviewMindMapEntity.class)); - } - - @Test - void upsertMindMap_shouldUpdateExisting() throws Exception { - ReviewMindMapEntity existing = new ReviewMindMapEntity(); - existing.setId(5); - existing.setTaskNum("T1"); - existing.setTitle("Old"); - existing.setContent("old"); - existing.setContentFormat("TEXT"); - - when(tasksMapper.exists(any())).thenReturn(true); - when(reviewMindMapMapper.selectOne(any())).thenReturn(existing); - - UpsertReviewMindMapRequest request = new UpsertReviewMindMapRequest(); - request.setTitle("New"); - request.setContent("new"); - request.setContentFormat("json"); - - ReviewMindMapEntity entity = reviewService.upsertMindMap("T1", request); - - assertEquals(5, entity.getId()); - assertEquals("New", entity.getTitle()); - assertEquals("JSON", entity.getContentFormat()); - verify(reviewMindMapMapper).updateById(existing); - } - - @Test - void uploadMindMap_shouldParseMarkdownFile() throws Exception { - when(tasksMapper.exists(any())).thenReturn(true); - when(reviewMindMapMapper.selectOne(any())).thenReturn(null); - when(reviewMindMapMapper.insert(any())).thenAnswer(invocation -> { - ReviewMindMapEntity entity = invocation.getArgument(0); - entity.setId(9); - return 1; - }); - - MockMultipartFile file = new MockMultipartFile( - "file", - "java-review.md", - "text/markdown", - "# Java 并发\n## 线程基础\n- RUNNABLE\n".getBytes()); - - ReviewMindMapEntity entity = reviewService.uploadMindMap("T1", file); - - try { - assertEquals(9, entity.getId()); - assertEquals("FILE", entity.getSourceType()); - assertEquals(ReviewMindMapFileFormatEnum.MARKDOWN.getCode(), entity.getFileFormat()); - assertEquals(ReviewMindMapParseStatusEnum.SUCCESS.getCode(), entity.getParseStatus()); - assertEquals("JSON", entity.getContentFormat()); - assertNotNull(entity.getParsedContent()); - assertEquals(true, entity.getParsedContent().contains("线程基础")); - assertEquals(true, entity.getContent().contains("RUNNABLE")); - } finally { - if (entity.getFilePath() != null) { - Path storedFile = Path.of(entity.getFilePath()); - Files.deleteIfExists(storedFile); - Files.deleteIfExists(storedFile.getParent()); - } - } - verify(reviewMindMapMapper).insert(any(ReviewMindMapEntity.class)); - } }