### Question:
AdministratorLoginManager implements AuthenticationProvider { public Authentication authenticate(final Authentication authentication) { final AdministratorLoginResult result = findUserAndGetResult(authentication); final AdministratorLoginStatus status = result.getStatus(); if (validCredential(status)) { final Administrator administrator = result.getAdministrator(); final String username = administrator.getUsername(); LOGGER.info("{} has been authenticated for admin panel", username); return createToken(result); } else if (userNotFound(status)) { LOGGER.error("\"{}\" username has not found", authentication.getPrincipal()); throw new UsernameNotFoundException("User not found: " + authentication.getPrincipal()); } else { LOGGER.error( "\"{}\" has failed to login because of bad credentials", authentication.getPrincipal()); throw new BadCredentialsException("Invalid password"); } }  void setLoginDao(final AdministratorLoginDao loginDao); Authentication authenticate(final Authentication authentication); boolean supports(final Class<?> aClass);  }### Answer:
@Test(expected = UsernameNotFoundException.class) public void loginInvalidUsername() throws Exception { final AdministratorLoginResult daoResult = createDaoResult(AdministratorLoginStatus.INVALID_USERNAME); setMockReturn(daoResult); mockAuthentication(); manager.authenticate(authentication); verify(); }
@Test(expected = BadCredentialsException.class) public void loginInvalidPassword() throws Exception { final AdministratorLoginResult daoResult = createDaoResult(AdministratorLoginStatus.INVALID_PASSWORD); setMockReturn(daoResult); mockAuthentication(); manager.authenticate(authentication); verify(); }
@Test public void loginSuccessfull() throws Exception { final AdministratorLoginResult daoResult = createDaoResult(AdministratorLoginStatus.SUCCESS); final Administrator admin = createAdministrator(); daoResult.setAdministrator(admin); setMockReturn(daoResult); mockAuthentication(); final Authentication result = manager.authenticate(authentication); final GrantedAuthority authority = result.getAuthorities().iterator() .next(); assertTrue(authority.getAuthority().equals(Role.ROLE_ADMIN)); }