Skip to content

Commit 75b9093

Browse files
committed
test(recruit-board): 모집글 Validator 추가에 따른 테스트
1 parent 2e6f8a9 commit 75b9093

File tree

2 files changed

+58
-4
lines changed

2 files changed

+58
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,27 +80,27 @@ void updateWithRegion() {
8080

8181
@DisplayName("올바른 기관 식별 값이 주어지면 작성자인지 확인할 수 있다")
8282
@Test
83-
void isWriterWithCorrectCenterId() {
83+
void isAuthorWithCorrectCenterId() {
8484
// given
8585
UUID centerId = UUID.randomUUID();
8686
RecruitBoard recruitBoard = createRecruitBoard(centerId);
8787

8888
// when
89-
boolean isWriter = recruitBoard.isWriter(centerId);
89+
boolean isWriter = recruitBoard.isAuthor(centerId);
9090

9191
// then
9292
assertThat(isWriter).isTrue();
9393
}
9494

9595
@DisplayName("잘못된 기관 식별 값이 주어지면 잘못된 작성자인 확인할 수있다.")
9696
@Test
97-
void isNotWriterWithWrongCenterId() {
97+
void isNotAuthorWithWrongCenterId() {
9898
UUID centerId = UUID.randomUUID();
9999
UUID wrongId = UUID.randomUUID();
100100
RecruitBoard recruitBoard = createRecruitBoard(centerId);
101101

102102
// when
103-
boolean isWriter = recruitBoard.isWriter(wrongId);
103+
boolean isWriter = recruitBoard.isAuthor(wrongId);
104104

105105
// then
106106
assertThat(isWriter).isFalse();
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.somemore.domains.recruitboard.service.validator;
2+
3+
import com.somemore.domains.recruitboard.domain.RecruitBoard;
4+
import com.somemore.global.exception.BadRequestException;
5+
import org.junit.jupiter.api.DisplayName;
6+
import org.junit.jupiter.api.Test;
7+
import org.junit.jupiter.params.ParameterizedTest;
8+
import org.junit.jupiter.params.provider.ValueSource;
9+
10+
import java.time.LocalDateTime;
11+
import java.util.UUID;
12+
13+
import static com.somemore.global.exception.ExceptionMessage.INVALID_RECRUIT_BOARD_TIME;
14+
import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_RECRUIT_BOARD;
15+
import static com.somemore.support.fixture.LocalDateTimeFixture.createStartDateTime;
16+
import static com.somemore.support.fixture.RecruitBoardFixture.createRecruitBoard;
17+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
18+
19+
class RecruitBoardValidatorTest {
20+
21+
private final RecruitBoardValidator validator = new RecruitBoardValidator();
22+
23+
@DisplayName("봉사 종료 시간이 시작 시간과 같거나 빠르면, 봉사 모집글 생성 시 에러가 발생한다")
24+
@ParameterizedTest
25+
@ValueSource(longs = {0, -1})
26+
void createRecruitBoardWithInValidVolunteerTime(long minutesOffset) {
27+
// given
28+
LocalDateTime now = createStartDateTime();
29+
LocalDateTime endDateTime = now.plusMinutes(minutesOffset);
30+
31+
// when & then
32+
assertThatThrownBy(
33+
() -> validator.validateRecruitBoardTime(now, endDateTime))
34+
.isInstanceOf(BadRequestException.class)
35+
.hasMessage(INVALID_RECRUIT_BOARD_TIME.getMessage());
36+
37+
}
38+
39+
@DisplayName("모집글 작성자가 아닌 경우 에러가 발생한다")
40+
@Test
41+
void validateAuthor() {
42+
// given
43+
UUID wrongCenterId = UUID.randomUUID();
44+
RecruitBoard board = createRecruitBoard(UUID.randomUUID());
45+
46+
// when
47+
// then
48+
assertThatThrownBy(
49+
() -> validator.validateAuthor(board, wrongCenterId))
50+
.isInstanceOf(BadRequestException.class)
51+
.hasMessage(UNAUTHORIZED_RECRUIT_BOARD.getMessage());
52+
}
53+
54+
}

0 commit comments

Comments
 (0)