BAEL-581 - Fixing assertions
This commit is contained in:
parent
67206a4a5c
commit
a7c1fb3b72
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue