@Test
public void testAuthenticateUser() throws UnknownHostException {

    Pair<Boolean, UserAuthenticator.ActionOnFailedAuthentication> successAuthenticationPair = new Pair<>(true, null);
    Pair<Boolean, UserAuthenticator.ActionOnFailedAuthentication> failureAuthenticationPair = new Pair<>(false,
                                                                                                         UserAuthenticator.ActionOnFailedAuthentication.INCREMENT_INCORRECT_LOGIN_ATTEMPT_COUNT);
    UserAccountVO userAccountVO = new UserAccountVO();
    userAccountVO.setSource(User.Source.UNKNOWN);
    userAccountVO.setState(Account.State.disabled.toString());
    Mockito.when(_userAccountDao.getUserAccount("test", 1L)).thenReturn(userAccountVO);
    Mockito.when(userAuthenticator.authenticate("test", "fail", 1L, null)).thenReturn(failureAuthenticationPair);
    Mockito.when(userAuthenticator.authenticate("test", null, 1L, null)).thenReturn(successAuthenticationPair);
    Mockito.when(userAuthenticator.authenticate("test", "", 1L, null)).thenReturn(successAuthenticationPair);
    //Test for incorrect password. authentication should fail
    UserAccount userAccount = accountManager.authenticateUser("test", "fail", 1L, InetAddress.getByName("127.0.0.1"), null);
    Assert.assertNull(userAccount);
    //Test for null password. authentication should fail
    userAccount = accountManager.authenticateUser("test", null, 1L, InetAddress.getByName("127.0.0.1"), null);
    Assert.assertNull(userAccount);
    //Test for empty password. authentication should fail
    userAccount = accountManager.authenticateUser("test", "", 1L, InetAddress.getByName("127.0.0.1"), null);
    Assert.assertNull(userAccount);
    //Verifying that the authentication method is only called when password is specified
    Mockito.verify(userAuthenticator, Mockito.times(1)).authenticate("test", "fail", 1L, null);
    Mockito.verify(userAuthenticator, Mockito.never()).authenticate("test", null, 1L, null);
    Mockito.verify(userAuthenticator, Mockito.never()).authenticate("test", "", 1L, null);
}