RowResultScanner implements ResultScanner<T> { @Override public T next() { if (!iterator.hasNext()) { return null; } try (Timer.Context ignored = resultsTimer.time()) { T result = iterator.next(); resultsMeter.mark(); return result; } catch (RuntimeException e) { throw e; } } RowResultScanner(ServerStream<T> stream, T[] arr); @Override T next(); @Override T[] next(int count); @Override int available(); @Override void close();  }
@Test public void testNextWhenValueIsPresent() { List<String> listOfOneElement = ImmutableList.of(TEST_VALUE); when(stream.iterator()).thenReturn(listOfOneElement.iterator()); scanner = new RowResultScanner<>(stream, TEST_ARRAY); assertEquals(TEST_VALUE, scanner.next()); assertNull(scanner.next()); verify(stream).iterator(); }
@Test public void testNextWhenNoValueIsPresent() { List<String> listOfWithoutElement = ImmutableList.of(); when(stream.iterator()).thenReturn(listOfWithoutElement.iterator()); scanner = new RowResultScanner<>(stream, TEST_ARRAY); assertNull(scanner.next()); verify(stream).iterator(); }
@Test public void testNextWithCount() { List<String> listWithMultipleElmt = ImmutableList.of("firstValue", "secondValue", "thirdValue"); when(stream.iterator()).thenReturn(listWithMultipleElmt.iterator()); scanner = new RowResultScanner<>(stream, TEST_ARRAY); String[] actualArr = scanner.next(3); assertArrayEquals(listWithMultipleElmt.toArray(TEST_ARRAY), actualArr); verify(stream).iterator(); }