### Question:
ActiveDirectoryAuthenticationProvider implements AuthenticationProvider, InitializingBean { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { KerberosServiceRequestToken auth = (KerberosServiceRequestToken) authentication; byte[] token = auth.getToken(); LOG.debug("Try to validate Kerberos Token"); String username = this.ticketValidator.validateTicket(token); LOG.debug("Succesfully validated " + username); userDetailsService.setToken(token); UserDetails userDetails = this.userDetailsService.loadUserByUsername(username); userDetailsChecker.check(userDetails); Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); authorities.addAll(userDetails.getAuthorities()); return new KerberosServiceRequestToken(userDetails, authorities, token); }  void setUserDetailsService(ActiveDirectoryUserDetailsService userDetailsService); void setTicketValidator(KerberosTicketValidator ticketValidator); @Override Authentication authenticate(Authentication authentication); @Override boolean supports(Class<? extends Object> auth); @Override void afterPropertiesSet();  }### Answer:
@Test public void testLoginOk() throws Exception { when(userDetailsService.loadUserByUsername(TEST_USER)).thenReturn(USER_DETAILS); when(ticketValidator.validateTicket(TOKEN)).thenReturn(TEST_USER); when(securityIntegration.getUserGroupSids(TOKEN)).thenReturn(GROUP_SIDS); when(authoritiesPopulator.getGrantedAuthorities(GROUP_SIDS)).thenReturn(AUTHORITY_LIST); Authentication authenticate = provider.authenticate(INPUT_TOKEN); assertNotNull(authenticate); assertEquals(TEST_USER, authenticate.getName()); assertEquals(USER_DETAILS, authenticate.getPrincipal()); assertEquals(AUTHORITY_LIST, authenticate.getAuthorities()); }