ToStreamHandler implements OutputOperationHandler<ToStream<T>, Stream<? extends T>> { @Override public Stream<? extends T> doOperation(final ToStream<T> operation, final Context context, final Store store) throws OperationException { if (null == operation.getInput()) { return null; } return Streams.toStream(operation.getInput()); }  @Override Stream<? extends T> doOperation(final ToStream<T> operation, final Context context, final Store store);  }
@Test public void shouldConvertIterableToStream() throws OperationException { final List<Integer> originalList = Arrays.asList(1, 2, 3); final Iterable<Integer> originalResults = new WrappedCloseableIterable<>(originalList); final ToStreamHandler<Integer> handler = new ToStreamHandler(); final ToStream operation = mock(ToStream.class); given(operation.getInput()).willReturn(originalResults); final Stream<Integer> stream = handler.doOperation(operation, new Context(), null); final List<Integer> results = stream.collect(Collectors.toList()); assertEquals(originalList, results); }
@Test public void shouldHandleNullInput() throws OperationException { final ToStreamHandler<Integer> handler = new ToStreamHandler(); final ToStream operation = mock(ToStream.class); given(operation.getInput()).willReturn(null); final Stream<Integer> results = handler.doOperation(operation, new Context(), null); assertThat(results, is(nullValue())); }