From 4d0f9f0f874932208633cf858a111c1a3bfde0b9 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Thu, 8 Feb 2024 16:24:34 +0900 Subject: [PATCH] =?UTF-8?q?PET-300=20fix=20:=20=EC=9A=94=EC=B2=AD=EC=9D=84?= =?UTF-8?q?=20=EB=B3=B4=EB=82=B8=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=EC=8B=9C=20static=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C=EB=A1=9C=20=ED=98=B8=EC=B6=9C=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../userapplication/service/UserAuthorityGetUseCase.java | 3 ++- .../service/UserAuthorityGetUseCaseTest.java | 9 ++++++--- .../main/java/com/pawith/userdomain/utils/UserUtils.java | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Domain-Module/User-Module/User-Application/src/main/java/com/pawith/userapplication/service/UserAuthorityGetUseCase.java b/Domain-Module/User-Module/User-Application/src/main/java/com/pawith/userapplication/service/UserAuthorityGetUseCase.java index 38a31d2f..1d039255 100644 --- a/Domain-Module/User-Module/User-Application/src/main/java/com/pawith/userapplication/service/UserAuthorityGetUseCase.java +++ b/Domain-Module/User-Module/User-Application/src/main/java/com/pawith/userapplication/service/UserAuthorityGetUseCase.java @@ -12,9 +12,10 @@ public class UserAuthorityGetUseCase { private final UserAuthorityQueryService userAuthorityQueryService; + private final UserUtils userUtils; public UserAuthorityInfoResponse getUserAuthority() { - final Long userId = UserUtils.getIdFromAccessUser(); + final Long userId = userUtils.getIdFromAccessUser(); final UserAuthority userAuthority = userAuthorityQueryService.findByUserId(userId); return new UserAuthorityInfoResponse(userAuthority.getAuthority()); } diff --git a/Domain-Module/User-Module/User-Application/src/test/java/com/pawith/userapplication/service/UserAuthorityGetUseCaseTest.java b/Domain-Module/User-Module/User-Application/src/test/java/com/pawith/userapplication/service/UserAuthorityGetUseCaseTest.java index 331330c5..6df3ef84 100644 --- a/Domain-Module/User-Module/User-Application/src/test/java/com/pawith/userapplication/service/UserAuthorityGetUseCaseTest.java +++ b/Domain-Module/User-Module/User-Application/src/test/java/com/pawith/userapplication/service/UserAuthorityGetUseCaseTest.java @@ -6,6 +6,7 @@ import com.pawith.userapplication.dto.response.UserAuthorityInfoResponse; import com.pawith.userdomain.entity.UserAuthority; import com.pawith.userdomain.service.UserAuthorityQueryService; +import com.pawith.userdomain.utils.UserUtils; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -20,13 +21,14 @@ class UserAuthorityGetUseCaseTest { @Mock - UserAuthorityQueryService userAuthorityQueryService; + private UserAuthorityQueryService userAuthorityQueryService; + @Mock + private UserUtils userUtils; UserAuthorityGetUseCase userAuthorityGetUseCase; - @BeforeEach void init() { - userAuthorityGetUseCase = new UserAuthorityGetUseCase(userAuthorityQueryService); + userAuthorityGetUseCase = new UserAuthorityGetUseCase(userAuthorityQueryService, userUtils); } @Test @@ -37,6 +39,7 @@ void getUserAuthority() { final UserAuthority userAuthority = FixtureMonkeyUtils.getReflectionbasedFixtureMonkey() .giveMeBuilder(UserAuthority.class) .sample(); + given(userUtils.getIdFromAccessUser()).willReturn(userAuthority.getUser().getId()); given(userAuthorityQueryService.findByUserId(anyLong())).willReturn(userAuthority); //when UserAuthorityInfoResponse result = userAuthorityGetUseCase.getUserAuthority(); diff --git a/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/utils/UserUtils.java b/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/utils/UserUtils.java index 2015e2ee..8dd9bb20 100644 --- a/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/utils/UserUtils.java +++ b/Domain-Module/User-Module/User-Domain/src/main/java/com/pawith/userdomain/utils/UserUtils.java @@ -19,7 +19,7 @@ public User getAccessUser(){ return userQueryService.findById(userId); } - public static Long getIdFromAccessUser(){ + public Long getIdFromAccessUser(){ return SecurityUtils.getAuthenticationPrincipal(); } }