1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.atlassian.fugue;
17
18 import org.junit.Test;
19
20 import java.util.function.Supplier;
21
22 import static io.atlassian.fugue.Iterables.intersperse;
23 import static java.util.Arrays.asList;
24 import static org.hamcrest.Matchers.contains;
25 import static org.junit.Assert.assertThat;
26
27 public class IterablesIntersperseTest {
28
29 @Test public void interspersed() {
30 assertThat(intersperse(asList("a", "b", "c"), "-"), contains("a", "-", "b", "-", "c"));
31 }
32
33 @Test public void interspersedSupplier() {
34 final Supplier<Integer> count = new Supplier<Integer>() {
35 int count = 0;
36
37 @Override public Integer get() {
38 try {
39 return count;
40 } finally {
41 count += 1;
42 }
43 }
44 };
45 assertThat(intersperse(asList(100, 200, 300), count), contains(100, 0, 200, 1, 300));
46 }
47 }