private static AuthenticationHandler newMockHandler(final String name, final boolean success, final boolean error) throws Throwable {
        val mock = mock(AuthenticationHandler.class);
        when(mock.getName()).thenReturn(name);
        when(mock.supports(any(Credential.class))).thenReturn(true);
        when(mock.getState()).thenCallRealMethod();
        if (success) {
            val principal = PrincipalFactoryUtils.newPrincipalFactory().createPrincipal("nobody");
            val metadata = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword("nobody");
            val result = new DefaultAuthenticationHandlerExecutionResult(mock, metadata, principal);
            when(mock.authenticate(any(Credential.class), any(Service.class))).thenReturn(result);
        } else if (!error) {
            when(mock.authenticate(any(Credential.class), any(Service.class))).thenThrow(new FailedLoginException());
        } else {
            when(mock.authenticate(any(Credential.class), any(Service.class))).thenThrow(new PreventedException("failure"));
        }
        return mock;
    }
Unit test for {@link DefaultAuthenticationManager}.

@author Marvin S. Addison
@since 4.0.0
core/cas-server-core-authentication/src/test/java/org/apereo/cas/authentication/DefaultAuthenticationManagerTests.java