JwtTokenUtil { public String generateRefreshToken(String subject) { final Instant createdDate = Instant.now(); final Instant expirationDate = createdDate.plus(jwtConfig.getRefreshExpiration()); log.info("generateRefreshToken()"); return Jwts.builder() .setSubject(subject) .setIssuedAt(Date.from(createdDate)) .setExpiration(Date.from(expirationDate)) .signWith(Keys.hmacShaKeyFor(Decoders.BASE64.decode(jwtConfig.getSecret())), SignatureAlgorithm.HS512) .compact(); }  String getUsernameFromToken(String token); Instant getIssuedAtDateFromToken(String token); Instant getExpirationDateFromToken(String token); T getClaimFromToken(String token, Function<Claims, T> claimsResolver); String generateToken(UserDetails userDetails); Boolean canTokenBeRefreshed(String token, Instant lastPasswordReset); String generateRefreshToken(String subject); Boolean validateToken(String token, UserDetails userDetails); Collection<? extends GrantedAuthority> getGrantedAuthoritiesFromToken(String authToken);  }
@Test public void testGenerateRefreshToken() throws Exception { Instant start = Instant.now().minusSeconds(1); Duration expiration = Duration.ofDays(90); String token = jwtTokenUtil.generateRefreshToken("username"); assertThat(jwtTokenUtil.getUsernameFromToken(token)).isEqualTo("username"); assertThat(jwtTokenUtil.getIssuedAtDateFromToken(token)).isBetween(start, Instant.now()); assertThat(jwtTokenUtil.getExpirationDateFromToken(token)).isBetween(start.plus(expiration), Instant.now().plus(expiration)); }