@Test
    void verifyOperationWithSurrogateSuccess() 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("test"), 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("surrogate"));
        val builder = surrogatePrincipalBuilder.buildSurrogateAuthenticationResult(
            resultBuilder, credential, registeredService).orElseThrow();
        val authentication = builder.build().getAuthentication();
        assertTrue(authentication.getSingleValuedAttribute(SurrogateAuthenticationService.AUTHENTICATION_ATTR_SURROGATE_ENABLED, Boolean.class));
        assertEquals("test", authentication.getSingleValuedAttribute(SurrogateAuthenticationService.AUTHENTICATION_ATTR_SURROGATE_PRINCIPAL, String.class));
        assertEquals("surrogate", authentication.getSingleValuedAttribute(SurrogateAuthenticationService.AUTHENTICATION_ATTR_SURROGATE_USER, String.class));
    }
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