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