@Test
public void validate_expired_shouldThrow() throws Exception {

  String algo = "HS256";
  Clock clock1 = Clock.systemUTC();
  // This token expires in 1 minute in the future.
  ToBeSignedJwt token =
      new ToBeSignedJwt.Builder()
          .setAlgorithm(algo)
          .setExpiration(clock1.instant().plus(Duration.ofMinutes(1)))
          .build();
  // Move the clock to 2 minutes in the future.
  Clock clock2 = Clock.offset(clock1, Duration.ofMinutes(2));
  JwtValidator validator = new JwtValidator.Builder().setClock(clock2).build();
  assertThrows(JwtExpiredException.class, () -> validator.validate(algo, token));
}