Skip to content

Commit

Permalink
AddTestCaseForJwtTokenUtil (opengoofy#1009)
Browse files Browse the repository at this point in the history
* AddTestCaseForJwtTokenUtil

* add public prefix for UT
  • Loading branch information
baymax55 authored Nov 24, 2022
1 parent 649c84f commit 26fa5d7
Showing 1 changed file with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,55 @@

package cn.hippo4j.auth.toolkit;

import cn.hippo4j.common.toolkit.Assert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public final class JwtTokenUtilTest {
Long userId = 1L;
String username = "baymax";
String role = "";
boolean isRememberMe = true;

String token;

@BeforeEach
public void setUp() {
token = JwtTokenUtil.createToken(userId, username, role, isRememberMe);
}

@Test
public void createToken() {
String name = JwtTokenUtil.getUsername(token);
Assert.isTrue(username.equals(name));
Integer userId = JwtTokenUtil.getUserId(token);
String userRole = JwtTokenUtil.getUserRole(token);
Assert.isTrue(username.equals(name));
Assert.isTrue(this.userId.intValue() == userId);
Assert.isTrue(role.equals(userRole));
}

@Test
public void getUsername() {
String name = JwtTokenUtil.getUsername(token);
Assert.isTrue(username.equals(name));
}

@Test
public void getUserId() {
Integer id = JwtTokenUtil.getUserId(token);
Assert.isTrue(userId.intValue() == id);
}

@Test
public void getUserRole() {
String userRole = JwtTokenUtil.getUserRole(token);
Assert.isTrue(role.equals(userRole));
}

@Test
public void isExpiration() {
boolean isExpiration = JwtTokenUtil.isExpiration(token);
Assert.isTrue(!isExpiration);
}
}

0 comments on commit 26fa5d7

Please sign in to comment.