|
10 | 10 | import org.junit.Assert; |
11 | 11 | import org.junit.Test; |
12 | 12 |
|
| 13 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 14 | +import static org.hamcrest.Matchers.containsInAnyOrder; |
| 15 | +import static org.hamcrest.collection.IsIterableContainingInOrder.contains; |
| 16 | + |
13 | 17 | public class IterableStreamConversionTest { |
14 | 18 |
|
15 | 19 | @Test |
16 | | - public void givenIterable_whenConvertedToStream_thenTrue() { |
| 20 | + public void givenIterable_whenConvertedToStream_thenNotNull() { |
17 | 21 | String[] names = { "Testing", "Iterable", "conversion", "to", "Stream" }; |
18 | 22 | StreamIterable<String> iterable = new StreamIterable<>(names); |
19 | | - Assert.assertTrue(StreamSupport.stream(iterable.spliterator(), false) instanceof Stream<?>); |
| 23 | + Assert.assertNotNull(StreamSupport.stream(iterable.spliterator(), false)); |
20 | 24 | } |
21 | 25 |
|
22 | | - @Test |
23 | | - public void whenConvertedToList_thenCorrect() { |
24 | | - String[] names = { "Testing", "Iterable", "conversion", "to", "Stream" }; |
25 | | - StreamIterable<String> iterable = new StreamIterable<>(names); |
26 | | - Stream<String> convertedStream = StreamSupport.stream(iterable.spliterator(), false); |
27 | | - Assert.assertTrue(convertedStream.map(String::toUpperCase) |
28 | | - .collect(Collectors.toList()) instanceof List<?>); |
29 | | - } |
| 26 | +@Test |
| 27 | +public void whenConvertedToList_thenCorrect() { |
| 28 | + String[] names = { "Testing", "Iterable", "conversion", "to", "Stream" }; |
| 29 | + StreamIterable<String> iterable = new StreamIterable<>(names); |
| 30 | + Stream<String> convertedStream = StreamSupport.stream(iterable.spliterator(), false); |
| 31 | + List<String> collected = convertedStream.map(String::toUpperCase).collect(Collectors.toList()); |
| 32 | + assertThat(collected, contains("TESTING", "ITERABLE", "CONVERSION", "TO", "STREAM")); |
| 33 | +} |
30 | 34 | } |
31 | 35 |
|
32 | 36 | class StreamIterable<T> implements Iterable<T> { |
33 | 37 | private List<T> list; |
34 | 38 |
|
35 | | - public StreamIterable(T[] array) { |
| 39 | + StreamIterable(T[] array) { |
36 | 40 | this.list = Arrays.asList(array); |
37 | 41 | } |
38 | 42 |
|
|
0 commit comments