Skip to content

Commit a25aba5

Browse files
committed
โ™ป๏ธ extract variable and rename constant
1 parent ada4a59 commit a25aba5

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

โ€Žbackend/src/test/java/net/pengcook/comment/service/CommentServiceTest.java

+11-10
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
@Sql(scripts = "/data/comment.sql")
2828
class CommentServiceTest {
2929

30-
private static final int INITIAL_COMMENT_COUNT = 4;
30+
private static final int INITIAL_TOTAL_COMMENT_COUNT = 4;
3131

3232
@Autowired
3333
private CommentService commentService;
@@ -60,13 +60,14 @@ void createComment() {
6060
CreateCommentRequest request = new CreateCommentRequest(2L, "thank you!");
6161
UserInfo userInfo = new UserInfo(2L, "ela@pengcook.net");
6262
Recipe recipe = recipeRepository.findById(2L).orElseThrow();
63-
int before = recipe.getCommentCount();
63+
int beforeRecipeCommentCount = recipe.getCommentCount();
6464

6565
commentService.createComment(request, userInfo);
66+
int afterRecipeCommentCount = recipeRepository.findById(2L).orElseThrow().getCommentCount();
6667

6768
assertAll(
68-
() -> assertThat(commentRepository.count()).isEqualTo(INITIAL_COMMENT_COUNT + 1),
69-
() -> assertThat(recipeRepository.findById(2L).orElseThrow().getCommentCount()).isEqualTo(before + 1)
69+
() -> assertThat(commentRepository.count()).isEqualTo(INITIAL_TOTAL_COMMENT_COUNT + 1),
70+
() -> assertThat(afterRecipeCommentCount).isEqualTo(beforeRecipeCommentCount + 1)
7071
);
7172
}
7273

@@ -76,14 +77,14 @@ void deleteComment() {
7677
UserInfo userInfo = new UserInfo(1L, "ela@pengcook.net");
7778
Recipe recipe = commentRepository.findById(2L).orElseThrow().getRecipe();
7879
Long recipeId = recipe.getId();
79-
int before = recipe.getCommentCount();
80+
int beforeRecipeCommentCount = recipe.getCommentCount();
8081

8182
commentService.deleteComment(2L, userInfo);
83+
int afterRecipeCommentCount = recipeRepository.findById(recipeId).orElseThrow().getCommentCount();
8284

8385
assertAll(
84-
() -> assertThat(commentRepository.count()).isEqualTo(INITIAL_COMMENT_COUNT - 1),
85-
() -> assertThat(recipeRepository.findById(recipeId).orElseThrow().getCommentCount()).isEqualTo(
86-
before - 1)
86+
() -> assertThat(commentRepository.count()).isEqualTo(INITIAL_TOTAL_COMMENT_COUNT - 1),
87+
() -> assertThat(afterRecipeCommentCount).isEqualTo(beforeRecipeCommentCount - 1)
8788
);
8889
}
8990

@@ -112,15 +113,15 @@ void deleteCommentWhenNotCommentOwner() {
112113
void deleteCommentsByRecipe() {
113114
commentService.deleteCommentsByRecipe(1L);
114115

115-
assertThat(commentRepository.count()).isEqualTo(INITIAL_COMMENT_COUNT - 3);
116+
assertThat(commentRepository.count()).isEqualTo(INITIAL_TOTAL_COMMENT_COUNT - 3);
116117
}
117118

118119
@Test
119120
@DisplayName("ํŠน์ • ์‚ฌ์šฉ์ž์˜ ๋Œ“๊ธ€๋“ค์„ ์‚ญ์ œํ•œ๋‹ค.")
120121
void deleteCommentsByUser() {
121122
commentService.deleteCommentsByUser(2L);
122123

123-
assertThat(commentRepository.count()).isEqualTo(INITIAL_COMMENT_COUNT - 2);
124+
assertThat(commentRepository.count()).isEqualTo(INITIAL_TOTAL_COMMENT_COUNT - 2);
124125
}
125126

126127
@Test

0 commit comments

Comments
ย (0)