Skip to content

Commit

Permalink
โ™ป๏ธ extract variable and rename constant
Browse files Browse the repository at this point in the history
  • Loading branch information
hyxrxn committed Dec 8, 2024
1 parent ada4a59 commit a25aba5
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,13 +60,14 @@ void createComment() {
CreateCommentRequest request = new CreateCommentRequest(2L, "thank you!");
UserInfo userInfo = new UserInfo(2L, "[email protected]");
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)
);
}

Expand All @@ -76,14 +77,14 @@ void deleteComment() {
UserInfo userInfo = new UserInfo(1L, "[email protected]");
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)
);
}

Expand Down Expand Up @@ -112,15 +113,15 @@ 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
@DisplayName("ํŠน์ • ์‚ฌ์šฉ์ž์˜ ๋Œ“๊ธ€๋“ค์„ ์‚ญ์ œํ•œ๋‹ค.")
void deleteCommentsByUser() {
commentService.deleteCommentsByUser(2L);

assertThat(commentRepository.count()).isEqualTo(INITIAL_COMMENT_COUNT - 2);
assertThat(commentRepository.count()).isEqualTo(INITIAL_TOTAL_COMMENT_COUNT - 2);
}

@Test
Expand Down

0 comments on commit a25aba5

Please sign in to comment.