### Question:
KerberosServiceAuthenticationProvider 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); UserDetails userDetails = this.userDetailsService.loadUserByUsername(username); userDetailsChecker.check(userDetails); additionalAuthenticationChecks(userDetails, auth); return new KerberosServiceRequestToken(userDetails, userDetails.getAuthorities(), token); }  void setUserDetailsService(UserDetailsService userDetailsService); void setTicketValidator(KerberosTicketValidator ticketValidator); @Override Authentication authenticate(Authentication authentication); @Override boolean supports(Class<? extends Object> auth); @Override void afterPropertiesSet();  }### Answer:
@Test(expected=UsernameNotFoundException.class) public void testUsernameNotFound() throws Exception { when(ticketValidator.validateTicket(TEST_TOKEN)).thenReturn(TEST_USER); when(userDetailsService.loadUserByUsername(TEST_USER)).thenThrow(new UsernameNotFoundException("")); provider.authenticate(INPUT_TOKEN); }
@Test(expected=BadCredentialsException.class) public void testTicketValidationWrong() throws Exception { when(ticketValidator.validateTicket(TEST_TOKEN)).thenThrow(new BadCredentialsException("")); provider.authenticate(INPUT_TOKEN); }