### Question:
DatastreamUtil { public static String getThumbnailUrl(BriefObjectMetadata metadata, String size) { String selectedSize = size == null ? "large" : size; selectedSize = selectedSize.toLowerCase().trim(); String derivativeName = "thumbnail_" + selectedSize; Datastream preferredDS = getPreferredDatastream(metadata, derivativeName); if (preferredDS == null) { return ""; } StringBuilder url = new StringBuilder(datastreamEndpoint); url.append("thumb/"); if (isBlank(preferredDS.getOwner())) { url.append(metadata.getId()); } else { url.append(preferredDS.getOwner()); } url.append("/").append(selectedSize); return url.toString(); } private  DatastreamUtil(); static void setDatastreamEndpoint(String uri); static String getDatastreamUrl(BriefObjectMetadata metadata, String datastreamName); static String getOriginalFileUrl(BriefObjectMetadata metadata); static Datastream getPreferredDatastream(BriefObjectMetadata metadata, String datastreamName); static String getThumbnailUrl(BriefObjectMetadata metadata, String size);  }### Answer:
@Test public void testGetThumbnailUrl() { PID pid = makePid(); BriefObjectMetadataBean mdObj = new BriefObjectMetadataBean(); mdObj.setId(pid.getId()); mdObj.setDatastream(asList(ORIGINAL_DS, THUMB_SMALL_DS)); String url = DatastreamUtil.getThumbnailUrl(mdObj, "small"); assertEquals(ENDPOINT_URL + "thumb/" + pid.getId() + "/small", url); }
@Test public void testGetThumbnailUrlForPrimaryObject() { PID primaryObjPid = makePid(); PID pid = makePid(); BriefObjectMetadataBean mdObj = new BriefObjectMetadataBean(); mdObj.setId(pid.getId()); mdObj.setDatastream(asList(ORIGINAL_DS, THUMB_SMALL_DS + primaryObjPid.getId())); String url = DatastreamUtil.getThumbnailUrl(mdObj, "small"); assertEquals(ENDPOINT_URL + "thumb/" + primaryObjPid.getId() + "/small", url); }
@Test public void testGetThumbnailUrlNoThumbs() { PID pid = makePid(); BriefObjectMetadataBean mdObj = new BriefObjectMetadataBean(); mdObj.setId(pid.getId()); mdObj.setDatastream(asList(ORIGINAL_DS)); String url = DatastreamUtil.getThumbnailUrl(mdObj, "small"); assertEquals("", url); }