From cd868e8db29336f82f88442a23ba71c80abb6d33 Mon Sep 17 00:00:00 2001 From: hgh1472 Date: Mon, 21 Oct 2024 12:33:09 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EA=B5=AC=ED=98=84=EC=B2=B4=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=ED=86=B5=ED=95=A9=EC=97=90=20=EC=9D=98?= =?UTF-8?q?=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Related to: #139 Ref: #136 --- .../repository/CommentRepositoryTest.java | 49 ++++--------------- 1 file changed, 9 insertions(+), 40 deletions(-) diff --git a/application/src/test/java/core/application/movies/repository/CommentRepositoryTest.java b/application/src/test/java/core/application/movies/repository/CommentRepositoryTest.java index 33398fd..e4441ae 100644 --- a/application/src/test/java/core/application/movies/repository/CommentRepositoryTest.java +++ b/application/src/test/java/core/application/movies/repository/CommentRepositoryTest.java @@ -118,13 +118,7 @@ public void findByMovieId() { comment2); // WHEN - List finds; - if (commentRepository instanceof MybatisCommentRepository) { - finds = commentRepository.findByMovieId(comment.getMovieId(), null, 0); - } else { - finds = commentRepository.findByMovieIdOrderBy(comment.getMovieId(), null, PageRequest.of(0, 10)) - .getContent(); - } + List finds = commentRepository.findByMovieId(comment.getMovieId(), null, 0).getContent(); // THEN assertThat(finds.size()).isEqualTo(2); @@ -143,13 +137,7 @@ public void findByMovieIdWithUser() { commentLikeRepository.saveCommentLike(comment.getCommentId(), userId); // WHEN - List finds; - if (commentRepository instanceof MybatisCommentRepository) { - finds = commentRepository.findByMovieId(comment.getMovieId(), userId, 0); - } else { - finds = commentRepository.findByMovieIdOrderBy(comment.getMovieId(), userId, PageRequest.of(0, 10)) - .getContent(); - } + List finds = commentRepository.findByMovieId(comment.getMovieId(), userId, 0).getContent(); // THEN assertThat(finds.size()).isEqualTo(1); @@ -159,7 +147,7 @@ public void findByMovieIdWithUser() { @Test @DisplayName("특정 영화의 한줄평을 시간순으로 조회한다.") - public void findByMovieIdOnDateDescend() { + public void findByMovieIdOnDateDescend() throws InterruptedException { // GIVEN CommentEntity comment2 = CommentEntity.builder() .content("내용2") @@ -170,22 +158,17 @@ public void findByMovieIdOnDateDescend() { .userId(userRepository.findByUserEmail("testEmail").get().getUserId()) .build(); commentRepository.saveNewComment(comment.getMovieId(), comment.getUserId(), comment); + Thread.sleep(1000); commentRepository.saveNewComment(comment2.getMovieId(), comment2.getUserId(), comment2); // WHEN - List finds; - if (commentRepository instanceof MybatisCommentRepository) { - finds = commentRepository.findByMovieIdOnDateDescend(comment.getMovieId(), userId, 0); - } else { - finds = commentRepository.findByMovieIdOrderBy(comment.getMovieId(), userId, PageRequest.of(0, 10, Sort.by( - Direction.DESC, "createdAt"))) - .getContent(); - } + List finds = commentRepository.findByMovieIdOnDateDescend(comment.getMovieId(), userId, 0) + .getContent(); // THEN Instant later = finds.get(0).getCreatedAt(); for (CommentRespDTO find : finds) { - assertThat(later).isBeforeOrEqualTo(find.getCreatedAt()); + assertThat(later).isAfterOrEqualTo(find.getCreatedAt()); later = find.getCreatedAt(); } } @@ -206,14 +189,7 @@ public void testLikeOrder() { commentRepository.saveNewComment(comment2.getMovieId(), comment2.getUserId(), comment2); // WHEN - List finds; - if (commentRepository instanceof MybatisCommentRepository) { - finds = commentRepository.findByMovieIdOnLikeDescend(comment.getMovieId(), userId, 0); - } else { - finds = commentRepository.findByMovieIdOrderBy(comment.getMovieId(), userId, PageRequest.of(0, 10, Sort.by( - Direction.DESC, "like"))) - .getContent(); - } + List finds = commentRepository.findByMovieIdOnLikeDescend(comment.getMovieId(), userId, 0).getContent(); // THEN int more = finds.get(0).getLike(); @@ -239,14 +215,7 @@ public void testDislikeOrder() { commentRepository.saveNewComment(comment2.getMovieId(), comment2.getUserId(), comment2); // WHEN - List finds; - if (commentRepository instanceof MybatisCommentRepository) { - finds = commentRepository.findByMovieIdOnDislikeDescend(comment.getMovieId(), userId, 0); - } else { - finds = commentRepository.findByMovieIdOrderBy(comment.getMovieId(), userId, PageRequest.of(0, 10, Sort.by( - Direction.DESC, "dislike"))) - .getContent(); - } + List finds = commentRepository.findByMovieIdOnDislikeDescend(comment.getMovieId(), userId, 0).getContent(); // THEN int more = finds.get(0).getDislike();