@Test
    void verifyPolicyBySpEntityCache() 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 spCacheDuration = Duration.ofSeconds(30);
        when(entity.getCacheDuration()).thenReturn(spCacheDuration);
        when(resolver.resolveSingle(argThat(argument -> argument != null && argument.size() == 1))).thenReturn(entity);
        when(resolver.resolveSingle(argThat(argument -> argument != null && argument.size() > 1))).thenReturn(null);

        val result = CachedMetadataResolverResult.builder().metadataResolver(resolver).build();
        assertEquals(spCacheDuration.toNanos(), policy.expireAfterCreate(cacheKey, result, System.currentTimeMillis()));
    }
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