Skip to content

Commit

Permalink
[BE] refactor: assertThatThrownBy.hasMessage()에서 ErrorCode를 활용하도록 수정 (#…
Browse files Browse the repository at this point in the history
…476) (#477)

* refactor: AdminAuthServiceTest 네이밍 수정

* refactor: assertThatThrownBy hasMessage ErrorCode.getMessage로 수정

* refactor: 잘못된 ErrorCode 수정
  • Loading branch information
xxeol2 authored and BGuga committed Oct 17, 2023
1 parent 4e227c0 commit 530887b
Show file tree
Hide file tree
Showing 24 changed files with 114 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.festago.application;

import static com.festago.common.exception.ErrorCode.MEMBER_TICKET_NOT_FOUND;
import static com.festago.common.exception.ErrorCode.NOT_ENTRY_TIME;
import static com.festago.common.exception.ErrorCode.NOT_MEMBER_TICKET_OWNER;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import static org.assertj.core.api.SoftAssertions.assertSoftly;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -98,7 +101,7 @@ class 티켓의_QR_생성_요청 {
// when & then
assertThatThrownBy(() -> entryService.createEntryCode(memberId, memberTicketId))
.isInstanceOf(BadRequestException.class)
.hasMessage("입장 가능한 시간이 아닙니다.");
.hasMessage(NOT_ENTRY_TIME.getMessage());
}

@Test
Expand Down Expand Up @@ -129,7 +132,7 @@ class 티켓의_QR_생성_요청 {
// when & then
assertThatThrownBy(() -> entryService.createEntryCode(memberId, memberTicketId))
.isInstanceOf(BadRequestException.class)
.hasMessage("입장 가능한 시간이 아닙니다.");
.hasMessage(NOT_ENTRY_TIME.getMessage());
}

@Test
Expand All @@ -151,7 +154,7 @@ class 티켓의_QR_생성_요청 {
// when & then
assertThatThrownBy(() -> entryService.createEntryCode(memberId, memberTicketId))
.isInstanceOf(BadRequestException.class)
.hasMessage("해당 예매 티켓의 주인이 아닙니다.");
.hasMessage(NOT_MEMBER_TICKET_OWNER.getMessage());
}

@Test
Expand All @@ -164,7 +167,7 @@ class 티켓의_QR_생성_요청 {
// when & then
assertThatThrownBy(() -> entryService.createEntryCode(1L, memberTicketId))
.isInstanceOf(NotFoundException.class)
.hasMessage("존재하지 않은 멤버 티켓입니다.");
.hasMessage(MEMBER_TICKET_NOT_FOUND.getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.festago.application;

import static com.festago.common.exception.ErrorCode.FESTIVAL_NOT_FOUND;
import static com.festago.common.exception.ErrorCode.INVALID_FESTIVAL_START_DATE;
import static com.festago.common.exception.ErrorCode.SCHOOL_NOT_FOUND;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -85,7 +88,7 @@ class 축제_생성 {
// when & then
assertThatThrownBy(() -> festivalService.create(request))
.isInstanceOf(NotFoundException.class)
.hasMessage("존재하지 않는 학교입니다.");
.hasMessage(SCHOOL_NOT_FOUND.getMessage());
}

@Test
Expand All @@ -101,7 +104,7 @@ class 축제_생성 {
// when & then
assertThatThrownBy(() -> festivalService.create(request))
.isInstanceOf(BadRequestException.class)
.hasMessage("축제 시작 일자는 과거일 수 없습니다.");
.hasMessage(INVALID_FESTIVAL_START_DATE.getMessage());
}

@Test
Expand Down Expand Up @@ -140,7 +143,7 @@ class 축제_상세_조회 {

// when & then
assertThatThrownBy(() -> festivalService.findDetail(festivalId)).isInstanceOf(NotFoundException.class)
.hasMessage("존재하지 않는 축제입니다.");
.hasMessage(FESTIVAL_NOT_FOUND.getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.festago.application;

import static com.festago.common.exception.ErrorCode.MEMBER_NOT_FOUND;
import static com.festago.common.exception.ErrorCode.MEMBER_TICKET_NOT_FOUND;
import static com.festago.common.exception.ErrorCode.NOT_MEMBER_TICKET_OWNER;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -67,7 +70,7 @@ class 사용자의_멤버티켓_전체_조회 {
// when & then
assertThatThrownBy(() -> memberTicketService.findAll(memberId, PageRequest.ofSize(1)))
.isInstanceOf(NotFoundException.class)
.hasMessage("존재하지 않는 멤버입니다.");
.hasMessage(MEMBER_NOT_FOUND.getMessage());
}
}

Expand All @@ -85,7 +88,7 @@ class 현재_멤버티켓_조회 {
// when & then
assertThatThrownBy(() -> memberTicketService.findCurrent(memberId, Pageable.ofSize(10)))
.isInstanceOf(NotFoundException.class)
.hasMessage("존재하지 않는 멤버입니다.");
.hasMessage(MEMBER_NOT_FOUND.getMessage());
}

@Test
Expand Down Expand Up @@ -188,7 +191,7 @@ class 멤버_티켓_아이디로_단건_조회 {
// when & then
assertThatThrownBy(() -> memberTicketService.findById(memberId, 1L))
.isInstanceOf(NotFoundException.class)
.hasMessage("존재하지 않는 멤버입니다.");
.hasMessage(MEMBER_NOT_FOUND.getMessage());
}

@Test
Expand All @@ -205,7 +208,7 @@ class 멤버_티켓_아이디로_단건_조회 {
// when & then
assertThatThrownBy(() -> memberTicketService.findById(memberId, memberTicketId))
.isInstanceOf(NotFoundException.class)
.hasMessage("존재하지 않은 멤버 티켓입니다.");
.hasMessage(MEMBER_TICKET_NOT_FOUND.getMessage());
}

@Test
Expand All @@ -230,7 +233,7 @@ class 멤버_티켓_아이디로_단건_조회 {
// when & then
assertThatThrownBy(() -> memberTicketService.findById(memberId, otherTicketId))
.isInstanceOf(BadRequestException.class)
.hasMessage("해당 예매 티켓의 주인이 아닙니다.");
.hasMessage(NOT_MEMBER_TICKET_OWNER.getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.festago.application;

import static com.festago.common.exception.ErrorCode.ALREADY_STUDENT_VERIFIED;
import static com.festago.common.exception.ErrorCode.DUPLICATE_STUDENT_EMAIL;
import static com.festago.common.exception.ErrorCode.INVALID_STUDENT_VERIFICATION_CODE;
import static com.festago.common.exception.ErrorCode.MEMBER_NOT_FOUND;
import static com.festago.common.exception.ErrorCode.SCHOOL_NOT_FOUND;
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -74,7 +79,7 @@ class 인증_메일_전송 {
// when & then
assertThatThrownBy(() -> studentService.sendVerificationMail(memberId, request))
.isInstanceOf(BadRequestException.class)
.hasMessage("이미 학교 인증이 완료된 사용자입니다.");
.hasMessage(ALREADY_STUDENT_VERIFIED.getMessage());
}

@Test
Expand All @@ -93,7 +98,7 @@ class 인증_메일_전송 {
// when & then
assertThatThrownBy(() -> studentService.sendVerificationMail(memberId, request))
.isInstanceOf(BadRequestException.class)
.hasMessage("이미 인증된 이메일입니다.");
.hasMessage(DUPLICATE_STUDENT_EMAIL.getMessage());
}

@Test
Expand All @@ -114,7 +119,7 @@ class 인증_메일_전송 {
// when & then
assertThatThrownBy(() -> studentService.sendVerificationMail(memberId, request))
.isInstanceOf(NotFoundException.class)
.hasMessage("존재하지 않는 멤버입니다.");
.hasMessage(MEMBER_NOT_FOUND.getMessage());
}

@Test
Expand Down Expand Up @@ -142,7 +147,7 @@ class 인증_메일_전송 {
// when & then
assertThatThrownBy(() -> studentService.sendVerificationMail(memberId, request))
.isInstanceOf(NotFoundException.class)
.hasMessage("존재하지 않는 학교입니다.");
.hasMessage(SCHOOL_NOT_FOUND.getMessage());
}


Expand Down Expand Up @@ -188,7 +193,7 @@ class 학생_인증 {
// when & then
assertThatThrownBy(() -> studentService.verificate(memberId, request))
.isInstanceOf(BadRequestException.class)
.hasMessage("이미 학교 인증이 완료된 사용자입니다.");
.hasMessage(ALREADY_STUDENT_VERIFIED.getMessage());
}

@Test
Expand All @@ -204,7 +209,7 @@ class 학생_인증 {
// when & then
assertThatThrownBy(() -> studentService.verificate(memberId, request))
.isInstanceOf(BadRequestException.class)
.hasMessage("올바르지 않은 학생 인증 코드입니다.");
.hasMessage(INVALID_STUDENT_VERIFICATION_CODE.getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.festago.application.integration;

import static com.festago.common.exception.ErrorCode.FESTIVAL_NOT_FOUND;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.festago.common.exception.NotFoundException;
Expand Down Expand Up @@ -37,6 +38,6 @@ class StageServiceIntegrationTest extends ApplicationIntegrationTest {
// when && then
assertThatThrownBy(() -> stageService.create(request))
.isInstanceOf(NotFoundException.class)
.hasMessage("존재하지 않는 축제입니다.");
.hasMessage(FESTIVAL_NOT_FOUND.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.festago.application.integration;

import static com.festago.common.exception.ErrorCode.STAGE_NOT_FOUND;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.doReturn;
Expand Down Expand Up @@ -68,7 +69,7 @@ class TicketServiceIntegrationTest extends ApplicationIntegrationTest {
// when && then
assertThatThrownBy(() -> ticketService.create(request))
.isInstanceOf(NotFoundException.class)
.hasMessage("존재하지 않은 공연입니다.");
.hasMessage(STAGE_NOT_FOUND.getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.festago.application.integration;

import static com.festago.common.exception.ErrorCode.RESERVE_TICKET_OVER_AMOUNT;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -90,6 +91,6 @@ class TicketingServiceIntegrationTest extends ApplicationIntegrationTest {
// when & then
assertThatThrownBy(() -> ticketingService.ticketing(memberId, request))
.isInstanceOf(BadRequestException.class)
.hasMessage("예매 가능한 수량을 초과했습니다.");
.hasMessage(RESERVE_TICKET_OVER_AMOUNT.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.festago.auth.application;

import static com.festago.common.exception.ErrorCode.DUPLICATE_ACCOUNT_USERNAME;
import static com.festago.common.exception.ErrorCode.INCORRECT_PASSWORD_OR_ACCOUNT;
import static com.festago.common.exception.ErrorCode.NOT_ENOUGH_PERMISSION;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.BDDMockito.any;
Expand Down Expand Up @@ -28,7 +31,7 @@
@DisplayNameGeneration(ReplaceUnderscores.class)
@SuppressWarnings("NonAsciiCharacters")
@ExtendWith(MockitoExtension.class)
class AdminAuthFacadeServiceTest {
class AdminAuthServiceTest {

@Mock
AuthProvider authProvider;
Expand All @@ -52,7 +55,7 @@ class 로그인 {
// when & then
assertThatThrownBy(() -> adminAuthService.login(request))
.isInstanceOf(UnauthorizedException.class)
.hasMessage("비밀번호가 틀렸거나, 해당 계정이 없습니다.");
.hasMessage(INCORRECT_PASSWORD_OR_ACCOUNT.getMessage());
}

@Test
Expand All @@ -66,7 +69,7 @@ class 로그인 {
// when & then
assertThatThrownBy(() -> adminAuthService.login(request))
.isInstanceOf(UnauthorizedException.class)
.hasMessage("비밀번호가 틀렸거나, 해당 계정이 없습니다.");
.hasMessage(INCORRECT_PASSWORD_OR_ACCOUNT.getMessage());
}

@Test
Expand Down Expand Up @@ -102,7 +105,7 @@ class 가입 {
// when & then
assertThatThrownBy(() -> adminAuthService.signup(1L, request))
.isInstanceOf(BadRequestException.class)
.hasMessage("해당 계정이 존재합니다.");
.hasMessage(DUPLICATE_ACCOUNT_USERNAME.getMessage());
}

@Test
Expand All @@ -115,7 +118,7 @@ class 가입 {
// when & then
assertThatThrownBy(() -> adminAuthService.signup(1L, request))
.isInstanceOf(ForbiddenException.class)
.hasMessage("해당 권한이 없습니다.");
.hasMessage(NOT_ENOUGH_PERMISSION.getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.festago.auth.application;

import static com.festago.common.exception.ErrorCode.MEMBER_NOT_FOUND;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand Down Expand Up @@ -92,7 +93,7 @@ class 회원탈퇴 {
// then
assertThatThrownBy(() -> authService.deleteMember(memberId))
.isInstanceOf(NotFoundException.class)
.hasMessage("존재하지 않는 멤버입니다.");
.hasMessage(MEMBER_NOT_FOUND.getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.festago.auth.domain;

import static com.festago.common.exception.ErrorCode.DUPLICATE_SOCIAL_TYPE;
import static com.festago.common.exception.ErrorCode.OAUTH2_NOT_SUPPORTED_SOCIAL_TYPE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -32,7 +34,7 @@ class OAuth2ClientsTest {
// when & then
assertThatThrownBy(() -> builder.add(new FestagoOAuth2Client()))
.isInstanceOf(InternalServerException.class)
.hasMessage("중복된 OAuth2 제공자 입니다.");
.hasMessage(DUPLICATE_SOCIAL_TYPE.getMessage());
}

@Test
Expand All @@ -44,7 +46,7 @@ class OAuth2ClientsTest {
// when & then
assertThatThrownBy(() -> oAuth2Clients.getClient(SocialType.FESTAGO))
.isInstanceOf(BadRequestException.class)
.hasMessage("해당 OAuth2 제공자는 지원되지 않습니다.");
.hasMessage(OAUTH2_NOT_SUPPORTED_SOCIAL_TYPE.getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.festago.auth.infrastructure;

import static com.festago.common.exception.ErrorCode.NOT_BEARER_TOKEN_TYPE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.BDDMockito.given;
Expand Down Expand Up @@ -43,7 +44,7 @@ class HeaderTokenExtractorTest {
// when & then
assertThatThrownBy(() -> headerTokenExtractor.extract(request))
.isInstanceOf(UnauthorizedException.class)
.hasMessage("Bearer 타입의 토큰이 아닙니다.");
.hasMessage(NOT_BEARER_TOKEN_TYPE.getMessage());
}

@Test
Expand Down
Loading

0 comments on commit 530887b

Please sign in to comment.