StringUtils { public static String convertToUUIDString(String value) { if (value == null || value.contains("-") || value.length() != 32) { return value; } StringBuilder sb = new StringBuilder(value); char dash = '-'; sb.insert(8, dash); sb.insert(13, dash); sb.insert(18, dash); sb.insert(23, dash); return sb.toString(); } private  StringUtils(); static String join(List<String> list, String separator); static String convertToUUIDString(String value);  }
@Test public void whenInputIsRawUUIDShouldReturnValidUUID() { String uuid = StringUtils.convertToUUIDString("28A8836D5642534BB46B34F87E078729"); assertThat(uuid, is("28A8836D-5642-534B-B46B-34F87E078729")); }
@Test public void whenInputIsNullShouldReturnNull() { String uuid = StringUtils.convertToUUIDString(null); assertThat(uuid, is(nullValue())); }
@Test public void whenInputIsNotAtCorrectLengthShouldReturnInputValue() { String uuid = StringUtils.convertToUUIDString("abc"); assertThat(uuid, is("abc")); }