### Question:
ObjectStreams { public static <T> ObjectStream<T> wrap(Iterator<? extends T> iterator) { return new IteratorObjectStream<>(iterator); } private  ObjectStreams(); static ObjectStream<T> wrap(Iterator<? extends T> iterator); static ObjectStream<T> wrap(Stream<? extends T> stream); static ObjectStream<T> wrap(Stream<? extends T> stream,
                                           @WillCloseWhenClosed Closeable root); static ObjectStream<T> wrap(Collection<? extends T> collection); static ObjectStream<T> filter(@WillCloseWhenClosed ObjectStream<T> stream, Predicate<? super T> predicate); static ObjectStream<T> filter(@WillCloseWhenClosed final ObjectStream<?> source, final Class<T> type); static ObjectStream<T> consume(int n, ObjectStream<T> stream); @Deprecated static ObjectStream<T> transform(@WillCloseWhenClosed ObjectStream<S> objectStream, Function<? super S, ? extends T> function); static ObjectStream<T> empty(); @SuppressWarnings("PMD.LooseCoupling") @Deprecated static List<T> makeList(@WillClose ObjectStream<? extends T> objectStream); @SuppressWarnings("PMD.LooseCoupling") @Deprecated static int count(@WillClose ObjectStream<?> objectStream); @Deprecated static ObjectStream<T> sort(@WillClose ObjectStream<T> objectStream,
                                           Comparator<? super T> comp); @SafeVarargs @SuppressWarnings("varargs") // method is safe MDE 2015-05-08 static ObjectStream<T> of(T... contents); static ObjectStream<T> concat(Iterable<? extends ObjectStream<? extends T>> streams); @SafeVarargs @SuppressWarnings("varargs") // method is safe MDE 2015-05-08 static ObjectStream<T> concat(ObjectStream<? extends T>... objectStreams);  }### Answer:
@Test public void testWrapEmptyCollection() { ObjectStream<?> objectStream = ObjectStreams.wrap(Collections.emptyList()); try { assertThat(objectStream.readObject(), nullValue()); try { objectStream.iterator().next(); fail("next should fail on empty stream"); } catch (NoSuchElementException e) { } } finally { objectStream.close(); } }
@Test public void testWrapCollection() { ObjectStream<String> objectStream = ObjectStreams.wrap(Lists.newArrayList("foo", "bar")); try { assertThat(objectStream.readObject(), equalTo("foo")); assertThat(objectStream.readObject(), equalTo("bar")); assertThat(objectStream.readObject(), nullValue()); } finally { objectStream.close(); } }
@Test public void testWrapCollectionIterator() { ObjectStream<String> objectStream = ObjectStreams.wrap(Lists.newArrayList("foo", "bar")); try { List<String> strs = Lists.newArrayList(objectStream.iterator()); assertThat(strs, hasSize(2)); assertThat(strs, contains("foo", "bar")); } finally { objectStream.close(); } }
@Test public void testWrapIterator() { ObjectStream<String> stream = ObjectStreams.wrap(Lists.newArrayList("foo", "bar").iterator()); try { assertThat(stream, contains("foo", "bar")); } finally { stream.close(); } }
@Test public void testMapToInt() { List<Rating> ratings = makeRatings(); int correct = ratings.stream() .mapToInt(r -> (int) r.getUserId()) .sum(); int result = ObjectStreams.wrap(ratings) .mapToInt(r -> (int) r.getUserId()) .sum(); assertThat(result, equalTo(correct)); }
@Test public void testMapToLong() { List<Rating> ratings = makeRatings(); long correct = ratings.stream() .mapToLong(Rating::getUserId) .sum(); long result = ObjectStreams.wrap(ratings) .mapToLong(Rating::getUserId) .sum(); assertThat(result, equalTo(correct)); }
@Test public void testMapToDouble() { List<Rating> ratings = makeRatings(); double correct = ratings.stream() .mapToDouble(Rating::getValue) .sum(); double result = ObjectStreams.wrap(ratings) .mapToDouble(Rating::getValue) .sum(); assertThat(result, equalTo(correct)); }