-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
โป๏ธ extract variable and rename constant
- Loading branch information
Showing
1 changed file
with
11 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, "[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) | ||
); | ||
} | ||
|
||
|
@@ -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) | ||
); | ||
} | ||
|
||
|
@@ -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 | ||
|