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.ArrayList;
21 import java.util.List;
22 import java.util.function.Function;
23
24 import static java.util.Arrays.asList;
25 import static org.hamcrest.MatcherAssert.assertThat;
26 import static org.hamcrest.Matchers.contains;
27
28 public class IterableVarianceTest {
29
30 @Test public void flatMap() {
31 final Iterable<String> result = Iterables.flatMap(asList("123", "ABC"), new Function<CharSequence, List<String>>() {
32 public List<String> apply(final CharSequence from) {
33 return copyOf(new IterablesTest.CharSplitter(from));
34 }
35 });
36 assertThat(result, contains("1", "2", "3", "A", "B", "C"));
37 }
38
39
40 private List<String> copyOf(final IterablesTest.CharSplitter strings) {
41 final List<String> copy = new ArrayList<>();
42 for (String s : strings) {
43 copy.add(s);
44 }
45 return copy;
46 }
47 }