Skip to content

Commit be48c1a

Browse files
committed
feat: add and impl JwtUtilsTest
1 parent 2660ef8 commit be48c1a

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package kattsyn.dev.rentplace.utils;
2+
3+
import io.jsonwebtoken.Claims;
4+
import kattsyn.dev.rentplace.auth.JwtAuthentication;
5+
import kattsyn.dev.rentplace.enums.Role;
6+
import org.junit.jupiter.api.Test;
7+
import static org.junit.jupiter.api.Assertions.*;
8+
import static org.mockito.Mockito.mock;
9+
import static org.mockito.Mockito.when;
10+
11+
class JwtUtilsTest {
12+
13+
@Test
14+
void generate_JwtAuthenticationWithCorrectFields() {
15+
Claims claims = mock(Claims.class);
16+
when(claims.getSubject()).thenReturn("user@test.com");
17+
when(claims.get("name", String.class)).thenReturn("Test User");
18+
when(claims.get("role", String.class)).thenReturn("ROLE_USER");
19+
20+
JwtAuthentication auth = JwtUtils.generate(claims);
21+
22+
assertEquals("user@test.com", auth.getEmail());
23+
assertEquals(Role.ROLE_USER, auth.getRole());
24+
}
25+
}

0 commit comments

Comments
 (0)