Project extends OwnedEntity { public void addFile(File file) { Validate.notNull(file, "File can't be null"); if (file.getProject() != null) { if (file.getProject() == this) { return; } throw new IllegalArgumentException(file.toString() + " already belongs to some project; this project is " + this.toString()); } file.setProject(this); getFiles().add(file); } 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(expected = IllegalArgumentException.class) public void addFileNullArgument() { entity.addFile(null); }
@Test public void addFile() throws Exception { Set<File> files = new HashSet<File>(entity.getFiles()); File anotherFile = new FileStub2(); entity.addFile(anotherFile); files.add(anotherFile); assertTrue("file not added.", entity.getFiles().contains(anotherFile)); assertEquals("file size not same.", files.size(), entity.getFiles() .size()); assertEquals("files not same.", files, entity.getFiles()); }
@Test(expected = IllegalArgumentException.class) public void removeFileNullArgument() { entity.addFile(null); }