### Question:
UserHibernateDao extends GenericDao<PoulpeUser> implements UserDao { @Override public List<PoulpeUser> findUsersByUsernameAndPasswordHash(String username, String passwordHash) { Query query = session().getNamedQuery("findUsersByUsernameAndPasswordHash"); query.setString("username", username); query.setString("password", passwordHash); return query.list(); } UserHibernateDao(SessionFactory sessionFactory); @Override List<PoulpeUser> findPoulpeUsersPaginated(String searchString, Pagination paginate); @Override List<PoulpeUser> findPoulpeUsersBySearchRequest(UserSearchRequest searchRequest); @Override int countUsernameMatches(String searchString); @Override PoulpeUser getByUsername(String username); @Override PoulpeUser getByEmail(String email); @Override PoulpeUser getByUUID(String uuid); @Override List<PoulpeUser> getUsersInGroups(List<Group> groups); @Override List<PoulpeUser> findUsersByUsernameAndPasswordHash(String username, String passwordHash); @Override List<PoulpeUser> findUsersNotInGroups(String availableFilterText,
                                                 List<Group> groups, Pagination paginate); @Override List<PoulpeUser> findUsersNotInList(String availableFilterText,
                                               List<PoulpeUser> listUsers, Pagination paginate); @Override void save(User user);  }### Answer:
@Test public void returnsSingleUserForUniqueUsername() throws Exception { String username = alphanumeric(USERNAME_MAX_LENGTH); String password = alphanumeric(PASSWORD_MAX_LENGTH); PoulpeUser expected = saveAndEvictUser(username, password); saveAndEvictUser(alphanumeric(USERNAME_MAX_LENGTH), password); List<PoulpeUser> actualUserList = dao.findUsersByUsernameAndPasswordHash(username, password); assertEquals(actualUserList.size(), 1); assertEquals(actualUserList.get(0), expected); }
@Test public void returnsUsersFoundUsingCaseInsensitiveSearch() throws Exception { String username = english(USERNAME_MAX_LENGTH); String password = alphanumeric(PASSWORD_MAX_LENGTH); List<PoulpeUser> expectedUserList = Arrays.asList( saveAndEvictUser(username, password), saveAndEvictUser(username.toLowerCase(), password), saveAndEvictUser(StringUtils.capitalize(username.toLowerCase()), password), saveAndEvictUser(username.toUpperCase(), password)); List<PoulpeUser> poulpeUsers = dao.findUsersByUsernameAndPasswordHash(username, password); assertEquals(poulpeUsers.size(), expectedUserList.size()); assertTrue(poulpeUsers.containsAll(expectedUserList)); }
@Test public void returnsEmptyListIfUsernameOrPasswordIsEmpty() throws Exception { String username = alphanumeric(USERNAME_MAX_LENGTH); String password = alphanumeric(PASSWORD_MAX_LENGTH); saveAndEvictUser(username, password); List<PoulpeUser> poulpeUsers = dao.findUsersByUsernameAndPasswordHash(nullOrBlank(), password); assertEquals(poulpeUsers.size(), 0); poulpeUsers = dao.findUsersByUsernameAndPasswordHash(username, nullOrBlank()); assertEquals(poulpeUsers.size(), 0); }
@Test public void returnsEmptyListIfUserNotFound() throws Exception { String username = alphanumeric(USERNAME_MAX_LENGTH); String password = alphanumeric(PASSWORD_MAX_LENGTH); saveAndEvictUser(username, password); List<PoulpeUser> poulpeUsers = dao.findUsersByUsernameAndPasswordHash(alphanumeric(USERNAME_MAX_LENGTH), alphanumeric(PASSWORD_MAX_LENGTH)); assertEquals(poulpeUsers.size(), 0); }