### Question:
IdGeneratorHelper { public static String generateUUID(Map<String, Object> data, List<String> idFields) { String uuid = null; if (CollectionUtils.isNotEmpty(idFields)) { final StringBuilder sb = new StringBuilder(); for (String idField : idFields) { if (data.containsKey(idField)) { sb.append(data.get(idField).toString()); } } String concatId = sb.toString(); if (StringUtils.isNotEmpty(concatId)) { uuid = UUID.nameUUIDFromBytes(concatId.getBytes()).toString(); } else { uuid = UUID.randomUUID().toString(); } } else { uuid = UUID.randomUUID().toString(); } return uuid; } private  IdGeneratorHelper(); static String generateUUID(Map<String, Object> data, List<String> idFields);  }### Answer:
@Test public void testGenerateRandomUUID() { Map<String, Object> fieldKeyMap = new HashMap<>(); List<String> fields = new ArrayList<>(); String uuid1 = IdGeneratorHelper.generateUUID(fieldKeyMap, fields); String uuid2 = IdGeneratorHelper.generateUUID(fieldKeyMap, fields); assertFalse(uuid1.equals(uuid2)); }
@Test public void testUUIDFromFields() { Map<String, Object> fieldKeyMap1 = new HashMap<>(); fieldKeyMap1.put("one-field", "1"); Map<String, Object> fieldKeyMap2 = new HashMap<>(); fieldKeyMap2.put("one-field", "1"); List<String> fields = new ArrayList<>(); fields.add("one-field"); String uuid1 = IdGeneratorHelper.generateUUID(fieldKeyMap1, fields); String uuid2 = IdGeneratorHelper.generateUUID(fieldKeyMap2, fields); assertTrue(uuid1.equals(uuid2)); }
@Test public void testUUIDFromFieldsWithMultipleFields() { Map<String, Object> fieldKeyMap1 = new HashMap<>(); fieldKeyMap1.put("one-field", "1"); fieldKeyMap1.put("two-field", "2"); Map<String, Object> fieldKeyMap2 = new HashMap<>(); fieldKeyMap2.put("one-field", "1"); fieldKeyMap2.put("two-field", "2"); List<String> fields = new ArrayList<>(); fields.add("one-field"); fields.add("two-field"); String uuid1 = IdGeneratorHelper.generateUUID(fieldKeyMap1, fields); String uuid2 = IdGeneratorHelper.generateUUID(fieldKeyMap2, fields); assertTrue(uuid1.equals(uuid2)); }
@Test public void testUUIDFromFieldsDifferentNumberOfFields() { Map<String, Object> fieldKeyMap1 = new HashMap<>(); fieldKeyMap1.put("one-field", "1"); Map<String, Object> fieldKeyMap2 = new HashMap<>(); fieldKeyMap2.put("one-field", "1"); fieldKeyMap2.put("two-field", "2"); List<String> fields = new ArrayList<>(); fields.add("one-field"); fields.add("two-field"); String uuid1 = IdGeneratorHelper.generateUUID(fieldKeyMap1, fields); String uuid2 = IdGeneratorHelper.generateUUID(fieldKeyMap2, fields); assertFalse(uuid1.equals(uuid2)); }