-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d3f282
commit 389ce0c
Showing
1 changed file
with
44 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,57 @@ | ||
package com.gdschongik.gdsc.domain.email; | ||
package com.gdschongik.gdsc.domain.email.domain; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static com.gdschongik.gdsc.global.exception.ErrorCode.*; | ||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import com.gdschongik.gdsc.domain.member.domain.Member; | ||
import com.gdschongik.gdsc.global.common.constant.MemberConstant; | ||
import com.gdschongik.gdsc.global.exception.CustomException; | ||
import com.gdschongik.gdsc.global.exception.ErrorCode; | ||
import com.gdschongik.gdsc.global.util.email.HongikUnivEmailValidator; | ||
import java.util.Optional; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
@SpringBootTest | ||
@ActiveProfiles("test") | ||
class HongikUnivEmailValidatorTest { | ||
|
||
@Autowired | ||
private HongikUnivEmailValidator hongikUnivEmailValidator; | ||
HongikUnivEmailValidator hongikUnivEmailValidator = new HongikUnivEmailValidator(); | ||
|
||
@Test | ||
@DisplayName("'g.hongik.ac.kr' 도메인을 가진 이메일을 검증할 수 있다.") | ||
void validateEmailDomainTest() { | ||
// given | ||
String hongikDomainEmail = "[email protected]"; | ||
Optional<Member> optionalMember = Optional.empty(); | ||
|
||
assertThatCode(() -> hongikUnivEmailValidator.validate(hongikDomainEmail)) | ||
// when & then | ||
assertThatCode(() -> hongikUnivEmailValidator.validate(hongikDomainEmail, optionalMember)) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"[email protected]", "[email protected]", "[email protected]", "[email protected]"}) | ||
@DisplayName("'g.hongik.ac.kr'가 아닌 도메인을 가진 이메일을 입력하면 예외를 발생시킨다.") | ||
void validateEmailDomainMismatchTest(String email) { | ||
assertThatThrownBy(() -> hongikUnivEmailValidator.validate(email)) | ||
// given | ||
Optional<Member> optionalMember = Optional.empty(); | ||
|
||
// when & then | ||
assertThatThrownBy(() -> hongikUnivEmailValidator.validate(email, optionalMember)) | ||
.isInstanceOf(CustomException.class) | ||
.hasMessage(ErrorCode.UNIV_EMAIL_DOMAIN_MISMATCH.getMessage()); | ||
} | ||
|
||
@Test | ||
@DisplayName("Email의 '@' 앞 부분에는 연속되지 않은 점이 포함될 수 있다.") | ||
void validateEmailFormatWithDotsTest() { | ||
// given | ||
String email = "[email protected]"; | ||
Optional<Member> optionalMember = Optional.empty(); | ||
|
||
assertThatCode(() -> hongikUnivEmailValidator.validate(email)).doesNotThrowAnyException(); | ||
assertThatCode(() -> hongikUnivEmailValidator.validate(email, optionalMember)) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@ParameterizedTest | ||
|
@@ -61,17 +68,39 @@ void validateEmailFormatWithDotsTest() { | |
}) | ||
@DisplayName("Email의 '@' 앞 부분에 '&', '=', ''', '-', '+', ',', '<', '>'가 포함되는 경우 예외를 발생시킨다.") | ||
void validateEmailFormatMismatchTest(String email) { | ||
assertThatThrownBy(() -> hongikUnivEmailValidator.validate(email)) | ||
// given | ||
Optional<Member> optionalMember = Optional.empty(); | ||
|
||
// when & then | ||
assertThatThrownBy(() -> hongikUnivEmailValidator.validate(email, optionalMember)) | ||
.isInstanceOf(CustomException.class) | ||
.hasMessage(ErrorCode.UNIV_EMAIL_FORMAT_MISMATCH.getMessage()); | ||
} | ||
|
||
@Test | ||
@DisplayName("Email의 '@' 앞 부분에 '.'이 2개 연속 오는 경우 예외를 발생시킨다.") | ||
void validateEmailFormatMismatchWithDotsTest() { | ||
// given | ||
String email = "[email protected]"; | ||
assertThatThrownBy(() -> hongikUnivEmailValidator.validate(email)) | ||
Optional<Member> optionalMember = Optional.empty(); | ||
|
||
// when & then | ||
assertThatThrownBy(() -> hongikUnivEmailValidator.validate(email, optionalMember)) | ||
.isInstanceOf(CustomException.class) | ||
.hasMessage(ErrorCode.UNIV_EMAIL_FORMAT_MISMATCH.getMessage()); | ||
} | ||
|
||
@Test | ||
void 이미_가입된_재학생_메일이라면_실패한다() { | ||
// given | ||
String hongikDomainEmail = "[email protected]"; | ||
|
||
Member member = Member.createGuestMember(MemberConstant.OAUTH_ID); | ||
Optional<Member> optionalMember = Optional.of(member); | ||
|
||
// when & then | ||
assertThatThrownBy(() -> hongikUnivEmailValidator.validate(hongikDomainEmail, optionalMember)) | ||
.isInstanceOf(CustomException.class) | ||
.hasMessage(UNIV_EMAIL_ALREADY_SATISFIED.getMessage()); | ||
} | ||
} |