### Question:
UuidDicomUidGenerator implements DicomUidGenerator { @Override public String getNewDicomUid(String root) { if (root == null) { throw new NullPointerException("root is required"); } if (!DicomUidValidator.isValid(root)) { throw new IllegalArgumentException("root is an invalid DICOM UID"); } if (root.length() > MAX_ROOT_LENGTH) { throw new IllegalArgumentException("root length is > " + MAX_ROOT_LENGTH); } final String suffix = new DecimalUuid(java.util.UUID.randomUUID()).toString(); return root + DICOM_UID_SEPARATOR + suffix; }  @Override int getMaxRootLength(); @Override String getNewDicomUid(String root);  }### Answer:
@Test public void shouldReturnAValidUidPrefixedWithRoot() throws Exception { String root = "1.2.5.6.7.1220"; String uid = dicomUidGenerator.getNewDicomUid(root); assertThat(uid, startsWith(root)); }
@Test public void shouldAlwaysReturnUniqueUidsWhenCalledMultipleTimes() throws Exception { String root = "1.2.5.6.7.1220"; int N = 1000; final Set<String> uniqueStudyInstanceUids = new HashSet<String>(N); for (int i = 0; i < N; i++) { uniqueStudyInstanceUids.add(dicomUidGenerator.getNewDicomUid(root)); } assertThat(uniqueStudyInstanceUids.size(), is(N)); }
@Test public void shouldReturnAUidNotExceeding64Characters() throws Exception { String uid = dicomUidGenerator.getNewDicomUid("1.2.5.6.7.1220"); assertThat(uid.length(), is(not(greaterThan(64)))); }
@Test public void shouldReturnAUidComposedOnlyOfCharacters09SeparatedByADot() throws Exception { String uid = dicomUidGenerator.getNewDicomUid("1.2.5.6.7.1220"); assertTrue(DicomUidValidator.isPatternValid(uid)); }
@Test public void shouldReturnAUidWithNoNonsignificantLeadingZeros() throws Exception { String uid = dicomUidGenerator.getNewDicomUid("1.2.5.6.7.1220"); assertTrue(DicomUidValidator.isPatternValid(uid)); }
@Test public void shouldFailIfRootIsNull() throws Exception { expectedException.expect(NullPointerException.class); expectedException.expectMessage("root is required"); dicomUidGenerator.getNewDicomUid(null); }
@Test public void shouldFailIfRootIsEmpty() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("root is an invalid DICOM UID"); dicomUidGenerator.getNewDicomUid(" "); }
@Test public void shouldFailIfRootIsNotAValidUID() throws Exception { String root = "1.2.A.1"; expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("root is an invalid DICOM UID"); dicomUidGenerator.getNewDicomUid(root); root = StringUtils.repeat("1.2", 22); assertThat(root.length(), is(greaterThan(64))); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("root is an invalid DICOM UID"); dicomUidGenerator.getNewDicomUid(root); }