用户,分区,作品的增删改查,根据作者查所有作品的接口,根据用户查还有多少任务没做,帖子和评论的增删改查,并优化了测试文件的结构
Change-Id: I4266495b6465fcbdf5705f02a59d2ae9fa54cbda
diff --git a/src/test/java/edu/bjtu/groupone/backend/CommentServiceTest.java b/src/test/java/edu/bjtu/groupone/backend/CommentServiceTest.java
new file mode 100644
index 0000000..50ea9ba
--- /dev/null
+++ b/src/test/java/edu/bjtu/groupone/backend/CommentServiceTest.java
@@ -0,0 +1,81 @@
+package edu.bjtu.groupone.backend;
+
+import edu.bjtu.groupone.backend.domain.entity.Comment;
+import edu.bjtu.groupone.backend.mapper.CommentMapper;
+import edu.bjtu.groupone.backend.service.impl.CommentServiceImpl;
+import org.junit.jupiter.api.BeforeEach;
+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 java.util.Arrays;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.*;
+
+@ExtendWith(MockitoExtension.class)
+public class CommentServiceTest {
+
+ @Mock
+ private CommentMapper commentMapper;
+
+ @InjectMocks
+ private CommentServiceImpl commentService;
+
+ private Comment comment;
+ private List<Comment> comments;
+
+ @BeforeEach
+ void setUp() {
+ comment = new Comment(1L, 1L, 1, "测试评论", "2023-06-15");
+ comments = Arrays.asList(comment);
+ }
+
+ @Test
+ void addComment() {
+ doNothing().when(commentMapper).insertComment(any(Comment.class));
+
+ commentService.addComment(comment);
+
+ verify(commentMapper, times(1)).insertComment(comment);
+ }
+
+ @Test
+ void deleteComment() {
+ doNothing().when(commentMapper).deleteComment(1L);
+
+ commentService.deleteComment(1L);
+
+ verify(commentMapper, times(1)).deleteComment(1L);
+ }
+
+ @Test
+ void updateComment() {
+ doNothing().when(commentMapper).updateComment(any(Comment.class));
+
+ commentService.updateComment(comment);
+
+ verify(commentMapper, times(1)).updateComment(comment);
+ }
+
+ @Test
+ void getCommentById() {
+ when(commentMapper.selectCommentById(1L)).thenReturn(comment);
+
+ Comment result = commentService.getCommentById(1L);
+
+ assertEquals(comment, result);
+ }
+
+ @Test
+ void getCommentsByPostId() {
+ when(commentMapper.selectCommentsByPostId(1L)).thenReturn(comments);
+
+ List<Comment> result = commentService.getCommentsByPostId(1L);
+
+ assertEquals(comments, result);
+ }
+}
\ No newline at end of file