CountHandler implements OutputOperationHandler<Count<T>, Long> { @Override public Long doOperation(final Count operation, final Context context, final Store store) throws OperationException { if (null == operation.getInput()) { throw new OperationException("Count operation has null iterable of items"); } return Streams.toStream(operation.getInput()).count(); }  @Override Long doOperation(final Count operation, final Context context, final Store store);  }
@Test public void shouldReturnCount() throws OperationException { final CountHandler handler = new CountHandler(); final Store store = mock(Store.class); final Count count = mock(Count.class); final CloseableIterable<Element> elements = CountGroupsHandlerTest.getElements(); final Context context = new Context(); given(count.getInput()).willReturn(elements); final Long result = handler.doOperation(count, context, store); assertEquals(8L, (long) result); }