22
33import static org .assertj .core .api .Assertions .assertThat ;
44import static org .assertj .core .api .Assertions .assertThatCode ;
5- import static org .assertj . core .api .Assertions .assertThatThrownBy ;
5+ import static org .junit . jupiter .api .Assertions .assertThrows ;
66
77import java .time .Duration ;
88import org .junit .jupiter .api .Nested ;
99import org .junit .jupiter .api .Test ;
10+ import timeeat .exception .BusinessErrorCode ;
11+ import timeeat .exception .BusinessException ;
1012
1113class JwtManagerTest {
1214
@@ -59,28 +61,31 @@ class ResolveAccessToken {
5961 long id = 12345L ;
6062 String accessToken = jwtManager .issueAccessToken (id );
6163
62- assertThatThrownBy (() -> jwtManager .resolveAccessToken (accessToken ))
63- .isInstanceOf (RuntimeException .class )
64- .hasMessage ("이미 만료된 토큰입니다." );
64+ BusinessException exception = assertThrows (BusinessException .class ,
65+ () -> jwtManager .resolveAccessToken (accessToken ));
66+
67+ assertThat (exception .getErrorCode ()).isEqualTo (BusinessErrorCode .EXPIRED_TOKEN );
6568 }
6669
6770 @ Test
6871 void 유효하지_않은_액세스_토큰을_해석하면_에러가_발생한다 () {
6972 String accessToken = "aaa.bbb.ccc" ;
7073
71- assertThatThrownBy (() -> jwtManager .resolveAccessToken (accessToken ))
72- .isInstanceOf (RuntimeException .class )
73- .hasMessage ("인증되지 않은 회원입니다." );
74+ BusinessException exception = assertThrows (BusinessException .class ,
75+ () -> jwtManager .resolveAccessToken (accessToken ));
76+
77+ assertThat (exception .getErrorCode ()).isEqualTo (BusinessErrorCode .UNAUTHORIZED_MEMBER );
7478 }
7579
7680 @ Test
7781 void 액세스_토큰의_타입이_다르면_에러가_발생한다 () {
7882 long id = 12345L ;
7983 String refreshToken = jwtManager .issueRefreshToken (id );
8084
81- assertThatThrownBy (() -> jwtManager .resolveAccessToken (refreshToken ))
82- .isInstanceOf (RuntimeException .class )
83- .hasMessage ("인증되지 않은 회원입니다." );
85+ BusinessException exception = assertThrows (BusinessException .class ,
86+ () -> jwtManager .resolveAccessToken (refreshToken ));
87+
88+ assertThat (exception .getErrorCode ()).isEqualTo (BusinessErrorCode .UNAUTHORIZED_MEMBER );
8489 }
8590 }
8691
@@ -105,28 +110,31 @@ class ResolveRefreshToken {
105110 long id = 12345L ;
106111 String refreshToken = jwtManager .issueRefreshToken (id );
107112
108- assertThatThrownBy (() -> jwtManager .resolveRefreshToken (refreshToken ))
109- .isInstanceOf (RuntimeException .class )
110- .hasMessage ("이미 만료된 토큰입니다." );
113+ BusinessException exception = assertThrows (BusinessException .class ,
114+ () -> jwtManager .resolveRefreshToken (refreshToken ));
115+
116+ assertThat (exception .getErrorCode ()).isEqualTo (BusinessErrorCode .EXPIRED_TOKEN );
111117 }
112118
113119 @ Test
114120 void 유효하지_않은_리프레시_토큰을_해석하면_에러가_발생한다 () {
115121 String refreshToken = "aaa.bbb.ccc" ;
116122
117- assertThatThrownBy (() -> jwtManager .resolveRefreshToken (refreshToken ))
118- .isInstanceOf (RuntimeException .class )
119- .hasMessage ("인증되지 않은 회원입니다." );
123+ BusinessException exception = assertThrows (BusinessException .class ,
124+ () -> jwtManager .resolveRefreshToken (refreshToken ));
125+
126+ assertThat (exception .getErrorCode ()).isEqualTo (BusinessErrorCode .UNAUTHORIZED_MEMBER );
120127 }
121128
122129 @ Test
123130 void 리프레시_토큰의_타입이_다르면_에러가_발생한다 () {
124131 long id = 12345L ;
125132 String accessToken = jwtManager .issueAccessToken (id );
126133
127- assertThatThrownBy (() -> jwtManager .resolveRefreshToken (accessToken ))
128- .isInstanceOf (RuntimeException .class )
129- .hasMessage ("인증되지 않은 회원입니다." );
134+ BusinessException exception = assertThrows (BusinessException .class ,
135+ () -> jwtManager .resolveRefreshToken (accessToken ));
136+
137+ assertThat (exception .getErrorCode ()).isEqualTo (BusinessErrorCode .UNAUTHORIZED_MEMBER );
130138 }
131139 }
132140}
0 commit comments