Separator { public T get() { T result = next; next = separator; return result; } Separator(T initial, T separator); T get();  }
@Test public void testOneElement() { StringBuilder sb = new StringBuilder(); for (String s : values.subList(0, 1)) { sb.append(sep.get()).append(s); } assertThat(sb.toString(), is("1")); }
@Test public void testTwoElements() { StringBuilder sb = new StringBuilder(); for (String s : values.subList(0, 2)) { sb.append(sep.get()).append(s); } assertThat(sb.toString(), is("1,2")); }
@Test public void testThreeElements() { StringBuilder sb = new StringBuilder(); for (String s : values) { sb.append(sep.get()).append(s); } assertThat(sb.toString(), is("1,2,3")); }