Skip to content

Commit bae904f

Browse files
committed
test(recruit-board): 변경에 따른 테스트 수정 및 테스트 케이스 추가
1 parent 75b4ee5 commit bae904f

File tree

2 files changed

+60
-7
lines changed

2 files changed

+60
-7
lines changed

src/test/java/com/somemore/recruitboard/domain/RecruitBoardTest.java

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33
import static com.somemore.recruitboard.domain.RecruitStatus.RECRUITING;
44
import static com.somemore.recruitboard.domain.VolunteerType.OTHER;
55
import static org.assertj.core.api.Assertions.assertThat;
6+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
67

78
import java.time.LocalDateTime;
89
import java.time.LocalTime;
910
import java.util.UUID;
1011
import org.junit.jupiter.api.DisplayName;
1112
import org.junit.jupiter.api.Test;
13+
import org.junit.jupiter.params.ParameterizedTest;
14+
import org.junit.jupiter.params.provider.ValueSource;
1215

1316
class RecruitBoardTest {
1417

1518
@DisplayName("봉사 모집글 생성시 모집상태는 모집중이다")
1619
@Test
17-
void CreateRecruitBoardWithDefaultStatus() {
20+
void createRecruitBoardWithDefaultStatus() {
1821
// given
1922
RecruitBoard board = RecruitBoard.builder()
2023
.centerId(UUID.randomUUID())
@@ -24,9 +27,9 @@ void CreateRecruitBoardWithDefaultStatus() {
2427
.region("경기")
2528
.recruitmentCount(10)
2629
.imgUrl("https://image.domain.com/links")
27-
.volunteerDate(LocalDateTime.now())
30+
.volunteerStartDateTime(LocalDateTime.now())
31+
.volunteerEndDateTime(LocalDateTime.now().plusHours(1))
2832
.volunteerType(OTHER)
29-
.volunteerHours(LocalTime.of(7, 30))
3033
.admitted(true)
3134
.build();
3235

@@ -36,4 +39,55 @@ void CreateRecruitBoardWithDefaultStatus() {
3639
// then
3740
assertThat(recruitStatus).isEqualTo(RECRUITING);
3841
}
42+
43+
@DisplayName("봉사 종료 시간이 시작 시간과 같거나 빠르면, 봉사 모집글 생성 시 에러가 발생한다")
44+
@ParameterizedTest
45+
@ValueSource(longs = {0, -1})
46+
void createRecruitBoardWithInValidVolunteerTime(long secondsOffset) {
47+
// given
48+
LocalDateTime now = LocalDateTime.now();
49+
LocalDateTime endDateTime = now.plusSeconds(secondsOffset);
50+
51+
// when & then
52+
assertThatThrownBy(
53+
() -> RecruitBoard.builder()
54+
.centerId(UUID.randomUUID())
55+
.locationId(1L)
56+
.title("봉사모집제목")
57+
.content("봉사모집내용")
58+
.region("경기")
59+
.recruitmentCount(10)
60+
.imgUrl("https://image.domain.com/links")
61+
.volunteerStartDateTime(now)
62+
.volunteerEndDateTime(endDateTime)
63+
.volunteerType(VolunteerType.OTHER)
64+
.admitted(true)
65+
.build()
66+
).isInstanceOf(IllegalArgumentException.class);
67+
}
68+
69+
@DisplayName("봉사 시간을 계산할 수 있다")
70+
@Test
71+
void testCalculateVolunteerTime() {
72+
// given
73+
RecruitBoard board = RecruitBoard.builder()
74+
.centerId(UUID.randomUUID())
75+
.locationId(1L)
76+
.title("봉사모집제목")
77+
.content("봉사모집내용")
78+
.region("경기")
79+
.recruitmentCount(10)
80+
.imgUrl("https://image.domain.com/links")
81+
.volunteerStartDateTime(LocalDateTime.now())
82+
.volunteerEndDateTime(LocalDateTime.now().plusHours(3))
83+
.volunteerType(OTHER)
84+
.admitted(true)
85+
.build();
86+
87+
// when
88+
LocalTime volunteerTime = board.calculateVolunteerTime();
89+
90+
// then
91+
assertThat(volunteerTime).isEqualTo(LocalTime.of(3, 0));
92+
}
3993
}

src/test/java/com/somemore/recruitboard/service/command/CreateRecruitBoardServiceTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ void createRecruitBoardWithDto() {
5151
.content("봉사 하실분을 모집합니다. <br>")
5252
.region("지역")
5353
.recruitmentCount(10)
54-
.volunteerDate(LocalDateTime.now())
54+
.volunteerStartDateTime(LocalDateTime.now())
55+
.volunteerEndDateTime(LocalDateTime.now().plusHours(2))
5556
.volunteerType(VolunteerType.OTHER)
56-
.volunteerHours(1)
57-
.volunteerMinutes(30)
5857
.admitted(true)
5958
.location(locationDto)
6059
.build();
@@ -72,7 +71,7 @@ void createRecruitBoardWithDto() {
7271
assertThat(recruitBoard.get().getId()).isEqualTo(saveId);
7372
assertThat(recruitBoard.get().getCenterId()).isEqualTo(centerId);
7473
assertThat(recruitBoard.get().getImgUrl()).isEqualTo(imgUrl);
75-
assertThat(recruitBoard.get().getVolunteerHours()).isEqualTo(LocalTime.of(1, 30));
74+
assertThat(recruitBoard.get().calculateVolunteerTime()).isEqualTo(LocalTime.of(2, 0));
7675
}
7776

7877
}

0 commit comments

Comments
 (0)