From 5173b0b3663675747736e787943e21a4a466b8d2 Mon Sep 17 00:00:00 2001 From: "HyunSeo Park (Hyena)" Date: Thu, 21 Sep 2023 14:07:16 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B9=83=ED=97=88=EB=B8=8C=20=EC=86=8C?= =?UTF-8?q?=EC=85=9C=20=ED=9A=8C=EC=9B=90=20=EA=B0=80=EC=9E=85=EC=8B=9C=20?= =?UTF-8?q?=EA=B3=84=EC=A0=95=EC=9D=98=20=EB=8B=89=EB=84=A4=EC=9E=84?= =?UTF-8?q?=EC=9D=B4=20=EC=97=86=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20=EA=B8=B0?= =?UTF-8?q?=EB=B3=B8=EA=B0=92=EC=9C=BC=EB=A1=9C=20=EC=A0=80=EC=9E=A5=20(#5?= =?UTF-8?q?89)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix: 사용자 이름 null 로 생성시 기본값 '익명의 사용자'를 사용하도록 수정 --- .../baton/domain/member/vo/MemberName.java | 12 +++++------- .../github/response/GithubMemberResponse.java | 3 ++- .../touch/baton/domain/member/MemberTest.java | 16 +++++++++------- .../domain/member/vo/MemberNameTest.java | 19 +++++++++++++++++++ .../baton/domain/member/vo/NameTest.java | 16 ---------------- 5 files changed, 35 insertions(+), 31 deletions(-) create mode 100644 backend/baton/src/test/java/touch/baton/domain/member/vo/MemberNameTest.java delete mode 100644 backend/baton/src/test/java/touch/baton/domain/member/vo/NameTest.java diff --git a/backend/baton/src/main/java/touch/baton/domain/member/vo/MemberName.java b/backend/baton/src/main/java/touch/baton/domain/member/vo/MemberName.java index 2a4dcd958..2c900d3f8 100644 --- a/backend/baton/src/main/java/touch/baton/domain/member/vo/MemberName.java +++ b/backend/baton/src/main/java/touch/baton/domain/member/vo/MemberName.java @@ -16,17 +16,15 @@ @Embeddable public class MemberName { + private static final String DEFAULT_VALUE = "익명의 사용자"; + @Column(name = "name", nullable = false) - private String value; + private String value = DEFAULT_VALUE; public MemberName(final String value) { - validateNotNull(value); - this.value = value; - } - - private void validateNotNull(final String value) { if (Objects.isNull(value)) { - throw new IllegalArgumentException("MemberName 객체 내부에 name 은 null 일 수 없습니다."); + return; } + this.value = value; } } diff --git a/backend/baton/src/main/java/touch/baton/infra/auth/oauth/github/response/GithubMemberResponse.java b/backend/baton/src/main/java/touch/baton/infra/auth/oauth/github/response/GithubMemberResponse.java index 05e5001c7..9a3db4030 100644 --- a/backend/baton/src/main/java/touch/baton/infra/auth/oauth/github/response/GithubMemberResponse.java +++ b/backend/baton/src/main/java/touch/baton/infra/auth/oauth/github/response/GithubMemberResponse.java @@ -1,6 +1,7 @@ package touch.baton.infra.auth.oauth.github.response; import com.fasterxml.jackson.databind.annotation.JsonNaming; +import jakarta.annotation.Nullable; import touch.baton.domain.member.vo.GithubUrl; import touch.baton.domain.member.vo.ImageUrl; import touch.baton.domain.member.vo.MemberName; @@ -13,7 +14,7 @@ @JsonNaming(SnakeCaseStrategy.class) public record GithubMemberResponse(String id, - String name, + @Nullable String name, String login, String htmlUrl, String avatarUrl diff --git a/backend/baton/src/test/java/touch/baton/domain/member/MemberTest.java b/backend/baton/src/test/java/touch/baton/domain/member/MemberTest.java index a3ff8dbc1..d1fe576e9 100644 --- a/backend/baton/src/test/java/touch/baton/domain/member/MemberTest.java +++ b/backend/baton/src/test/java/touch/baton/domain/member/MemberTest.java @@ -37,19 +37,21 @@ void success() { ).doesNotThrowAnyException(); } - @DisplayName("이름에 null 이 들어갈 경우 예외가 발생한다.") + @DisplayName("이름에 null 이 들어갈 경우 기본값으로 생성한다.") @Test - void fail_if_name_is_null() { - assertThatThrownBy(() -> Member.builder() - .memberName(null) + void success_if_name_is_null_then_default_value() { + // given + final Member member = Member.builder() + .memberName(new MemberName(null)) .socialId(new SocialId("testSocialId")) .oauthId(new OauthId("dsigjh98gh230gn2oinv913bcuo23nqovbvu93b12voi3bc31j")) .githubUrl(new GithubUrl("github.com/hyena0608")) .company(new Company("우아한형제들")) .imageUrl(new ImageUrl("imageUrl")) - .build() - ).isInstanceOf(MemberDomainException.class) - .hasMessage("Member 의 name 은 null 일 수 없습니다."); + .build(); + + // when, then + assertThat(member.getMemberName()).isEqualTo(new MemberName("익명의 사용자")); } @DisplayName("socialId에 null 이 들어갈 경우 예외가 발생한다.") diff --git a/backend/baton/src/test/java/touch/baton/domain/member/vo/MemberNameTest.java b/backend/baton/src/test/java/touch/baton/domain/member/vo/MemberNameTest.java new file mode 100644 index 000000000..6cf5fef9c --- /dev/null +++ b/backend/baton/src/test/java/touch/baton/domain/member/vo/MemberNameTest.java @@ -0,0 +1,19 @@ +package touch.baton.domain.member.vo; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class MemberNameTest { + + @DisplayName("value 가 null 이면 기본값으로_생성한다") + @Test + void fail_if_value_is_null_then_default_value() { + // given + final MemberName memberName = new MemberName(null); + + // when, then + assertThat(memberName.getValue()).isEqualTo("익명의 사용자"); + } +} diff --git a/backend/baton/src/test/java/touch/baton/domain/member/vo/NameTest.java b/backend/baton/src/test/java/touch/baton/domain/member/vo/NameTest.java deleted file mode 100644 index 062e90c46..000000000 --- a/backend/baton/src/test/java/touch/baton/domain/member/vo/NameTest.java +++ /dev/null @@ -1,16 +0,0 @@ -package touch.baton.domain.member.vo; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -class NameTest { - - @DisplayName("value 가 null 이면 예외가 발생한다.") - @Test - void fail_if_value_is_null() { - assertThatThrownBy(() -> new MemberName(null)) - .isInstanceOf(IllegalArgumentException.class); - } -}