@Test
public void shouldConvertJdbcResultSetToAStreamOfObjects() throws Exception {

    final PreparedStatementWrapper preparedStatementWrapper = mock(PreparedStatementWrapper.class);
    final ResultSet resultSet = mock(ResultSet.class);
    when(preparedStatementWrapper.executeQuery()).thenReturn(resultSet);
    when(resultSet.next()).thenReturn(true, true, false);
    when(resultSet.getString("name")).thenReturn("Fred", "Bert");
    when(resultSet.getInt("age")).thenReturn(63, 59);
    final Function<ResultSet, Student> resultSetFunction = rs -> {
        try {
            return new Student(
                    rs.getString("name"),
                    rs.getInt("age"));
        } catch (final SQLException e) {
            throw new RuntimeException(e);
        }
    };
    try (final Stream<Student> studentStream = jdbcResultSetStreamer.streamOf(preparedStatementWrapper, resultSetFunction)) {
        final List<Student> students = studentStream.collect(toList());
        assertThat(students.size(), is(2));
        assertThat(students.get(0).getName(), is("Fred"));
        assertThat(students.get(0).getAge(), is(63));
        assertThat(students.get(1).getName(), is("Bert"));
        assertThat(students.get(1).getAge(), is(59));
    }
    verify(preparedStatementWrapper).close();
}