Skip to content

Commit 528402b

Browse files
committed
feat: MentorSlotValidatorTest 추가
1 parent 0b2cbe7 commit 528402b

File tree

4 files changed

+155
-4
lines changed

4 files changed

+155
-4
lines changed

back/src/main/java/com/back/domain/mentoring/slot/error/MentorSlotErrorCode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
public enum MentorSlotErrorCode implements ErrorCode {
1010

1111
// 400 DateTime 체크
12-
START_TIME_REQUIRED("400-1", "시작 일시와 종료 일시는 필수입니다."),
13-
END_TIME_REQUIRED("400-2", "시작 일시와 종료 일시는 필수입니다."),
12+
START_TIME_REQUIRED("400-1", "시작 일시는 필수입니다."),
13+
END_TIME_REQUIRED("400-2", "종료 일시는 필수입니다."),
1414
START_TIME_IN_PAST("400-3", "시작 일시는 현재 이후여야 합니다."),
1515
END_TIME_BEFORE_START("400-4", "종료 일시는 시작 일시보다 이후여야 합니다."),
16-
INSUFFICIENT_SLOT_DURATION("400-5", "슬롯은 최소 30분 이상이어야 합니다."),
16+
INSUFFICIENT_SLOT_DURATION("400-5", "슬롯은 최소 20분 이상이어야 합니다."),
1717

1818
// 400 Slot 체크
1919
CANNOT_UPDATE_RESERVED_SLOT("400-6", "예약된 슬롯은 수정할 수 없습니다."),

back/src/main/java/com/back/global/exception/ServiceException.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.back.global.exception;
22

33
import com.back.global.rsData.RsData;
4+
import lombok.Getter;
45

56
public class ServiceException extends RuntimeException {
7+
@Getter
68
private final String resultCode;
79
private final String msg;
810

back/src/test/java/com/back/domain/mentoring/slot/controller/MentorSlotControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void setUp() {
6262
Member mentorMember = memberFixture.createMentorMember();
6363
mentor = memberFixture.createMentor(mentorMember);
6464

65-
// // JWT 발급
65+
// JWT 발급
6666
mentorToken = authTokenService.genAccessToken(mentorMember);
6767

6868
// Mentoring
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
package com.back.domain.mentoring.slot.service;
2+
3+
import com.back.domain.mentoring.slot.error.MentorSlotErrorCode;
4+
import com.back.global.exception.ServiceException;
5+
import org.junit.jupiter.api.DisplayName;
6+
import org.junit.jupiter.api.Test;
7+
8+
import java.time.LocalDateTime;
9+
10+
import static org.junit.jupiter.api.Assertions.*;
11+
12+
class MentorSlotValidatorTest {
13+
14+
@Test
15+
@DisplayName("시작 일시, 종료 일시 기입 시 정상 처리")
16+
void validateNotNull_success() {
17+
// given
18+
LocalDateTime start = LocalDateTime.now().plusHours(1);
19+
LocalDateTime end = LocalDateTime.now().plusHours(2);
20+
21+
// when & then
22+
assertDoesNotThrow(() -> MentorSlotValidator.validateNotNull(start, end));
23+
}
24+
25+
@Test
26+
@DisplayName("시작 일시 누락 시 예외 발생")
27+
void validateNotNull_fail_startNull() {
28+
// given
29+
LocalDateTime end = LocalDateTime.now().plusHours(1);
30+
31+
// when & then
32+
ServiceException exception = assertThrows(ServiceException.class,
33+
() -> MentorSlotValidator.validateNotNull(null, end));
34+
35+
assertEquals(MentorSlotErrorCode.START_TIME_REQUIRED.getCode(), exception.getResultCode());
36+
}
37+
38+
@Test
39+
@DisplayName("종료 일시 누락 시 예외 발생")
40+
void validateNotNull_fail_endNull() {
41+
// given
42+
LocalDateTime start = LocalDateTime.now().plusHours(1);
43+
44+
// when & then
45+
ServiceException exception = assertThrows(ServiceException.class,
46+
() -> MentorSlotValidator.validateNotNull(start, null));
47+
48+
assertEquals(MentorSlotErrorCode.END_TIME_REQUIRED.getCode(), exception.getResultCode());
49+
}
50+
51+
@Test
52+
@DisplayName("현재 이후의 시작 일시, 종료 일시 기입 시 정상 처리")
53+
void validateTimeRange_success() {
54+
// given
55+
LocalDateTime start = LocalDateTime.now().plusHours(1);
56+
LocalDateTime end = start.plusHours(1);
57+
58+
// when & then
59+
assertDoesNotThrow(() -> MentorSlotValidator.validateTimeRange(start, end));
60+
}
61+
62+
@Test
63+
@DisplayName("시작 일시가 현재보다 이전이면 예외 발생")
64+
void validateTimeRange_fail_startTimeInPast() {
65+
// given
66+
LocalDateTime start = LocalDateTime.now().minusHours(1);
67+
LocalDateTime end = LocalDateTime.now().plusHours(1);
68+
69+
// when & then
70+
ServiceException exception = assertThrows(ServiceException.class,
71+
() -> MentorSlotValidator.validateTimeRange(start, end));
72+
73+
assertEquals(MentorSlotErrorCode.START_TIME_IN_PAST.getCode(), exception.getResultCode());
74+
}
75+
76+
@Test
77+
@DisplayName("종료 일시가 시작 일시보다 이전이면 예외 발생")
78+
void validateTimeRange_fail_endTimeBeforeStart() {
79+
// given
80+
LocalDateTime start = LocalDateTime.now().plusHours(2);
81+
LocalDateTime end = LocalDateTime.now().plusHours(1);
82+
83+
// when & then
84+
ServiceException exception = assertThrows(ServiceException.class,
85+
() -> MentorSlotValidator.validateTimeRange(start, end));
86+
87+
assertEquals(MentorSlotErrorCode.END_TIME_BEFORE_START.getCode(), exception.getResultCode());
88+
}
89+
90+
@Test
91+
@DisplayName("20분 이상의 슬롯 기간 입력 시 정상 처리")
92+
void validateMinimumDuration_success() {
93+
// given
94+
LocalDateTime start = LocalDateTime.now().plusHours(1);
95+
LocalDateTime end = start.plusHours(1);
96+
97+
// when & then
98+
assertDoesNotThrow(() -> MentorSlotValidator.validateMinimumDuration(start, end));
99+
}
100+
101+
@Test
102+
@DisplayName("정확히 20분인 경우 정상 처리")
103+
void validateMinimumDuration_success_exactly20Minutes() {
104+
// given
105+
LocalDateTime start = LocalDateTime.now().plusHours(1);
106+
LocalDateTime end = start.plusMinutes(20);
107+
108+
// when & then
109+
assertDoesNotThrow(() -> MentorSlotValidator.validateMinimumDuration(start, end));
110+
}
111+
112+
@Test
113+
@DisplayName("슬롯 기간이 최소 시간(20분)보다 짧으면 예외 발생")
114+
void validateMinimumDuration_fail_insufficientSlotDuration() {
115+
// given
116+
LocalDateTime start = LocalDateTime.now().plusHours(1);
117+
LocalDateTime end = start.plusMinutes(19);
118+
119+
// when & then
120+
ServiceException exception = assertThrows(ServiceException.class,
121+
() -> MentorSlotValidator.validateMinimumDuration(start, end));
122+
123+
assertEquals(MentorSlotErrorCode.INSUFFICIENT_SLOT_DURATION.getCode(), exception.getResultCode());
124+
}
125+
126+
@Test
127+
@DisplayName("모든 검증을 통과하는 정상 케이스")
128+
void validateTimeSlot_success() {
129+
// given
130+
LocalDateTime start = LocalDateTime.now().plusHours(1);
131+
LocalDateTime end = start.plusMinutes(30);
132+
133+
// when & then
134+
assertDoesNotThrow(() -> MentorSlotValidator.validateTimeSlot(start, end));
135+
}
136+
137+
@Test
138+
@DisplayName("validateTimeSlot 메소드에서 null 체크 예외 발생")
139+
void validateTimeSlot_fail_nullCheck() {
140+
// given
141+
LocalDateTime end = LocalDateTime.now().plusHours(1);
142+
143+
// when & then
144+
ServiceException exception = assertThrows(ServiceException.class,
145+
() -> MentorSlotValidator.validateTimeSlot(null, end));
146+
147+
assertEquals(MentorSlotErrorCode.START_TIME_REQUIRED.getCode(), exception.getResultCode());
148+
}
149+
}

0 commit comments

Comments
 (0)