Project extends OwnedEntity { public void removeFile(File file) { Validate.notNull(file, "File can't be null"); if (file.getProject() != this) { throw new IllegalArgumentException(file.toString() + " doesn't belong to this " + this.toString()); } if (getFiles().remove(file)) { file.setProject(null); } } Project();  Project(String name);  Project(String userId, String name);  Project(Project clone); @NameFormatConstraint @Override String getName(); Set<File> getFiles(); void setFiles(Set<File> files); void addFile(File file); void removeFile(File file); @Override String toString();  }
@Test public void removeFile() throws Exception { File file = (File) CollectionUtils.get(entity.getFiles(), 0); entity.removeFile(file); assertTrue("files not empty.", entity.getFiles().isEmpty()); assertNull("project isn't set to null.", file.getProject()); }
@Test(expected = IllegalArgumentException.class) public void removeFile2() throws Exception { File anotherFile = new FileStub2(); entity.removeFile(anotherFile); }