//测试情况7,测试存在合法的认证处理器的情况,但是凭据转换器列表不为空,但是集合中的元素不为空,认证后处理器对象是空。
handler = Mockito.mock(AuthenticationHandler.class);
Mockito.when(handler.supports(credential)).thenReturn(true);
Mockito.when(handler.authenticate(credential)).thenReturn(true);
CredentialToPrincipalResolver resolver = Mockito.mock(CredentialToPrincipalResolver.class);
Principal principal = Mockito.mock(Principal.class);
Mockito.when(resolver.supports(credential)).thenReturn(true);
Mockito.when(resolver.resolvePrincipal(credential)).thenReturn(principal);
try{
authenticationHandlers = new ArrayList<AuthenticationHandler>();
authenticationHandlers.add(handler);
authenticationManager.setAuthenticationHandlers(authenticationHandlers);
resolvers = new ArrayList<CredentialToPrincipalResolver>();
resolvers.add(resolver);
authenticationManager.setCredentialToPrincipalResolvers(resolvers);
authenticationManager.authenticate(credential);
fail("当没有认证后处理器应该抛出异常信息");
}catch (NoAuthenticationPostHandlerException e) {
}
//测试情况8,测试存在合法的认证处理器的情况,但是凭据转换器列表不为空,但是集合中的元素不为空,认证后处理器对象不是空。
handler = Mockito.mock(AuthenticationHandler.class);
Mockito.when(handler.supports(credential)).thenReturn(true);
Mockito.when(handler.authenticate(credential)).thenReturn(true);
resolver = Mockito.mock(CredentialToPrincipalResolver.class);
principal = Mockito.mock(Principal.class);
Mockito.when(resolver.supports(credential)).thenReturn(true);
Mockito.when(resolver.resolvePrincipal(credential)).thenReturn(principal);
AuthenticationPostHandler authenticationPostHandler = Mockito.mock(AuthenticationPostHandler.class);
Authentication authentication = Mockito.mock(Authentication.class);
Mockito.when(authenticationPostHandler.postAuthentication(credential, principal)).thenReturn(authentication);
authenticationHandlers = new ArrayList<AuthenticationHandler>();
authenticationHandlers.add(handler);