AttachmentValue { public String relativeUri(ProjectEntity parentProject){ Assert.notNull(parentProject); if(this.fileReference == null){ throw new IllegalStateException("AttachmentValue has not yet an assigned 'fileReference' id and thus cannot serve its relative uri"); } return "/projects/" + parentProject.getId() + "/attachments/" + fileReference; } AttachmentValue(String fileReference, String contentType, String filename, long size, DateTime created);  AttachmentValue(String filename, String contentType); private  AttachmentValue(); String relativeUri(ProjectEntity parentProject); String getContentType(); DateTime getCreated(); String getFilename(); String getFileReference(); long getSize(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test public void relativeUri() throws Exception { final AttachmentValue attachmentValue = givenAttachmentValue("expFileRef"); final ProjectEntity givenProject = givenProjectEntity("aProjectId"); final String res = attachmentValue.relativeUri(givenProject); assertThat(res, is("/projects/" + givenProject.getId() + "/attachments/" + attachmentValue.getFileReference())); }
@Test(expected = IllegalStateException.class) public void relativeUri_ShouldThrowIllegalStateExceptionOnIncompleteAttachment() throws Exception { final AttachmentValue attachmentValue = givenAttachmentValue(null); final ProjectEntity givenProject = givenProjectEntity("aProjectId"); attachmentValue.relativeUri(givenProject); }