RowResultScanner implements ResultScanner<T> { @Override public void close() { if (iterator.hasNext()) { stream.cancel(); } } RowResultScanner(ServerStream<T> stream, T[] arr); @Override T next(); @Override T[] next(int count); @Override int available(); @Override void close();  }
@Test public void testClose() throws Exception { List<String> listOfOneElement = ImmutableList.of(TEST_VALUE, TEST_VALUE); when(stream.iterator()).thenReturn(listOfOneElement.iterator()); doNothing().when(stream).cancel(); try (ResultScanner<String> closedScanner = new RowResultScanner<>(stream, TEST_ARRAY)) { assertEquals(TEST_VALUE, closedScanner.next()); } verify(stream).iterator(); verify(stream).cancel(); }