Skip to content

Commit 373638b

Browse files
committed
test(recruit-board): 시간 검증 로직 변경 테스트
- Service 계층에서 Clock 사용
1 parent e085aed commit 373638b

File tree

2 files changed

+41
-18
lines changed

2 files changed

+41
-18
lines changed

src/test/java/com/somemore/domains/recruitboard/controller/RecruitBoardCommandApiControllerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ void updateRecruitBoard() throws Exception {
150150

151151
given(imageUploadUseCase.uploadImage(any())).willReturn(mockImageUrl);
152152
willDoNothing().given(updateRecruitBoardUseCase)
153-
.updateRecruitBoard(any(), any(), any(UUID.class), anyString(), any());
153+
.updateRecruitBoard(any(), any(), any(UUID.class), anyString());
154154

155155
MockMultipartHttpServletRequestBuilder builder = multipart("/api/recruit-board/{id}", 1);
156156
builder.with(new RequestPostProcessor() {
@@ -187,7 +187,7 @@ void updateRecruitBoardLocation() throws Exception {
187187
.build();
188188

189189
willDoNothing().given(updateRecruitBoardUseCase)
190-
.updateRecruitBoardLocation(any(), any(), any(UUID.class), any());
190+
.updateRecruitBoardLocation(any(), any(), any(UUID.class));
191191

192192
String requestBody = objectMapper.writeValueAsString(requestDto);
193193

@@ -213,7 +213,7 @@ void updateRecruitBoardStatus() throws Exception {
213213
status);
214214
String requestBody = objectMapper.writeValueAsString(dto);
215215
willDoNothing().given(updateRecruitBoardUseCase)
216-
.updateRecruitBoardStatus(any(), any(), any(UUID.class), any(LocalDateTime.class));
216+
.updateRecruitBoardStatus(any(), any(), any(UUID.class));
217217

218218
// when
219219
mockMvc.perform(patch("/api/recruit-board/{id}", 1L)

src/test/java/com/somemore/domains/recruitboard/service/UpdateRecruitBoardServiceTest.java

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
package 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+
312
import com.somemore.domains.location.domain.Location;
413
import com.somemore.domains.location.repository.LocationRepository;
514
import com.somemore.domains.recruitboard.domain.RecruitBoard;
@@ -10,22 +19,18 @@
1019
import com.somemore.domains.recruitboard.repository.RecruitBoardJpaRepository;
1120
import com.somemore.domains.recruitboard.repository.RecruitBoardRepository;
1221
import 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;
1327
import org.junit.jupiter.api.BeforeEach;
1428
import org.junit.jupiter.api.DisplayName;
1529
import org.junit.jupiter.api.Test;
1630
import org.springframework.beans.factory.annotation.Autowired;
31+
import org.springframework.boot.test.mock.mockito.SpyBean;
1732
import 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
3035
class 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

Comments
 (0)