From add77b18609b818bcb850bc44254258363295004 Mon Sep 17 00:00:00 2001 From: ParkJuHan94 <1004sunye@naver.com> Date: Tue, 9 Jan 2024 18:21:34 +0900 Subject: [PATCH] =?UTF-8?q?[feat]:=20=EC=9D=B8=ED=84=B0=EC=85=89=ED=84=B0?= =?UTF-8?q?=EC=99=80=20=EC=95=84=EA=B7=9C=EB=A8=BC=ED=8A=B8=EB=A6=AC?= =?UTF-8?q?=EC=A1=B8=EB=B2=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B0=81?= =?UTF-8?q?=EA=B0=81=EC=97=90=EC=84=9C=20@ExtendWith=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=EC=99=80=20setUp()=20=EC=9D=84=20=ED=95=84=EB=93=9C=EC=97=90?= =?UTF-8?q?=20=EC=A7=81=EC=A0=91=20=ED=95=A0=EB=8B=B9=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JwtAuthorizationArgumentResolverTest.java | 16 ++++++---------- .../java/dev/hooon/auth/JwtInterceptorTest.java | 16 +++++++--------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/api/src/test/java/dev/hooon/auth/JwtAuthorizationArgumentResolverTest.java b/api/src/test/java/dev/hooon/auth/JwtAuthorizationArgumentResolverTest.java index 2de4d9da..0a1d8426 100644 --- a/api/src/test/java/dev/hooon/auth/JwtAuthorizationArgumentResolverTest.java +++ b/api/src/test/java/dev/hooon/auth/JwtAuthorizationArgumentResolverTest.java @@ -4,11 +4,12 @@ import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.core.MethodParameter; import org.springframework.http.HttpHeaders; import org.springframework.mock.web.MockHttpServletRequest; @@ -17,12 +18,13 @@ import org.springframework.web.method.support.ModelAndViewContainer; import dev.hooon.auth.application.JwtProvider; +import dev.hooon.auth.jwt.JwtAuthorizationArgumentResolver; import dev.hooon.common.exception.NotFoundException; -import dev.hooon.common.support.ApiTestSupport; import jakarta.servlet.http.HttpServletRequest; @DisplayName("[JwtAuthorizationArgumentResolver 테스트]") -class JwtAuthorizationArgumentResolverTest extends ApiTestSupport { +@ExtendWith(MockitoExtension.class) +class JwtAuthorizationArgumentResolverTest { @InjectMocks private JwtAuthorizationArgumentResolver resolver; @@ -32,18 +34,12 @@ class JwtAuthorizationArgumentResolverTest extends ApiTestSupport { private MethodParameter parameter; @Mock private ModelAndViewContainer mavContainer; - private MockHttpServletRequest mockHttpServletRequest; + private final MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(); @Mock private NativeWebRequest webRequest; @Mock private WebDataBinderFactory binderFactory; - @BeforeEach - void setUp() { - mockHttpServletRequest = new MockHttpServletRequest(); - resolver = new JwtAuthorizationArgumentResolver(jwtProvider); - } - @Test @DisplayName("[토큰이 유효하면 claim 의 userId를 반환한다]") void shouldResolveArgumentWithValidToken() { diff --git a/api/src/test/java/dev/hooon/auth/JwtInterceptorTest.java b/api/src/test/java/dev/hooon/auth/JwtInterceptorTest.java index 07795f4d..254de9d2 100644 --- a/api/src/test/java/dev/hooon/auth/JwtInterceptorTest.java +++ b/api/src/test/java/dev/hooon/auth/JwtInterceptorTest.java @@ -4,38 +4,36 @@ import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.http.HttpHeaders; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.web.method.HandlerMethod; +import dev.hooon.auth.annotation.NoAuth; import dev.hooon.auth.application.JwtProvider; import dev.hooon.auth.exception.AuthException; -import dev.hooon.common.support.ApiTestSupport; +import dev.hooon.auth.jwt.JwtInterceptor; import jakarta.servlet.http.HttpServletResponse; @DisplayName("[JwtInterceptor 테스트]") -class JwtInterceptorTest extends ApiTestSupport { +@ExtendWith(MockitoExtension.class) +class JwtInterceptorTest { @InjectMocks private JwtInterceptor jwtInterceptor; @Mock private JwtProvider jwtProvider; - private MockHttpServletRequest request; + private final MockHttpServletRequest request = new MockHttpServletRequest(); @Mock private HttpServletResponse response; @Mock private HandlerMethod handlerMethod; - @BeforeEach - void setUp() { - request = new MockHttpServletRequest(); - } - @Test @DisplayName("[토큰이 없고 @NoAuth 있으면 -> 통과]") void shouldPassWithoutTokenWhenNoAuthAnnotationIsPresent() {