add comment, reward, total
Change-Id: Ib3d9f5f11b51e4bbf4dc5a553315ff3fd9110efb
diff --git a/src/test/java/com/g9/g9backend/controller/CommentControllerTest.java b/src/test/java/com/g9/g9backend/controller/CommentControllerTest.java
new file mode 100644
index 0000000..d9f9f87
--- /dev/null
+++ b/src/test/java/com/g9/g9backend/controller/CommentControllerTest.java
@@ -0,0 +1,68 @@
+package com.g9.g9backend.controller;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.g9.g9backend.pojo.Comment;
+import com.g9.g9backend.pojo.DTO.GetCommentDTO;
+import com.g9.g9backend.service.CommentService;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentMatchers;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+
+import org.springframework.http.ResponseEntity;
+
+import java.util.Collections;
+import java.util.Date;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.*;
+import static org.mockito.BDDMockito.given;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+@ExtendWith(MockitoExtension.class)
+public class CommentControllerTest {
+
+ @Mock
+ private CommentService commentService;
+
+ @InjectMocks
+ private CommentController commentController;
+
+ @Test
+ void testPostComment() {
+ Comment comment = new Comment();
+ ResponseEntity<String> response = commentController.postComment(comment);
+ verify(commentService).save(comment);
+ assertEquals(200, response.getStatusCode().value());
+ }
+
+ @Test
+ void testDeleteComment() {
+ Integer id = 1;
+ ResponseEntity<String> response = commentController.deleteComment(id);
+ verify(commentService).removeById(id);
+ assertEquals(204, response.getStatusCode().value());
+ }
+
+ @Test
+ void testGetCommentWithResourceType() {
+ Comment comment = new Comment();
+ comment.setCommentId(1);
+ comment.setUserId(2);
+ comment.setReplyId(null);
+ comment.setContent("Test");
+ comment.setCreateAt(new Date());
+ comment.setResourceId(1);
+
+ Page<Comment> page = new Page<>();
+ page.setRecords(Collections.singletonList(comment));
+
+ given(commentService.page(ArgumentMatchers.<Page<Comment>>any(), ArgumentMatchers.<LambdaQueryWrapper<Comment>>any())).willReturn(page);
+
+ ResponseEntity<GetCommentDTO> response = commentController.getComment(1, 1, 10, "资源");
+ assertEquals(200, response.getStatusCode().value());
+ assertEquals(1, response.getBody().getRecords().size());
+ }
+}