@Test
    void verifyPolicyByEntityCache() throws Throwable {
        val policy = new SamlRegisteredServiceMetadataExpirationPolicy(Beans.newDuration("PT5M"));

        val props = new SamlIdPProperties();
        props.getMetadata().getFileSystem().setLocation(new FileSystemResource(FileUtils.getTempDirectory()).getFile().getCanonicalPath());

        val service = new SamlRegisteredService();
        service.setMetadataExpirationDuration(StringUtils.EMPTY);
        service.setServiceId("https://carmenwiki.osu.edu/shibboleth");
        service.setMetadataLocation("classpath:GroovyMetadataResolver.groovy");
        val cacheKey = new SamlRegisteredServiceCacheKey(service, new CriteriaSet());

        val resolver = mock(MetadataResolver.class);
        val entity = mock(EntityDescriptor.class);
        val entityCacheDuration = Duration.ofSeconds(10);
        when(entity.getCacheDuration()).thenReturn(entityCacheDuration);
        when(resolver.resolveSingle(any())).thenReturn(entity);

        val result = CachedMetadataResolverResult.builder().metadataResolver(resolver).build();
        assertEquals(entityCacheDuration.toNanos(), policy.expireAfterCreate(cacheKey, result, System.currentTimeMillis()));

        when(resolver.resolveSingle(any())).thenThrow(new IllegalArgumentException());
        assertEquals(policy.defaultExpiration().toNanos(), policy.expireAfterCreate(cacheKey, result, System.currentTimeMillis()));
        assertEquals(policy.defaultExpiration().toNanos(),
            policy.expireAfterUpdate(cacheKey, result, 1000, policy.defaultExpiration().toNanos()));
    }
This is {@link SamlRegisteredServiceMetadataExpirationPolicyTests}.

@author Misagh Moayyed
@since 6.3.0
support/cas-server-support-saml-idp-metadata/src/test/java/org/apereo/cas/support/saml/services/idp/metadata/cache/resolver/SamlRegisteredServiceMetadataExpirationPolicyTests.java