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.Assert;
|
||||||
import org.junit.Test;
|
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 {
|
public class IterableStreamConversionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenIterable_whenConvertedToStream_thenTrue() {
|
public void givenIterable_whenConvertedToStream_thenNotNull() {
|
||||||
String[] names = { "Testing", "Iterable", "conversion", "to", "Stream" };
|
String[] names = { "Testing", "Iterable", "conversion", "to", "Stream" };
|
||||||
StreamIterable<String> iterable = new StreamIterable<>(names);
|
StreamIterable<String> iterable = new StreamIterable<>(names);
|
||||||
Assert.assertTrue(StreamSupport.stream(iterable.spliterator(), false) instanceof Stream<?>);
|
Assert.assertNotNull(StreamSupport.stream(iterable.spliterator(), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenConvertedToList_thenCorrect() {
|
public void whenConvertedToList_thenCorrect() {
|
||||||
String[] names = { "Testing", "Iterable", "conversion", "to", "Stream" };
|
String[] names = { "Testing", "Iterable", "conversion", "to", "Stream" };
|
||||||
StreamIterable<String> iterable = new StreamIterable<>(names);
|
StreamIterable<String> iterable = new StreamIterable<>(names);
|
||||||
Stream<String> convertedStream = StreamSupport.stream(iterable.spliterator(), false);
|
Stream<String> convertedStream = StreamSupport.stream(iterable.spliterator(), false);
|
||||||
Assert.assertTrue(convertedStream.map(String::toUpperCase)
|
List<String> collected = convertedStream.map(String::toUpperCase).collect(Collectors.toList());
|
||||||
.collect(Collectors.toList()) instanceof List<?>);
|
assertThat(collected, contains("TESTING", "ITERABLE", "CONVERSION", "TO", "STREAM"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class StreamIterable<T> implements Iterable<T> {
|
class StreamIterable<T> implements Iterable<T> {
|
||||||
private List<T> list;
|
private List<T> list;
|
||||||
|
|
||||||
public StreamIterable(T[] array) {
|
StreamIterable(T[] array) {
|
||||||
this.list = Arrays.asList(array);
|
this.list = Arrays.asList(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user