From 26fa5d768d9b1813be7ae813cf656ca72eb172c4 Mon Sep 17 00:00:00 2001 From: baymax55 <35788491+baymax55@users.noreply.github.com> Date: Thu, 24 Nov 2022 09:26:37 +0800 Subject: [PATCH] AddTestCaseForJwtTokenUtil (#1009) * AddTestCaseForJwtTokenUtil * add public prefix for UT --- .../auth/toolkit/JwtTokenUtilTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/hippo4j-server/hippo4j-auth/src/test/java/cn/hippo4j/auth/toolkit/JwtTokenUtilTest.java b/hippo4j-server/hippo4j-auth/src/test/java/cn/hippo4j/auth/toolkit/JwtTokenUtilTest.java index 28c8b227..46a94110 100644 --- a/hippo4j-server/hippo4j-auth/src/test/java/cn/hippo4j/auth/toolkit/JwtTokenUtilTest.java +++ b/hippo4j-server/hippo4j-auth/src/test/java/cn/hippo4j/auth/toolkit/JwtTokenUtilTest.java @@ -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); + } }