33import static com .somemore .recruitboard .domain .RecruitStatus .RECRUITING ;
44import static com .somemore .recruitboard .domain .VolunteerType .OTHER ;
55import static org .assertj .core .api .Assertions .assertThat ;
6+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
67
78import java .time .LocalDateTime ;
89import java .time .LocalTime ;
910import java .util .UUID ;
1011import org .junit .jupiter .api .DisplayName ;
1112import org .junit .jupiter .api .Test ;
13+ import org .junit .jupiter .params .ParameterizedTest ;
14+ import org .junit .jupiter .params .provider .ValueSource ;
1215
1316class 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}
0 commit comments