11package com .somemore .domains .recruitboard .service ;
22
3+ import static com .somemore .domains .recruitboard .domain .RecruitStatus .RECRUITING ;
4+ import static com .somemore .domains .recruitboard .domain .VolunteerCategory .ADMINISTRATIVE_SUPPORT ;
5+ import static com .somemore .domains .recruitboard .domain .VolunteerCategory .OTHER ;
6+ import static com .somemore .support .fixture .LocalDateTimeFixture .createCurrentDateTime ;
7+ import static com .somemore .support .fixture .LocalDateTimeFixture .createStartDateTime ;
8+ import static com .somemore .support .fixture .LocalDateTimeFixture .createUpdateStartDateTime ;
9+ import static org .assertj .core .api .Assertions .assertThat ;
10+ import static org .mockito .Mockito .doReturn ;
11+
312import com .somemore .domains .location .domain .Location ;
413import com .somemore .domains .location .repository .LocationRepository ;
514import com .somemore .domains .recruitboard .domain .RecruitBoard ;
1019import com .somemore .domains .recruitboard .repository .RecruitBoardJpaRepository ;
1120import com .somemore .domains .recruitboard .repository .RecruitBoardRepository ;
1221import com .somemore .support .IntegrationTestSupport ;
22+ import java .math .BigDecimal ;
23+ import java .time .Clock ;
24+ import java .time .LocalDateTime ;
25+ import java .time .ZoneId ;
26+ import java .util .UUID ;
1327import org .junit .jupiter .api .BeforeEach ;
1428import org .junit .jupiter .api .DisplayName ;
1529import org .junit .jupiter .api .Test ;
1630import org .springframework .beans .factory .annotation .Autowired ;
31+ import org .springframework .boot .test .mock .mockito .SpyBean ;
1732import org .springframework .transaction .annotation .Transactional ;
1833
19- import java .math .BigDecimal ;
20- import java .time .LocalDateTime ;
21- import java .util .UUID ;
22-
23- import static com .somemore .domains .recruitboard .domain .RecruitStatus .RECRUITING ;
24- import static com .somemore .domains .recruitboard .domain .VolunteerCategory .ADMINISTRATIVE_SUPPORT ;
25- import static com .somemore .domains .recruitboard .domain .VolunteerCategory .OTHER ;
26- import static com .somemore .support .fixture .LocalDateTimeFixture .*;
27- import static org .assertj .core .api .Assertions .assertThat ;
28-
2934@ Transactional
3035class UpdateRecruitBoardServiceTest extends IntegrationTestSupport {
3136
@@ -41,7 +46,11 @@ class UpdateRecruitBoardServiceTest extends IntegrationTestSupport {
4146 @ Autowired
4247 private LocationRepository locationRepository ;
4348
49+ @ SpyBean
50+ private Clock clock ;
51+
4452 private RecruitBoard recruitBoard ;
53+
4554 private UUID centerId ;
4655
4756 @ BeforeEach
@@ -73,8 +82,11 @@ void updateRecruitBoard() {
7382 .admitted (false )
7483 .build ();
7584
85+ setMockClock (current );
86+
7687 // when
77- updateRecruitBoardService .updateRecruitBoard (dto , recruitBoard .getId (), centerId , newImgUrl , current );
88+ updateRecruitBoardService .updateRecruitBoard (dto , recruitBoard .getId (), centerId ,
89+ newImgUrl );
7890
7991 // then
8092 RecruitBoard updatedRecruitBoard = recruitBoardRepository .findById (recruitBoard .getId ())
@@ -107,8 +119,10 @@ void updateRecruitBoardLocation() {
107119 .longitude (BigDecimal .valueOf (127.2222222 ))
108120 .build ();
109121
122+ setMockClock (current );
123+
110124 // when
111- updateRecruitBoardService .updateRecruitBoardLocation (dto , recruitBoard .getId (), centerId , current );
125+ updateRecruitBoardService .updateRecruitBoardLocation (dto , recruitBoard .getId (), centerId );
112126
113127 // then
114128 RecruitBoard updateRecruitBoard = recruitBoardRepository .findById (recruitBoard .getId ())
@@ -130,10 +144,12 @@ void updateRecruitBoardStatus() {
130144 // given
131145 Long recruitBoardId = recruitBoard .getId ();
132146 RecruitStatus newStatus = RecruitStatus .CLOSED ;
133- LocalDateTime currentDateTime = createCurrentDateTime ();
147+ LocalDateTime current = createCurrentDateTime ();
148+
149+ setMockClock (current );
134150
135151 // when
136- updateRecruitBoardService .updateRecruitBoardStatus (newStatus , recruitBoardId , centerId , currentDateTime );
152+ updateRecruitBoardService .updateRecruitBoardStatus (newStatus , recruitBoardId , centerId );
137153
138154 // then
139155 RecruitBoard findBoard = recruitBoardRepository .findById (recruitBoardId ).orElseThrow ();
@@ -147,7 +163,8 @@ private static RecruitBoard createRecruitBoard(UUID centerId, Long locationId) {
147163 return createRecruitBoard (centerId , locationId , startDateTime , endDateTime );
148164 }
149165
150- private static RecruitBoard createRecruitBoard (UUID centerId , Long locationId , LocalDateTime startDateTime , LocalDateTime endDateTime ) {
166+ private static RecruitBoard createRecruitBoard (UUID centerId , Long locationId ,
167+ LocalDateTime startDateTime , LocalDateTime endDateTime ) {
151168
152169 RecruitmentInfo recruitmentInfo = RecruitmentInfo .builder ()
153170 .region ("경기" )
@@ -177,4 +194,10 @@ private static Location createLocation() {
177194 .latitude (BigDecimal .valueOf (127.11111 ))
178195 .build ();
179196 }
197+
198+ private void setMockClock (LocalDateTime current ) {
199+ doReturn (current .atZone (ZoneId .systemDefault ()).toInstant ())
200+ .when (clock )
201+ .instant ();
202+ }
180203}
0 commit comments