ResultSetSpliterator extends Spliterators.AbstractSpliterator<ResultRow> { @Override public boolean tryAdvance(Consumer<? super ResultRow> action) { Objects.requireNonNull(action); try { if (resultSet.hasNext()) { resultSet.next(); action.accept(new DelegatingResultRow(resultSet)); return true; } else { return false; } } 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 tryAdvanceInvokesActionOnNextResultRowAndReturnsTrue() throws Exception { when(resultSet.hasNext()).thenReturn(true); final Consumer<ResultRow> consumer = mock(Consumer.class); final boolean result = sut.tryAdvance(consumer); assertTrue(result); verify(resultSet).next(); verify(consumer).accept(any(ResultRow.class)); }
@Test void tryAdvanceDoesNothingAndReturnsFalseWhenThereAreNoMoreRowsInResultSet() throws Exception { when(resultSet.hasNext()).thenReturn(false); final Consumer<ResultRow> consumer = mock(Consumer.class); final boolean result = sut.tryAdvance(consumer); assertFalse(result); verify(resultSet, never()).next(); verify(consumer, never()).accept(any(ResultRow.class)); }
@Test void tryAdvanceThrowsOntoDriverRuntimeExceptionWhenResultResultSetThrowsException() 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.tryAdvance(consumer)); assertThat(result.getCause(), instanceOf(OntoDriverException.class)); }