### Question:
Collection { public static <T> String join(List<T> list, String separator, Function<T, String> function) { String result = ""; for (int i = 0; i < list.size(); i++) { result += function.apply(list.get(i)).trim(); if (i + 1 < list.size()) { result += separator; } } return result; } private  Collection(); static String[] tail(String[] args); @SafeVarargs static T[] create(T... args); static String join(List<T> list, String separator, Function<T, String> function); static String join(List<String> list, String separator);  }### Answer:
@Test public void testJoin() { assertThat(join(Arrays.asList("a ", "b ", " c "), ","), is("a,b,c")); assertThat(join(Arrays.asList("a", "b", "c", "d"), ","), is("a,b,c,d")); assertThat(join(Arrays.asList("a ", "b ", " c "), ", "), is("a, b, c")); assertThat(join(Arrays.asList("a", "b", "c", "d"), ", "), is("a, b, c, d")); }
@Test public void testJoinWithFunction() { final List<FakeSpec> specs1 = Arrays.asList( new FakeSpec("a"), new FakeSpec("b"), new FakeSpec("c")); assertThat(join(specs1, ",", FakeSpec::getName), is("a,b,c")); final List<FakeSpec> specs2 = Arrays.asList( new FakeSpec("a"), new FakeSpec("b"), new FakeSpec("c")); assertThat(join(specs2, ", ", FakeSpec::getName), is("a, b, c")); final List<FakeSpec> specs3 = Arrays.asList( new FakeSpec(" a"), new FakeSpec("b "), new FakeSpec(" c ")); assertThat(join(specs3, ",", FakeSpec::getName), is("a,b,c")); final List<FakeSpec> specs4 = Arrays.asList( new FakeSpec(" a"), new FakeSpec("b "), new FakeSpec(" c ")); assertThat(join(specs4, ", ", FakeSpec::getName), is("a, b, c")); }