FileDaoImpl extends AbstractEntityDao<File> implements FileDao { @Override public File findByName(Integer projectId, String name) { Validate.notNull(projectId, "Project identifier can't be null"); Validate.notNull(name, "Name can't be null"); String query = "select f from File as f where f.project.id = ?1 and f.name = ?2 order by f.id"; return findUniqueResult(query, projectId, name); } FileDaoImpl(); @Override void delete(File entity); @Override File findByName(Integer projectId, String name);  }
@Test public void saveExistingProject() { Project newProject = new Project(USER_ID, NAME_2); projectDAO.persist(newProject); File newFile = new File(file.getName(), file.getType(), file.getData()); newProject.addFile(newFile); dao.persist(newFile); assertEquals("files not same.", newFile, dao.load(newFile.getId())); assertEquals("files not same.", newFile, dao.findByName(newProject .getId(), newFile.getName())); Project loadedProject = projectDAO.load(newProject.getId()); assertTrue("collection isn't updated.", loadedProject.getFiles() .contains(newFile)); }
@Test(expected = IllegalArgumentException.class) public void findByNameNullProjectId() { dao.findByName(null, NAME); }
@Test(expected = IllegalArgumentException.class) public void findByNameNullName() { dao.findByName(file.getProject().getId(), null); }
@Test public void findByNameNonExistingProjectId() { assertNull("file already exists.", dao.findByName(Integer.MAX_VALUE, NAME)); }
@Test public void findByNameNonExistingName() { assertNull("file already exists.", dao.findByName(file.getProject() .getId(), NAME_2)); }
@Test public void findByName() { dao.persist(file); assertEquals("files are not same.", file, dao.findByName(project .getId(), file.getName())); assertEquals("file name is not case insensitive.", file, dao .findByName(project.getId(), NAME_OPPOSITE_CASE)); }