@Test
    void verifyOperationWithSurrogate() throws Throwable {
        val registeredService = CoreAuthenticationTestUtils.getRegisteredService();
        when(registeredService.getAttributeReleasePolicy()).thenReturn(new DenyAllAttributeReleasePolicy());

        val surrogate = new BasicIdentifiableCredential();
        surrogate.getCredentialMetadata()
            .addTrait(new SurrogateCredentialTrait("surrogate"));
        val principal = surrogatePrincipalBuilder.buildSurrogatePrincipal(surrogate,
            CoreAuthenticationTestUtils.getPrincipal("unknown"), registeredService);

        val resultBuilder = new DefaultAuthenticationResultBuilder(principalElectionStrategy);
        resultBuilder.collect(CoreAuthenticationTestUtils.getAuthentication(principal));

        val credential = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
        assertThrows(SurrogateAuthenticationException.class,
            () -> surrogatePrincipalBuilder.buildSurrogateAuthenticationResult(resultBuilder, credential, registeredService));

        credential.getCredentialMetadata().addTrait(new SurrogateCredentialTrait(UUID.randomUUID().toString()));
        assertThrows(SurrogateAuthenticationException.class,
            () -> surrogatePrincipalBuilder.buildSurrogateAuthenticationResult(resultBuilder, credential, registeredService));
    }
This is {@link DefaultSurrogateAuthenticationPrincipalBuilderTests}.

@author Misagh Moayyed
@since 6.2.0
support/cas-server-support-surrogate-authentication/src/test/java/org/apereo/cas/authentication/DefaultSurrogateAuthenticationPrincipalBuilderTests.java