DATACMNS-1447 - Streamable now exposes Collectors.

Added Streamable.toStreamable() and ….toStreamable(Collector) to allow the creation of a Streamable from streams wither using a default List-based intermediate collector (former) or providing an explicit one (latter).
This commit is contained in:
Oliver Drotbohm
2018-12-12 10:36:40 +01:00
parent daaa16f195
commit 97390a1eef
2 changed files with 46 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.data.util;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.Test;
@@ -53,4 +54,16 @@ public class StreamableUnitTests {
public void concatenatesStreamable() {
assertThat(Streamable.of(1, 2).and(Streamable.of(3, 4))).containsExactly(1, 2, 3, 4);
}
@Test // DATACMNS-1447
public void usesStreamableCollectors() {
assertThat(Streamable.of(1, 2).stream() //
.collect(Streamable.toStreamable())) //
.containsExactly(1, 2);
assertThat(Streamable.of(1, 2, 2).stream() //
.collect(Streamable.toStreamable(Collectors.toSet()))) //
.containsExactlyInAnyOrder(1, 2);
}
}