UserDAO extends AbstractJPADAO<User, Long> { public User findUserFromName(String name) { Query query = entityManager.createQuery("SELECT u FROM " + getEntityClass().getName() + " u" + " left join fetch u.contractSet c" + " WHERE u.name = :name"); query.setParameter("name", name); try { return (User)query.getSingleResult(); } catch (NoResultException e) { return null; } } UserDAO(); User read(Long key); User findUserFromEmail(String email); User findUserFromName(String name); boolean isAccountActivated(String email);  }
@Test public void testFindUserFromName(){ User user = userDAO.findUserFromName("Test1"); assertEquals(Long.valueOf(1), user.getId()); user = userDAO.findUserFromName("test"); assertNull(user); }