1818import java .util .Optional ;
1919import java .util .UUID ;
2020
21- import static com .somemore .domains .volunteerapply .domain .ApplyStatus .APPROVED ;
22- import static com .somemore .domains .volunteerapply .domain .ApplyStatus .REJECTED ;
21+ import static com .somemore .domains .volunteerapply .domain .ApplyStatus .*;
2322import static org .assertj .core .api .Assertions .assertThat ;
2423
2524@ Transactional
@@ -30,12 +29,11 @@ class VolunteerApplyRepositoryImplTest extends IntegrationTestSupport {
3029
3130 @ BeforeEach
3231 void setUp () {
33- // Given
3432 for (int i = 1 ; i <= 15 ; i ++) {
3533 VolunteerApply apply = VolunteerApply .builder ()
3634 .volunteerId (UUID .randomUUID ())
3735 .recruitBoardId (1L )
38- .status (ApplyStatus . WAITING )
36+ .status (WAITING )
3937 .attended (false )
4038 .build ();
4139 volunteerApplyRepository .save (apply );
@@ -55,44 +53,41 @@ void setUp() {
5553 @ DisplayName ("봉사 신청 저장 및 조회" )
5654 @ Test
5755 void saveAndFindById () {
58- // Given
56+ // given
5957 VolunteerApply newApply = createApply (UUID .randomUUID (), 1L );
60- VolunteerApply savedApply = volunteerApplyRepository .save (newApply );
58+ volunteerApplyRepository .save (newApply );
6159
62- // When
63- Optional <VolunteerApply > foundApply = volunteerApplyRepository .findById (savedApply .getId ());
60+ // when
61+ Optional <VolunteerApply > foundApply = volunteerApplyRepository .findById (newApply .getId ());
6462
65- // Then
63+ // then
6664 assertThat (foundApply ).isPresent ();
67- assertThat (foundApply .get ().getId ()).isEqualTo (savedApply .getId ());
65+ assertThat (foundApply .get ().getId ()).isEqualTo (newApply .getId ());
6866 assertThat (foundApply .get ().getStatus ()).isEqualTo (APPROVED );
6967 }
7068
7169 @ DisplayName ("모집글 ID 리스트로 봉사자 ID 리스트 조회" )
7270 @ Test
7371 void findVolunteerIdsByRecruitIds () {
74- // When
75- List <UUID > volunteerIds = volunteerApplyRepository .findVolunteerIdsByRecruitIds (
76- List .of (1L , 2L ));
72+ // when
73+ List <UUID > volunteerIds = volunteerApplyRepository .findVolunteerIdsByRecruitIds (List .of (1L , 2L ));
7774
78- // Then
75+ // then
7976 assertThat (volunteerIds ).hasSize (20 );
8077 }
8178
8279 @ DisplayName ("모집글 ID로 페이징된 봉사 신청 조회" )
8380 @ Test
8481 void findAllByRecruitId () {
85- // Given
82+ // given
8683 PageRequest firstPage = PageRequest .of (0 , 10 , Sort .by (Sort .Order .asc ("created_at" )));
8784 PageRequest secondPage = PageRequest .of (1 , 10 , Sort .by (Sort .Order .asc ("created_at" )));
8885
89- // When
90- Page <VolunteerApply > firstPageResult = volunteerApplyRepository .findAllByRecruitId (1L ,
91- firstPage );
92- Page <VolunteerApply > secondPageResult = volunteerApplyRepository .findAllByRecruitId (1L ,
93- secondPage );
86+ // when
87+ Page <VolunteerApply > firstPageResult = volunteerApplyRepository .findAllByRecruitId (1L , firstPage );
88+ Page <VolunteerApply > secondPageResult = volunteerApplyRepository .findAllByRecruitId (1L , secondPage );
9489
95- // Then
90+ // then
9691 assertThat (firstPageResult .getContent ()).hasSize (10 );
9792 assertThat (firstPageResult .getTotalElements ()).isEqualTo (15 );
9893 assertThat (firstPageResult .getTotalPages ()).isEqualTo (2 );
@@ -115,8 +110,7 @@ void findByRecruitIdAndVolunteerId() {
115110 volunteerApplyRepository .save (newApply );
116111
117112 // when
118- Optional <VolunteerApply > findApply = volunteerApplyRepository .findByRecruitIdAndVolunteerId (
119- recruitId , volunteerId );
113+ Optional <VolunteerApply > findApply = volunteerApplyRepository .findByRecruitIdAndVolunteerId (recruitId , volunteerId );
120114
121115 // then
122116 assertThat (findApply ).isPresent ();
@@ -133,8 +127,7 @@ void existsByRecruitIdAndVolunteerId() {
133127 volunteerApplyRepository .save (newApply );
134128
135129 // when
136- boolean result = volunteerApplyRepository .existsByRecruitIdAndVolunteerId (recruitId ,
137- volunteerId );
130+ boolean result = volunteerApplyRepository .existsByRecruitIdAndVolunteerId (recruitId , volunteerId );
138131
139132 // then
140133 assertThat (result ).isTrue ();
@@ -173,28 +166,27 @@ void findAllByRecruitIdWithCondition() {
173166 .build ();
174167
175168 // when
176- Page <VolunteerApply > applies = volunteerApplyRepository .findAllByRecruitId (recruitBoardId ,
177- condition );
169+ Page <VolunteerApply > applies = volunteerApplyRepository .findAllByRecruitId (recruitBoardId , condition );
178170
179171 // then
180172 assertThat (applies .getTotalElements ()).isEqualTo (3 );
181173 assertThat (applies .getContent ())
182- .allMatch (apply -> apply .getStatus () == APPROVED && ! apply .getAttended ());
174+ .allMatch (apply -> apply .getStatus () == status && apply .getAttended () == attended );
183175
184176 }
185177
186178 @ DisplayName ("봉사자 아이디와 조건 - 지원 상태, 참석 여부로 페이징 조회할 수 있다." )
187179 @ Test
188180 void findAllByVolunteerId () {
189181 // given
190- UUID centerId = UUID .randomUUID ();
182+ UUID volunteerId = UUID .randomUUID ();
191183 ApplyStatus status = APPROVED ;
192184 Boolean attended = false ;
193185
194- volunteerApplyRepository .save (createApply (centerId , status , attended ));
195- volunteerApplyRepository .save (createApply (centerId , status , attended ));
196- volunteerApplyRepository .save (createApply (centerId , status , attended ));
197- volunteerApplyRepository .save (createApply (centerId , REJECTED , !attended ));
186+ volunteerApplyRepository .save (createApply (volunteerId , status , attended ));
187+ volunteerApplyRepository .save (createApply (volunteerId , status , attended ));
188+ volunteerApplyRepository .save (createApply (volunteerId , status , attended ));
189+ volunteerApplyRepository .save (createApply (volunteerId , REJECTED , !attended ));
198190
199191 VolunteerApplySearchCondition condition = VolunteerApplySearchCondition .builder ()
200192 .status (status )
@@ -203,13 +195,12 @@ void findAllByVolunteerId() {
203195 .build ();
204196
205197 // when
206- Page <VolunteerApply > applies = volunteerApplyRepository .findAllByVolunteerId (centerId ,
207- condition );
198+ Page <VolunteerApply > applies = volunteerApplyRepository .findAllByVolunteerId (volunteerId , condition );
208199
209200 // then
210201 assertThat (applies .getTotalElements ()).isEqualTo (3 );
211202 assertThat (applies .getContent ())
212- .allMatch (apply -> apply .getStatus () == APPROVED && ! apply .getAttended ());
203+ .allMatch (apply -> apply .getStatus () == status && apply .getAttended () == attended );
213204
214205 }
215206
@@ -250,8 +241,7 @@ private static VolunteerApply createApply(UUID volunteerId, Long recruitId) {
250241 .build ();
251242 }
252243
253- private static VolunteerApply createApply (Long recruitId , ApplyStatus status ,
254- Boolean attended ) {
244+ private static VolunteerApply createApply (Long recruitId , ApplyStatus status , Boolean attended ) {
255245 return VolunteerApply .builder ()
256246 .volunteerId (UUID .randomUUID ())
257247 .recruitBoardId (recruitId )
@@ -260,10 +250,9 @@ private static VolunteerApply createApply(Long recruitId, ApplyStatus status,
260250 .build ();
261251 }
262252
263- private static VolunteerApply createApply (UUID centerId , ApplyStatus status ,
264- Boolean attended ) {
253+ private static VolunteerApply createApply (UUID volunteerId , ApplyStatus status , Boolean attended ) {
265254 return VolunteerApply .builder ()
266- .volunteerId (centerId )
255+ .volunteerId (volunteerId )
267256 .recruitBoardId (101L )
268257 .status (status )
269258 .attended (attended )
0 commit comments