-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 행사 생성 API 예외 메세지 추가 및 DTO 검증 애너테이션 추가
- Loading branch information
1 parent
8ed9900
commit a90eafc
Showing
4 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 8 additions & 1 deletion
9
server/src/main/java/server/haengdong/presentation/request/EventSaveRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
server/src/test/java/server/haengdong/domain/event/EventTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package server.haengdong.domain.event; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
import server.haengdong.exception.HaengdongException; | ||
|
||
class EventTest { | ||
|
||
@DisplayName("공백 문자가 연속되지 않고, 이름이 2자 이상 20자 이하인 행사를 생성하면 예외가 발생하지 않는다.") | ||
@ParameterizedTest | ||
@ValueSource(strings = {"12", "12345678901234567890", "공 백", " 공백", "공백 ", " 공 백 "}) | ||
void createSuccessTest(String eventName) { | ||
assertThatCode(() -> new Event(eventName, "TEST_TOKEN")) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@DisplayName("공백 문자가 연속되면 예외가 발생한다.") | ||
@ParameterizedTest | ||
@ValueSource(strings = {" 공백", "공백 ", "공백 연속", "공 백"}) | ||
void createFailTest1(String eventName) { | ||
assertThatCode(() -> new Event(eventName, "TEST_TOKEN")) | ||
.isInstanceOf(HaengdongException.class) | ||
.hasMessage(String.format("행사 이름에는 공백 문자가 연속될 수 없습니다. 입력한 이름 : %s", eventName)); | ||
} | ||
|
||
@DisplayName("이름이 2자 미만이거나 20자 초과인 경우 예외가 발생한다.") | ||
@ParameterizedTest | ||
@ValueSource(strings = {"", " ", "123456789012345678901"}) | ||
void createFilTest2(String eventName) { | ||
assertThatCode(() -> new Event(eventName, "TEST_TOKEN")) | ||
.isInstanceOf(HaengdongException.class) | ||
.hasMessage(String.format("행사 이름은 2자 이상 20자 이하만 입력 가능합니다. 입력한 이름 길이 : %d", eventName.length())); | ||
} | ||
} |