ToSingletonListHandler implements OutputOperationHandler<ToSingletonList<T>, List<? extends T>> { @Override public List<? extends T> doOperation(final ToSingletonList<T> operation, final Context context, final Store store) throws OperationException { if (null != operation.getInput()) { return Collections.singletonList(operation.getInput()); } else { throw new OperationException("Input cannot be null"); } }  @Override List<? extends T> doOperation(final ToSingletonList<T> operation, final Context context, final Store store);  }
@Test public void shouldConvertIntToSingletonList() throws OperationException { final int singleInt = 4; final List<Integer> expectedResult = Arrays.asList(4); final ToSingletonListHandler handler = new ToSingletonListHandler(); final ToSingletonList<Integer> operation = new ToSingletonList.Builder<Integer>().input(singleInt).build(); final Iterable<Integer> result = handler.doOperation(operation, new Context(), null); assertEquals(expectedResult, result); }
@Test public void shouldHandleNullInput() throws OperationException { final ToSingletonListHandler handler = new ToSingletonListHandler(); final ToSingletonList<Integer> operation = new ToSingletonList.Builder<Integer>().input(null).build(); try { handler.doOperation(operation, new Context(), null); } catch (final OperationException e) { assertTrue(e.getMessage().equals("Input cannot be null")); } }