Skip to content

Commit

Permalink
[feat]: 인터셉터와 아규먼트리졸버 테스트 각각에서 @ExtendWith 추가와 setUp() 을 필드에 직접 할당으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
ParkJuhan94 committed Jan 9, 2024
1 parent 9a33959 commit add77b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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() {
Expand Down
16 changes: 7 additions & 9 deletions api/src/test/java/dev/hooon/auth/JwtInterceptorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit add77b1

Please sign in to comment.