ResultSetSpliterator extends Spliterators.AbstractSpliterator<ResultRow> { @Override public void forEachRemaining(Consumer<? super ResultRow> action) { Objects.requireNonNull(action); try { final DelegatingResultRow row = new DelegatingResultRow(resultSet); while (resultSet.hasNext()) { resultSet.next(); action.accept(row); } } catch (OntoDriverException e) { throw new OntoDriverRuntimeException(e); } } ResultSetSpliterator(ResultSet resultSet); @Override boolean tryAdvance(Consumer<? super ResultRow> action); @Override void forEachRemaining(Consumer<? super ResultRow> action);  }
@Test void forEachRemainingInvokesConsumerForAllResultSetRows() throws Exception { when(resultSet.hasNext()).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(false); final Consumer<ResultRow> consumer = mock(Consumer.class); sut.forEachRemaining(consumer); verify(resultSet, times(3)).next(); verify(consumer, times(3)).accept(any(ResultRow.class)); }
@Test void forEachRemainingThrowsOntoDriverRuntimeExceptionWhenResultSetThrowsException() throws Exception { when(resultSet.hasNext()).thenReturn(true); doThrow(OntoDriverException.class).when(resultSet).next(); final Consumer<ResultRow> consumer = mock(Consumer.class); final OntoDriverRuntimeException result = assertThrows(OntoDriverRuntimeException.class, () -> sut.forEachRemaining(consumer)); assertThat(result.getCause(), instanceOf(OntoDriverException.class)); }