27
27
@ Sql (scripts = "/data/comment.sql" )
28
28
class CommentServiceTest {
29
29
30
- private static final int INITIAL_COMMENT_COUNT = 4 ;
30
+ private static final int INITIAL_TOTAL_COMMENT_COUNT = 4 ;
31
31
32
32
@ Autowired
33
33
private CommentService commentService ;
@@ -60,13 +60,14 @@ void createComment() {
60
60
CreateCommentRequest request = new CreateCommentRequest (2L , "thank you!" );
61
61
UserInfo userInfo = new UserInfo (2L , "ela@pengcook.net" );
62
62
Recipe recipe = recipeRepository .findById (2L ).orElseThrow ();
63
- int before = recipe .getCommentCount ();
63
+ int beforeRecipeCommentCount = recipe .getCommentCount ();
64
64
65
65
commentService .createComment (request , userInfo );
66
+ int afterRecipeCommentCount = recipeRepository .findById (2L ).orElseThrow ().getCommentCount ();
66
67
67
68
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 )
70
71
);
71
72
}
72
73
@@ -76,14 +77,14 @@ void deleteComment() {
76
77
UserInfo userInfo = new UserInfo (1L , "ela@pengcook.net" );
77
78
Recipe recipe = commentRepository .findById (2L ).orElseThrow ().getRecipe ();
78
79
Long recipeId = recipe .getId ();
79
- int before = recipe .getCommentCount ();
80
+ int beforeRecipeCommentCount = recipe .getCommentCount ();
80
81
81
82
commentService .deleteComment (2L , userInfo );
83
+ int afterRecipeCommentCount = recipeRepository .findById (recipeId ).orElseThrow ().getCommentCount ();
82
84
83
85
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 )
87
88
);
88
89
}
89
90
@@ -112,15 +113,15 @@ void deleteCommentWhenNotCommentOwner() {
112
113
void deleteCommentsByRecipe () {
113
114
commentService .deleteCommentsByRecipe (1L );
114
115
115
- assertThat (commentRepository .count ()).isEqualTo (INITIAL_COMMENT_COUNT - 3 );
116
+ assertThat (commentRepository .count ()).isEqualTo (INITIAL_TOTAL_COMMENT_COUNT - 3 );
116
117
}
117
118
118
119
@ Test
119
120
@ DisplayName ("ํน์ ์ฌ์ฉ์์ ๋๊ธ๋ค์ ์ญ์ ํ๋ค." )
120
121
void deleteCommentsByUser () {
121
122
commentService .deleteCommentsByUser (2L );
122
123
123
- assertThat (commentRepository .count ()).isEqualTo (INITIAL_COMMENT_COUNT - 2 );
124
+ assertThat (commentRepository .count ()).isEqualTo (INITIAL_TOTAL_COMMENT_COUNT - 2 );
124
125
}
125
126
126
127
@ Test
0 commit comments