ProjectDaoImpl extends AbstractOwnedEntityDao<Project> implements
        ProjectDao { @Override public Project findByName(String userId, String name) { Validate.notNull(userId, "User identifier can't be null"); Validate.notNull(name, "Name can't be null"); String query = "select p from Project as p where p.userId = ?1 and p.name = ?2 order by p.id"; return findUniqueResult(query, userId, name); } ProjectDaoImpl(); @Override Project findByName(String userId, String name);  }
@Test public void saveAddFile() { dao.persist(project); File newFile = new File(NAME_2, FileType.AUTOMATON, "another file data"); project.addFile(newFile); dao.persist(project); Project loadedProject = dao.load(project.getId()); assertNotNull("file not saved.", fileDAO.load(newFile.getId())); assertNotNull("file not saved.", fileDAO.findByName(loadedProject .getId(), newFile.getName())); assertEquals("projects not equal.", project, loadedProject); assertTrue("project doesn't contain a new file.", loadedProject .getFiles().contains(newFile)); }
@Test(expected = IllegalArgumentException.class) public void findByNameNullUserId() { dao.findByName(null, NAME); }
@Test(expected = IllegalArgumentException.class) public void findByNameNullName() { dao.findByName(USER_ID, null); }
@Test public void findByNameNonExistingUserId() { Project newProject = dao.findByName(USER_ID_2, NAME); assertNull("project already exists.", newProject); }
@Test public void findByNameNonExistingName() { Project newProject = dao.findByName(USER_ID, NAME_2); assertNull("project already exists.", newProject); }
@Test public void findByName() { setupProject(project); assertEquals("project not found.", project, dao.findByName(project .getUserId(), project.getName())); assertEquals("project name and user id are not case insensitive.", project, dao.findByName(USER_ID_OPPOSITE_CASE, NAME_OPPOSITE_CASE)); }