### Question:
AuthenticationProviderManager extends AbstractService implements IAuthenticationProviderManager { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { try { if (null == authentication || null == authentication.getPrincipal() || null == authentication.getCredentials()) { throw new UsernameNotFoundException("Invalid principal and/or credentials"); } UserDetails user = this.extractUser(authentication.getPrincipal().toString(), authentication.getCredentials().toString(), false); if (null != user) { Authentication newAuth = new UsernamePasswordAuthenticationToken(authentication.getPrincipal(), authentication.getCredentials(), user.getAuthorizations()); return newAuth; } else { throw new UsernameNotFoundException("Invalid username/password"); } } catch (AuthenticationException e) { throw e; } catch (Exception e) { logger.error("Error detected during user authentication", e); throw new AuthenticationServiceException("Error detected during user authentication", e); } }  @Override void init(); @Override UserDetails getUser(String username); @Override UserDetails getUser(String username, String password); @Override Authentication authenticate(Authentication authentication); @Override org.springframework.security.core.userdetails.UserDetails loadUserByUsername(String username); void setUserManager(IUserManager userManager); void setAuthorizationManager(IAuthorizationManager authorizationManager); void setTokenManager(IApiOAuth2TokenManager tokenManager);  }### Answer:
@Test public void authenticate() throws Exception { UserDetails activeUser = this.createMockUser("admin", true, false, false); when(this.userManager.getUser(Mockito.anyString(), Mockito.anyString())).thenReturn(activeUser); when(this.authorizationManager.getUserAuthorizations("admin")).thenReturn(this.createMockAuthorization()); when(this.tokenManager.createAccessTokenForLocalUser("admin")).thenReturn(this.createMockToken()); TestingAuthenticationToken authTest = new TestingAuthenticationToken("admin", "password"); Authentication auth = this.authenticationProviderManager.authenticate(authTest); Assert.assertNotNull(auth); Assert.assertTrue(auth instanceof UsernamePasswordAuthenticationToken); Assert.assertEquals("admin", auth.getPrincipal()); Assert.assertEquals(2, auth.getAuthorities().size()); Mockito.verify(userManager, Mockito.times(1)).updateLastAccess(Mockito.any(UserDetails.class)); Mockito.verify(authorizationManager, Mockito.times(1)).getUserAuthorizations(Mockito.anyString()); Mockito.verify(tokenManager, Mockito.times(0)).createAccessTokenForLocalUser(Mockito.anyString()); }