diff --git a/backend/src/test/java/net/pengcook/comment/service/CommentServiceTest.java b/backend/src/test/java/net/pengcook/comment/service/CommentServiceTest.java index dda8a02f..fb4b0445 100644 --- a/backend/src/test/java/net/pengcook/comment/service/CommentServiceTest.java +++ b/backend/src/test/java/net/pengcook/comment/service/CommentServiceTest.java @@ -27,7 +27,7 @@ @Sql(scripts = "/data/comment.sql") class CommentServiceTest { - private static final int INITIAL_COMMENT_COUNT = 4; + private static final int INITIAL_TOTAL_COMMENT_COUNT = 4; @Autowired private CommentService commentService; @@ -60,13 +60,14 @@ void createComment() { CreateCommentRequest request = new CreateCommentRequest(2L, "thank you!"); UserInfo userInfo = new UserInfo(2L, "ela@pengcook.net"); Recipe recipe = recipeRepository.findById(2L).orElseThrow(); - int before = recipe.getCommentCount(); + int beforeRecipeCommentCount = recipe.getCommentCount(); commentService.createComment(request, userInfo); + int afterRecipeCommentCount = recipeRepository.findById(2L).orElseThrow().getCommentCount(); assertAll( - () -> assertThat(commentRepository.count()).isEqualTo(INITIAL_COMMENT_COUNT + 1), - () -> assertThat(recipeRepository.findById(2L).orElseThrow().getCommentCount()).isEqualTo(before + 1) + () -> assertThat(commentRepository.count()).isEqualTo(INITIAL_TOTAL_COMMENT_COUNT + 1), + () -> assertThat(afterRecipeCommentCount).isEqualTo(beforeRecipeCommentCount + 1) ); } @@ -76,14 +77,14 @@ void deleteComment() { UserInfo userInfo = new UserInfo(1L, "ela@pengcook.net"); Recipe recipe = commentRepository.findById(2L).orElseThrow().getRecipe(); Long recipeId = recipe.getId(); - int before = recipe.getCommentCount(); + int beforeRecipeCommentCount = recipe.getCommentCount(); commentService.deleteComment(2L, userInfo); + int afterRecipeCommentCount = recipeRepository.findById(recipeId).orElseThrow().getCommentCount(); assertAll( - () -> assertThat(commentRepository.count()).isEqualTo(INITIAL_COMMENT_COUNT - 1), - () -> assertThat(recipeRepository.findById(recipeId).orElseThrow().getCommentCount()).isEqualTo( - before - 1) + () -> assertThat(commentRepository.count()).isEqualTo(INITIAL_TOTAL_COMMENT_COUNT - 1), + () -> assertThat(afterRecipeCommentCount).isEqualTo(beforeRecipeCommentCount - 1) ); } @@ -112,7 +113,7 @@ void deleteCommentWhenNotCommentOwner() { void deleteCommentsByRecipe() { commentService.deleteCommentsByRecipe(1L); - assertThat(commentRepository.count()).isEqualTo(INITIAL_COMMENT_COUNT - 3); + assertThat(commentRepository.count()).isEqualTo(INITIAL_TOTAL_COMMENT_COUNT - 3); } @Test @@ -120,7 +121,7 @@ void deleteCommentsByRecipe() { void deleteCommentsByUser() { commentService.deleteCommentsByUser(2L); - assertThat(commentRepository.count()).isEqualTo(INITIAL_COMMENT_COUNT - 2); + assertThat(commentRepository.count()).isEqualTo(INITIAL_TOTAL_COMMENT_COUNT - 2); } @Test