From 5ed6b66f1555f9fad8d7128eaf1b70a2e9bf7258 Mon Sep 17 00:00:00 2001 From: swa07016 Date: Tue, 12 Mar 2024 19:39:57 +0900 Subject: [PATCH] =?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