Fixing assertions
@@ -10,13 +10,17 @@ 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
@@ -24,15 +28,15 @@ public class IterableStreamConversionTest {
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<?>);
+ 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);
}
