### Question:
UserHibernateDao extends GenericDao<PoulpeUser> implements UserDao { @Override public PoulpeUser getByUsername(String username) { Query query = session().getNamedQuery("findUsersByUsername"); query.setString("username", username); return (PoulpeUser) query.uniqueResult(); } 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 testGetByUsername() { PoulpeUser user = TestFixtures.user(); saveAndEvict(user); User actual = dao.getByUsername(user.getUsername()); assertReflectionEquals(actual, user); }
@Test public void testGetByUsernameIsPercent() { PoulpeUser user = TestFixtures.user("%", "testmail@mail.com"); saveAndEvict(user); User actual = dao.getByUsername(user.getUsername()); assertReflectionEquals(actual, user); }
@Test public void getByUsernameShouldEscapeControlSymbols() { PoulpeUser user = TestFixtures.user("abc", "testmail@mail.com"); saveAndEvict(user); User actual = dao.getByUsername("%"); assertNull(actual); }