### Question:
JwtTokenValidatorFactory { public static JwtTokenValidator tokenValidator( IssuerProperties issuerProperties, AuthorizationServerMetadata metadata, ResourceRetriever resourceRetriever ) { RemoteJWKSet<SecurityContext> remoteJWKSet = remoteJwkSet( issuerProperties, getJWKsUrl(metadata), resourceRetriever ); return tokenValidator(issuerProperties, metadata, remoteJWKSet); }  static JwtTokenValidator tokenValidator(
        IssuerProperties issuerProperties,
        AuthorizationServerMetadata metadata,
        ResourceRetriever resourceRetriever
    ); static JwtTokenValidator tokenValidator(
        IssuerProperties issuerProperties,
        AuthorizationServerMetadata metadata,
        RemoteJWKSet<SecurityContext> remoteJWKSet
    );  }### Answer:
@Test void testCreateDefaultJwtTokenValidator() { assertThat(tokenValidator(issuerProperties, metadata, resourceRetriever)) .isInstanceOf(DefaultJwtTokenValidator.class); }
@Test void testCreateConfigurableJwtTokenValidator() { issuerProperties.setValidation(new IssuerProperties.Validation(List.of("optionalclaim"))); JwtTokenValidator validatorWithDefaultCache = tokenValidator(issuerProperties, metadata, resourceRetriever); assertThat(validatorWithDefaultCache).isInstanceOf(ConfigurableJwtTokenValidator.class); }
@Test void testCreateJwtTokenValidatorWithDefaultCacheValues() { JwtTokenValidator validatorWithDefaultCache = tokenValidator(issuerProperties, metadata, resourceRetriever); assertThat(validatorWithDefaultCache).isInstanceOf(DefaultJwtTokenValidator.class); JWKSetCache cache = getCache(validatorWithDefaultCache); assertThat(cache).isInstanceOf(DefaultJWKSetCache.class); assertThat(((DefaultJWKSetCache) cache).getLifespan(TimeUnit.MINUTES)) .isEqualTo(DefaultJWKSetCache.DEFAULT_LIFESPAN_MINUTES); assertThat(((DefaultJWKSetCache) cache).getRefreshTime(TimeUnit.MINUTES)) .isEqualTo(DefaultJWKSetCache.DEFAULT_REFRESH_TIME_MINUTES); }
@Test void testCreateJwtTokenValidatorWithCustomCacheValues() { issuerProperties.setJwksCache(new IssuerProperties.JwksCache(1L, 2L)); JwtTokenValidator validatorWithCustomCache = tokenValidator(issuerProperties, metadata, resourceRetriever); assertThat(validatorWithCustomCache).isInstanceOf(DefaultJwtTokenValidator.class); JWKSetCache cache = getCache(validatorWithCustomCache); assertThat(cache).isInstanceOf(DefaultJWKSetCache.class); assertThat(((DefaultJWKSetCache) cache).getLifespan(TimeUnit.MINUTES)) .isEqualTo(1L); assertThat(((DefaultJWKSetCache) cache).getRefreshTime(TimeUnit.MINUTES)) .isEqualTo(2L); }
@Test void testCreateValidatorWithProvidedRemoteJWKSet() { JwtTokenValidator jwtTokenValidator = tokenValidator(issuerProperties, metadata, remoteJWKSet); JWKSetCache cache = new DefaultJWKSetCache(1L, 2L, TimeUnit.MINUTES); when(remoteJWKSet.getJWKSetCache()).thenReturn(cache); assertThat(getCache(jwtTokenValidator)).isEqualTo(cache); }