@Test void tryAdvanceWhenNextThrows() throws SQLException { when(resultSet.next()).thenThrow(new SQLException("Connection lost")); ResultSetSpliterator<String> sut = new ResultSetSpliterator<>(resultSet, rowMapper); calling(() -> sut.tryAdvance(action)) .shouldThrow(RuntimeSqlException.class) .withCause(SQLException.class) .withMessage(is("Connection lost")); verify(resultSet).next(); verifyNoMoreInteractions(resultSet, rowMapper, action); }
@Override public boolean tryAdvance(Consumer<? super T> action) { try { if (exhausted.get() || !resultSet.next()) { if (!exhausted.getAndSet(true)) { atEnd.run(); } return false; } action.accept(rowMapper.mapRow(resultSet)); return true; } catch (SQLException e) { throw new RuntimeSqlException(e); } }
ResultSetSpliterator extends Spliterators.AbstractSpliterator<T> { @Override public boolean tryAdvance(Consumer<? super T> action) { try { if (exhausted.get() || !resultSet.next()) { if (!exhausted.getAndSet(true)) { atEnd.run(); } return false; } action.accept(rowMapper.mapRow(resultSet)); return true; } catch (SQLException e) { throw new RuntimeSqlException(e); } } }
ResultSetSpliterator extends Spliterators.AbstractSpliterator<T> { @Override public boolean tryAdvance(Consumer<? super T> action) { try { if (exhausted.get() || !resultSet.next()) { if (!exhausted.getAndSet(true)) { atEnd.run(); } return false; } action.accept(rowMapper.mapRow(resultSet)); return true; } catch (SQLException e) { throw new RuntimeSqlException(e); } } ResultSetSpliterator(ResultSet resultSet, RowMapper<T> rowMapper);  ResultSetSpliterator(ResultSet resultSet, RowMapper<T> rowMapper, Runnable atEnd); }
ResultSetSpliterator extends Spliterators.AbstractSpliterator<T> { @Override public boolean tryAdvance(Consumer<? super T> action) { try { if (exhausted.get() || !resultSet.next()) { if (!exhausted.getAndSet(true)) { atEnd.run(); } return false; } action.accept(rowMapper.mapRow(resultSet)); return true; } catch (SQLException e) { throw new RuntimeSqlException(e); } } ResultSetSpliterator(ResultSet resultSet, RowMapper<T> rowMapper);  ResultSetSpliterator(ResultSet resultSet, RowMapper<T> rowMapper, Runnable atEnd); @Override boolean tryAdvance(Consumer<? super T> action); }
ResultSetSpliterator extends Spliterators.AbstractSpliterator<T> { @Override public boolean tryAdvance(Consumer<? super T> action) { try { if (exhausted.get() || !resultSet.next()) { if (!exhausted.getAndSet(true)) { atEnd.run(); } return false; } action.accept(rowMapper.mapRow(resultSet)); return true; } catch (SQLException e) { throw new RuntimeSqlException(e); } } ResultSetSpliterator(ResultSet resultSet, RowMapper<T> rowMapper);  ResultSetSpliterator(ResultSet resultSet, RowMapper<T> rowMapper, Runnable atEnd); @Override boolean tryAdvance(Consumer<? super T> action);  }