From 7938ff2a106d712e7298ad169812e0cba3c55eba Mon Sep 17 00:00:00 2001 From: swa07016 Date: Sun, 10 Mar 2024 20:24:53 +0900 Subject: [PATCH 1/6] =?UTF-8?q?:sparkles:=20Feat:=20NickName=20Feign=20Cli?= =?UTF-8?q?ent=20=EC=84=B8=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nickname/hwanmoo/client/NickNameClient.java | 17 +++++++++++++++++ .../feign/nickname/hwanmoo/dto/NickNameRes.java | 11 +++++++++++ 2 files changed, 28 insertions(+) create mode 100644 core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/client/NickNameClient.java create mode 100644 core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/dto/NickNameRes.java diff --git a/core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/client/NickNameClient.java b/core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/client/NickNameClient.java new file mode 100644 index 0000000..4120542 --- /dev/null +++ b/core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/client/NickNameClient.java @@ -0,0 +1,17 @@ +package com.example.briefinginfra.feign.nickname.hwanmoo.client; + +import com.example.briefinginfra.feign.nickname.hwanmoo.dto.NickNameRes; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@FeignClient( + name = "nickNameClient", + url = "https://nickname.hwanmoo.kr" +) +@Component +public interface NickNameClient { + @GetMapping(value = "/") + NickNameRes getNickName(@RequestParam(defaultValue = "json") String format, @RequestParam(defaultValue = "1") int count, @RequestParam(defaultValue = "8") int max_length); +} diff --git a/core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/dto/NickNameRes.java b/core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/dto/NickNameRes.java new file mode 100644 index 0000000..71ec2d1 --- /dev/null +++ b/core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/dto/NickNameRes.java @@ -0,0 +1,11 @@ +package com.example.briefinginfra.feign.nickname.hwanmoo.dto; + +import lombok.Getter; + +import java.util.List; + +@Getter +public class NickNameRes { + private List words; + private String seed; +} From 20d4dea10b684d8a09a6dfea2a20080edb493554 Mon Sep 17 00:00:00 2001 From: swa07016 Date: Sun, 10 Mar 2024 20:49:54 +0900 Subject: [PATCH 2/6] =?UTF-8?q?:sparkles:=20Feat:=20=EC=95=A0=ED=94=8C?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EB=9E=9C=EB=8D=A4=20=EB=8B=89?= =?UTF-8?q?=EB=84=A4=EC=9E=84=20=EC=84=B8=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../briefingcommon/common/constant/BriefingStatic.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 core/Briefing-Common/src/main/java/com/example/briefingcommon/common/constant/BriefingStatic.java diff --git a/core/Briefing-Common/src/main/java/com/example/briefingcommon/common/constant/BriefingStatic.java b/core/Briefing-Common/src/main/java/com/example/briefingcommon/common/constant/BriefingStatic.java new file mode 100644 index 0000000..30cd452 --- /dev/null +++ b/core/Briefing-Common/src/main/java/com/example/briefingcommon/common/constant/BriefingStatic.java @@ -0,0 +1,7 @@ +package com.example.briefingcommon.common.constant; + +public class BriefingStatic { + public static final String NICK_NAME_FORMAT = "json"; + public static final int NICK_NAME_COUNT = 1; + public static final int NICK_NAME_MAX_LENGTH = 8; +} From ad4bad9c7d3c9c281ee23134093b020dcf3ea091 Mon Sep 17 00:00:00 2001 From: swa07016 Date: Mon, 11 Mar 2024 15:52:03 +0900 Subject: [PATCH 3/6] =?UTF-8?q?:sparkles:=20Feat:=20=EB=8B=89=EB=84=A4?= =?UTF-8?q?=EC=9E=84=20=EC=83=9D=EC=84=B1=20=EA=B4=80=EB=A0=A8=20=EC=83=81?= =?UTF-8?q?=EC=88=98=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/business/MemberConverter.java | 3 ++- .../member/implement/MemberCommandService.java | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Briefing-Api/src/main/java/com/example/briefingapi/member/business/MemberConverter.java b/Briefing-Api/src/main/java/com/example/briefingapi/member/business/MemberConverter.java index 3eca6d3..8e72224 100644 --- a/Briefing-Api/src/main/java/com/example/briefingapi/member/business/MemberConverter.java +++ b/Briefing-Api/src/main/java/com/example/briefingapi/member/business/MemberConverter.java @@ -37,12 +37,13 @@ public static Member toMember(GoogleUserInfo googleUserInfo) { .build(); } - public static Member toMember(String appleSocialId) { + public static Member toMember(String appleSocialId, String nickName) { return Member.builder() // .profileImgUrl(googleUserInfo.getPicture()) // .nickName(googleUserInfo.getName()) .socialId(appleSocialId) .socialType(SocialType.APPLE) + .nickName(nickName) .role(MemberRole.ROLE_USER) .status(MemberStatus.ACTIVE) .build(); diff --git a/Briefing-Api/src/main/java/com/example/briefingapi/member/implement/MemberCommandService.java b/Briefing-Api/src/main/java/com/example/briefingapi/member/implement/MemberCommandService.java index d615540..8d96606 100644 --- a/Briefing-Api/src/main/java/com/example/briefingapi/member/implement/MemberCommandService.java +++ b/Briefing-Api/src/main/java/com/example/briefingapi/member/implement/MemberCommandService.java @@ -5,9 +5,11 @@ import java.security.PublicKey; import java.security.spec.RSAPublicKeySpec; import java.util.Base64; +import java.util.List; import java.util.Optional; import com.example.briefingapi.member.business.MemberConverter; +import com.example.briefingcommon.common.constant.BriefingStatic; import com.example.briefingcommon.domain.repository.FcmTokenRepository; import com.example.briefingcommon.domain.repository.member.MemberRepository; import com.example.briefingapi.member.presentation.dto.MemberRequest; @@ -16,10 +18,11 @@ import com.example.briefingcommon.entity.FcmToken; import com.example.briefingcommon.entity.Member; import com.example.briefingcommon.entity.enums.SocialType; +import com.example.briefinginfra.feign.nickname.hwanmoo.client.NickNameClient; import com.example.briefinginfra.feign.oauth.apple.client.AppleOauth2Client; import com.example.briefinginfra.feign.oauth.apple.dto.ApplePublicKey; import com.example.briefinginfra.feign.oauth.apple.dto.ApplePublicKeyList; -import com.example.briefinginfra.feign.oauth.google.client.GoogleOauth2Client; + import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; @@ -27,17 +30,19 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; - import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; import lombok.RequiredArgsConstructor; +import static com.example.briefingcommon.common.constant.BriefingStatic.*; + @Service @RequiredArgsConstructor public class MemberCommandService { private final MemberRepository memberRepository; private final AppleOauth2Client appleOauth2Client; + private final NickNameClient nickNameClient; private final FcmTokenRepository fcmTokenRepository; @@ -87,8 +92,12 @@ private Member loginWithApple(MemberRequest.LoginDTO request) { Optional foundMember = memberRepository.findBySocialIdAndSocialType(appleSocialId, SocialType.APPLE); + String nickName = ""; + List nickNameWords = nickNameClient.getNickName(NICK_NAME_FORMAT, NICK_NAME_COUNT, NICK_NAME_MAX_LENGTH).getWords(); + if(!nickNameWords.isEmpty()) nickName = nickNameWords.get(0); + return foundMember.isEmpty() - ? memberRepository.save(MemberConverter.toMember(appleSocialId)) + ? memberRepository.save(MemberConverter.toMember(appleSocialId, nickName)) : foundMember.get(); } From db5fdf6c84884fb6094077d9b28c928175aee424 Mon Sep 17 00:00:00 2001 From: swa07016 Date: Mon, 11 Mar 2024 16:34:41 +0900 Subject: [PATCH 4/6] =?UTF-8?q?:recycle:=20Refactor:=20=ED=81=B4=EB=9D=BC?= =?UTF-8?q?=EC=9D=B4=EC=96=B8=ED=8A=B8=20=EC=BD=94=EB=93=9C=EA=B0=80=20?= =?UTF-8?q?=EB=9E=9C=EB=8D=A4=20=EB=8B=89=EB=84=A4=EC=9E=84=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=97=90=20=EA=B4=80=EC=97=AC=ED=95=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EB=8F=84=EB=A1=9D=20Adapter=20=EC=A0=9C=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../implement/MemberCommandService.java | 11 ++-- .../hwanmoo/adapter/NickNameGenerator.java | 51 +++++++++++++++++++ 2 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/adapter/NickNameGenerator.java diff --git a/Briefing-Api/src/main/java/com/example/briefingapi/member/implement/MemberCommandService.java b/Briefing-Api/src/main/java/com/example/briefingapi/member/implement/MemberCommandService.java index 8d96606..82b7ab0 100644 --- a/Briefing-Api/src/main/java/com/example/briefingapi/member/implement/MemberCommandService.java +++ b/Briefing-Api/src/main/java/com/example/briefingapi/member/implement/MemberCommandService.java @@ -9,7 +9,6 @@ import java.util.Optional; import com.example.briefingapi.member.business.MemberConverter; -import com.example.briefingcommon.common.constant.BriefingStatic; import com.example.briefingcommon.domain.repository.FcmTokenRepository; import com.example.briefingcommon.domain.repository.member.MemberRepository; import com.example.briefingapi.member.presentation.dto.MemberRequest; @@ -18,7 +17,7 @@ import com.example.briefingcommon.entity.FcmToken; import com.example.briefingcommon.entity.Member; import com.example.briefingcommon.entity.enums.SocialType; -import com.example.briefinginfra.feign.nickname.hwanmoo.client.NickNameClient; +import com.example.briefinginfra.feign.nickname.hwanmoo.adapter.NickNameGenerator; import com.example.briefinginfra.feign.oauth.apple.client.AppleOauth2Client; import com.example.briefinginfra.feign.oauth.apple.dto.ApplePublicKey; import com.example.briefinginfra.feign.oauth.apple.dto.ApplePublicKeyList; @@ -34,15 +33,13 @@ import io.jsonwebtoken.Jwts; import lombok.RequiredArgsConstructor; -import static com.example.briefingcommon.common.constant.BriefingStatic.*; - @Service @RequiredArgsConstructor public class MemberCommandService { private final MemberRepository memberRepository; private final AppleOauth2Client appleOauth2Client; - private final NickNameClient nickNameClient; + private final NickNameGenerator nickNameGenerator; private final FcmTokenRepository fcmTokenRepository; @@ -92,9 +89,7 @@ private Member loginWithApple(MemberRequest.LoginDTO request) { Optional foundMember = memberRepository.findBySocialIdAndSocialType(appleSocialId, SocialType.APPLE); - String nickName = ""; - List nickNameWords = nickNameClient.getNickName(NICK_NAME_FORMAT, NICK_NAME_COUNT, NICK_NAME_MAX_LENGTH).getWords(); - if(!nickNameWords.isEmpty()) nickName = nickNameWords.get(0); + String nickName = nickNameGenerator.getOneRandomNickName(); return foundMember.isEmpty() ? memberRepository.save(MemberConverter.toMember(appleSocialId, nickName)) diff --git a/core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/adapter/NickNameGenerator.java b/core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/adapter/NickNameGenerator.java new file mode 100644 index 0000000..cb236f7 --- /dev/null +++ b/core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/adapter/NickNameGenerator.java @@ -0,0 +1,51 @@ +package com.example.briefinginfra.feign.nickname.hwanmoo.adapter; + +import com.example.briefinginfra.feign.nickname.hwanmoo.client.NickNameClient; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import java.util.List; + +import static com.example.briefingcommon.common.constant.BriefingStatic.*; +import static com.example.briefingcommon.common.constant.BriefingStatic.NICK_NAME_FORMAT; + +@Component +@RequiredArgsConstructor +public class NickNameGenerator { + private final NickNameClient nickNameClient; + + /** + * 기본 최대 길이를 사용하여 랜덤 닉네임을 생성하고 반환합니다. + * 이 메소드는 내부적으로 {@code getOneRandomNickNameWithDetails}를 호출합니다. + * + * @return 생성된 닉네임. 닉네임 생성에 실패한 경우 빈 문자열을 반환합니다. + */ + public String getOneRandomNickName() { + return getOneRandomNickNameWithDetails(NICK_NAME_MAX_LENGTH); + } + + /** + * 사용자가 지정한 최대 길이를 사용하여 랜덤 닉네임을 생성하고 반환합니다. + * 이 메소드는 내부적으로 {@code getOneRandomNickNameWithDetails}를 호출합니다. + * + * @param maxLength 생성할 닉네임의 최대 길이 + * @return 생성된 닉네임. 닉네임 생성에 실패한 경우 빈 문자열을 반환합니다. + */ + public String getOneRandomNickName(int maxLength) { + return getOneRandomNickNameWithDetails(maxLength); + } + + /** + * 지정된 최대 길이를 사용하여 랜덤 닉네임을 생성하고, 생성된 목록에서 첫 번째 닉네임을 반환합니다. + * 이 메소드는 내부적으로 {@code NickNameClient}를 사용하여 닉네임을 요청합니다. + * + * @param maxLength 생성할 닉네임의 최대 길이 + * @return 생성된 닉네임 중 첫 번째 닉네임. 닉네임 생성에 실패한 경우 빈 문자열을 반환합니다. + */ + private String getOneRandomNickNameWithDetails(int maxLength) { + List nickNameWords = nickNameClient.getNickName(NICK_NAME_FORMAT, NICK_NAME_COUNT, maxLength).getWords(); + if (!nickNameWords.isEmpty()) return nickNameWords.get(0); + return ""; + } +} + From 3d625cb4dc68cb450e8babdecfb8dc613145c5fa Mon Sep 17 00:00:00 2001 From: swa07016 Date: Mon, 11 Mar 2024 17:22:00 +0900 Subject: [PATCH 5/6] =?UTF-8?q?:white=5Fcheck=5Fmark:=20Test:=20NickNameGe?= =?UTF-8?q?nerator=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nickname/hwanmoo/dto/NickNameRes.java | 2 + .../briefinginfra/config/TestConfig.java | 20 +++++++++ .../adapter/NickNameGeneratorTest.java | 45 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 core/Briefing-Infra/src/test/java/com/example/briefinginfra/config/TestConfig.java create mode 100644 core/Briefing-Infra/src/test/java/com/example/briefinginfra/feign/nickname/hwanmoo/adapter/NickNameGeneratorTest.java diff --git a/core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/dto/NickNameRes.java b/core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/dto/NickNameRes.java index 71ec2d1..87a7587 100644 --- a/core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/dto/NickNameRes.java +++ b/core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/dto/NickNameRes.java @@ -1,10 +1,12 @@ package com.example.briefinginfra.feign.nickname.hwanmoo.dto; import lombok.Getter; +import lombok.Setter; import java.util.List; @Getter +@Setter public class NickNameRes { private List words; private String seed; diff --git a/core/Briefing-Infra/src/test/java/com/example/briefinginfra/config/TestConfig.java b/core/Briefing-Infra/src/test/java/com/example/briefinginfra/config/TestConfig.java new file mode 100644 index 0000000..2b4416f --- /dev/null +++ b/core/Briefing-Infra/src/test/java/com/example/briefinginfra/config/TestConfig.java @@ -0,0 +1,20 @@ +package com.example.briefinginfra.config; + +import com.example.briefinginfra.feign.nickname.hwanmoo.adapter.NickNameGenerator; +import com.example.briefinginfra.feign.nickname.hwanmoo.client.NickNameClient; +import org.mockito.Mockito; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; + +@TestConfiguration +public class TestConfig { + @Bean + public NickNameClient nickNameClient() { + return Mockito.mock(NickNameClient.class); + } + + @Bean + public NickNameGenerator nickNameGenerator(NickNameClient nickNameClient) { + return new NickNameGenerator(nickNameClient); + } +} diff --git a/core/Briefing-Infra/src/test/java/com/example/briefinginfra/feign/nickname/hwanmoo/adapter/NickNameGeneratorTest.java b/core/Briefing-Infra/src/test/java/com/example/briefinginfra/feign/nickname/hwanmoo/adapter/NickNameGeneratorTest.java new file mode 100644 index 0000000..bd24212 --- /dev/null +++ b/core/Briefing-Infra/src/test/java/com/example/briefinginfra/feign/nickname/hwanmoo/adapter/NickNameGeneratorTest.java @@ -0,0 +1,45 @@ +package com.example.briefinginfra.feign.nickname.hwanmoo.adapter; + +import com.example.briefinginfra.config.TestConfig; +import com.example.briefinginfra.feign.nickname.hwanmoo.client.NickNameClient; +import com.example.briefinginfra.feign.nickname.hwanmoo.dto.NickNameRes; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import java.util.Arrays; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration(classes = TestConfig.class) // 테스트 설정 클래스 지정 +class NickNameGeneratorTest { + @Autowired + private NickNameGenerator nickNameGenerator; + + @MockBean + private NickNameClient nickNameClient; + + @Test + @DisplayName("[NickNameGenerator] 랜덤 닉네임 생성") + void 랜덤_닉네임_생성() throws Exception { + // given + NickNameRes mockResponse = new NickNameRes(); + mockResponse.setWords(Arrays.asList("하품하는 프로도")); + when(nickNameClient.getNickName("json", 1, 8)).thenReturn(mockResponse); + + // when + String nickName = nickNameGenerator.getOneRandomNickName(); + + // then + assertThat(nickName).isNotNull(); + assertThat(nickName).isEqualTo("하품하는 프로도"); + } +} \ No newline at end of file From 5ed6b66f1555f9fad8d7128eaf1b70a2e9bf7258 Mon Sep 17 00:00:00 2001 From: swa07016 Date: Tue, 12 Mar 2024 19:39:57 +0900 Subject: [PATCH 6/6] =?UTF-8?q?:sparkles:=20Feat:=20=EA=B8=B0=EB=B3=B8=20?= =?UTF-8?q?=EB=8B=89=EB=84=A4=EC=9E=84=20=EC=84=B8=ED=8C=85=20&=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20words=20=EA=B8=B0=EB=B3=B8=20=EB=B9=88=20?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=ED=95=A0=EB=8B=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/constant/BriefingStatic.java | 2 ++ .../hwanmoo/adapter/NickNameGenerator.java | 2 +- .../nickname/hwanmoo/dto/NickNameRes.java | 3 ++- .../hwanmoo/adapter/NickNameGeneratorTest.java | 18 ++++++++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/core/Briefing-Common/src/main/java/com/example/briefingcommon/common/constant/BriefingStatic.java b/core/Briefing-Common/src/main/java/com/example/briefingcommon/common/constant/BriefingStatic.java index 30cd452..246158a 100644 --- a/core/Briefing-Common/src/main/java/com/example/briefingcommon/common/constant/BriefingStatic.java +++ b/core/Briefing-Common/src/main/java/com/example/briefingcommon/common/constant/BriefingStatic.java @@ -4,4 +4,6 @@ public class BriefingStatic { public static final String NICK_NAME_FORMAT = "json"; public static final int NICK_NAME_COUNT = 1; public static final int NICK_NAME_MAX_LENGTH = 8; + + public static final String DEFAULT_NICK_NAME = "하품하는 프로도"; } diff --git a/core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/adapter/NickNameGenerator.java b/core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/adapter/NickNameGenerator.java index cb236f7..37410ca 100644 --- a/core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/adapter/NickNameGenerator.java +++ b/core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/adapter/NickNameGenerator.java @@ -45,7 +45,7 @@ public String getOneRandomNickName(int maxLength) { private String getOneRandomNickNameWithDetails(int maxLength) { List nickNameWords = nickNameClient.getNickName(NICK_NAME_FORMAT, NICK_NAME_COUNT, maxLength).getWords(); if (!nickNameWords.isEmpty()) return nickNameWords.get(0); - return ""; + return DEFAULT_NICK_NAME; } } diff --git a/core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/dto/NickNameRes.java b/core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/dto/NickNameRes.java index 87a7587..d0c04fa 100644 --- a/core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/dto/NickNameRes.java +++ b/core/Briefing-Infra/src/main/java/com/example/briefinginfra/feign/nickname/hwanmoo/dto/NickNameRes.java @@ -3,11 +3,12 @@ import lombok.Getter; import lombok.Setter; +import java.util.ArrayList; import java.util.List; @Getter @Setter public class NickNameRes { - private List words; + private List words = new ArrayList<>(); private String seed; } diff --git a/core/Briefing-Infra/src/test/java/com/example/briefinginfra/feign/nickname/hwanmoo/adapter/NickNameGeneratorTest.java b/core/Briefing-Infra/src/test/java/com/example/briefinginfra/feign/nickname/hwanmoo/adapter/NickNameGeneratorTest.java index bd24212..5da84dc 100644 --- a/core/Briefing-Infra/src/test/java/com/example/briefinginfra/feign/nickname/hwanmoo/adapter/NickNameGeneratorTest.java +++ b/core/Briefing-Infra/src/test/java/com/example/briefinginfra/feign/nickname/hwanmoo/adapter/NickNameGeneratorTest.java @@ -1,5 +1,6 @@ package com.example.briefinginfra.feign.nickname.hwanmoo.adapter; +import com.example.briefingcommon.common.constant.BriefingStatic; import com.example.briefinginfra.config.TestConfig; import com.example.briefinginfra.feign.nickname.hwanmoo.client.NickNameClient; import com.example.briefinginfra.feign.nickname.hwanmoo.dto.NickNameRes; @@ -13,6 +14,7 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; +import java.util.ArrayList; import java.util.Arrays; import static org.assertj.core.api.Assertions.assertThat; @@ -42,4 +44,20 @@ class NickNameGeneratorTest { assertThat(nickName).isNotNull(); assertThat(nickName).isEqualTo("하품하는 프로도"); } + + @Test + @DisplayName("[NickNameGenerator] 랜덤 닉네임 생성 - 빈 리스트 (기본 닉네임)") + void 랜덤_닉네임_생성_기본_닉네임() throws Exception { + // given + NickNameRes mockResponse = new NickNameRes(); + when(nickNameClient.getNickName("json", 1, 8)).thenReturn(mockResponse); + + // when + String nickName = nickNameGenerator.getOneRandomNickName(); + + // then + assertThat(nickName).isNotNull(); + assertThat(nickName).isEqualTo(BriefingStatic.DEFAULT_NICK_NAME); + } + } \ No newline at end of file