### Question:
StaticStringUtils { public static <T> String collectionToString(Collection<T> collection, String delimiter) { if (collection == null) { return "null"; } if (collection.isEmpty()) { return "[]"; } StringBuilder sb = new StringBuilder(); sb.append("["); List<T> list = new ArrayList<T>(collection); for (int i = 0; i < list.size() - 1; i++) { T entry = list.get(i); if (entry == null) { sb.append("null").append(delimiter); continue; } sb.append(entry.toString()).append(delimiter); } sb.append(list.get(list.size() - 1)).append("]"); return sb.toString(); }  static String lpadLong(long val, String pad, int npad); static String lpad(String val, String pad, int npad); static String getExtendedStackTrace(Throwable th); static String mapToString(Map<K, V> map, String delimiter); static String collectionToString(Collection<T> collection, String delimiter); static String truncate(String stringIn, int maxLen); static String mapToString(Map<K, V> mapIn); static String stripCRLF(String line); static String[] stripBlankArgs(String line); static Map<String, String> argMapper(String[] args); static String[] stripKwArgs(String[] args); static String justOneCR(String strIn); static String showDiff(String a, String b);  }### Answer:
@Test public void testSetToString() { String out = ""; Set<String> testSet = new HashSet<String>(); out = StaticStringUtils.<String>collectionToString(testSet, ", "); testSet.add("test1"); out = StaticStringUtils.<String>collectionToString(testSet, ", "); testSet.add("test2"); out = StaticStringUtils.<String>collectionToString(testSet, ", "); testSet.add("test3"); out = StaticStringUtils.<String>collectionToString(testSet, ", "); }
@Test public void testListToString() { String out = ""; List<String> testSet = new ArrayList<String>(); out = StaticStringUtils.<String>collectionToString(testSet, ", "); assertTrue(out.equals("[]")); assertFalse(out.equals("")); testSet.add("test1"); out = StaticStringUtils.<String>collectionToString(testSet, ", "); assertTrue(out.equals("[test1]")); assertFalse(out.equals("")); testSet.add("test2"); out = StaticStringUtils.<String>collectionToString(testSet, ", "); assertTrue(out.equals("[test1, test2]")); assertFalse(out.equals("")); testSet.add("test3"); out = StaticStringUtils.<String>collectionToString(testSet, ", "); assertTrue(out.equals("[test1, test2, test3]")); assertFalse(out.equals("")); }