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(); } }