BAEL-581 - Fixing assertions

This commit is contained in:
slavisa-baeldung 2017-01-17 11:30:15 +01:00
parent 67206a4a5c
commit a7c1fb3b72
1 changed files with 15 additions and 11 deletions

View File

@ -10,29 +10,33 @@ import java.util.stream.StreamSupport;
import org.junit.Assert;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
public class IterableStreamConversionTest {
@Test
public void givenIterable_whenConvertedToStream_thenTrue() {
public void givenIterable_whenConvertedToStream_thenNotNull() {
String[] names = { "Testing", "Iterable", "conversion", "to", "Stream" };
StreamIterable<String> iterable = new StreamIterable<>(names);
Assert.assertTrue(StreamSupport.stream(iterable.spliterator(), false) instanceof Stream<?>);
Assert.assertNotNull(StreamSupport.stream(iterable.spliterator(), false));
}
@Test
public void whenConvertedToList_thenCorrect() {
String[] names = { "Testing", "Iterable", "conversion", "to", "Stream" };
StreamIterable<String> iterable = new StreamIterable<>(names);
Stream<String> convertedStream = StreamSupport.stream(iterable.spliterator(), false);
Assert.assertTrue(convertedStream.map(String::toUpperCase)
.collect(Collectors.toList()) instanceof List<?>);
}
@Test
public void whenConvertedToList_thenCorrect() {
String[] names = { "Testing", "Iterable", "conversion", "to", "Stream" };
StreamIterable<String> iterable = new StreamIterable<>(names);
Stream<String> convertedStream = StreamSupport.stream(iterable.spliterator(), false);
List<String> collected = convertedStream.map(String::toUpperCase).collect(Collectors.toList());
assertThat(collected, contains("TESTING", "ITERABLE", "CONVERSION", "TO", "STREAM"));
}
}
class StreamIterable<T> implements Iterable<T> {
private List<T> list;
public StreamIterable(T[] array) {
StreamIterable(T[] array) {
this.list = Arrays.asList(array);
}