@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
public void shouldAlwaysCloseThePreparedStatmentOnException() throws Exception {

    final NullPointerException nullPointerException = new NullPointerException("Ooops");
    final PreparedStatementWrapper preparedStatementWrapper = mock(PreparedStatementWrapper.class);
    final ResultSet resultSet = mock(ResultSet.class);
    when(preparedStatementWrapper.executeQuery()).thenReturn(resultSet);
    when(resultSet.next()).thenReturn(true);
    final Stream<Student> studentStream = jdbcResultSetStreamer.streamOf(preparedStatementWrapper, rs -> {
        throw nullPointerException;
    });
    try {
        studentStream.collect(toList());
        fail();
    } catch (final JdbcRepositoryException expected) {
        assertThat(expected.getCause(), is(nullPointerException));
    }
    verify(preparedStatementWrapper).close();
}