AuthenticationServiceImpl implements AuthenticationService { @Override public boolean isLoginAlreadyInUse(String login, String email) throws LoginNameException { if (!this.isLoginNameWellFormed(login)){ throw new LoginNameException(); } if (userDao.getUserByLogin(login).getId() != null){ return true; } else { Map<String, String> loginQueryMap = new HashMap<String, String>(); loginQueryMap.put("login", login); for (UserPending up : userPendingDao.findByMap(loginQueryMap)){ if ( (up.getStatus().equals("WAIT_EMAIL") || up.getStatus().equals("PENDING")) && !up.getEmail().equals(email) ){ return true; } } } return false; }  void setUserDao(UserDao userDao); void setUserPendingDao(UserPendingDao userPendingDao); @Override User getAuthenticatedUser(); @Override boolean isAuthenticated(); @Override boolean isAuthenticatedWaspUser(); @SuppressWarnings("unchecked") @Override String[] getRoles(); @Override boolean isExternallyAuthenticated(); @Override boolean isAuthenticationSetExternal(); @Override boolean isAuthenticatedGuest(); @Override boolean hasRole(String theRole); @Override boolean hasRoleInRoleArray(String[] rolesToCompare, String[] rolesBaseline); @Override Integer getRoleValue(String role); @Override boolean hasRoleInRoleArray(String[] rolesToCompare); @Override boolean isSuperUser(); @Override boolean isFacilityMember(); @Override boolean isOnlyDepartmentAdministrator(); @Override boolean authenticate(String name, String password); @Override boolean authenticates(String name, String password); @Override boolean isLoginNameWellFormed(String login); @Override boolean isLoginAlreadyInUse(String login, String email); @Override String encodePassword(String s); @Override boolean validatePassword(String s); @Override boolean matchPassword(String s1, String s2); @Override String getRandomPassword(int length); @Override Set<Integer> idsOfDepartmentsManagedByCurrentUser(); @Override Set<Integer> idsOfLabsManagedByCurrentUser(); @Override boolean isThisExistingUserPIPending();  }
@Test public void isLoginAlreadyInUse2() { User user = new User(); user.setUserId(1); Map loginQueryMap = new HashMap(); loginQueryMap.put("login", "jgreally"); expect(mockUserDao.getUserByLogin("jgreally")).andReturn(user); replay(mockUserDao); try { Assert.assertTrue(authServiceImpl.isLoginAlreadyInUse("jgreally", "jgreally@einstein.yu.edu")); } catch (LoginNameException e) { e.printStackTrace(); } verify(mockUserDao); }