@Test
public void testLazyTable() throws SQLException {
createAndFillUserTable();
Query q = sql2o.createQuery("select * from User");
LazyTable lt = null;
try {
lt = q.executeAndFetchTableLazy();
for (Row r : lt.rows()){
String name = r.getString("name");
assertThat(name, notNullValue());
}
// still in autoClosable scope. Expecting connection to be open.
assertThat(q.getConnection().getJdbcConnection().isClosed(), is(false));
} finally {
// simulate autoClose.
lt.close();
}
// simulated autoClosable scope exited. Expecting connection to be closed.
assertThat(q.getConnection().getJdbcConnection().isClosed(), is(true));
}