### Question:
SelectIterator implements CloseableIterator<T> { public void removeThrow() throws SQLException { if (last == null) { throw new IllegalStateException("No last " + dataClass + " object to remove. Must be called after a call to next."); } if (classDao == null) { throw new IllegalStateException("Cannot remove " + dataClass + " object because classDao not initialized"); } try { classDao.delete(last); } finally { last = null; } } SelectIterator(Class<?> dataClass, Dao<T, ID> classDao, GenericRowMapper<T> rowMapper,
			ConnectionSource connectionSource, DatabaseConnection connection, CompiledStatement compiledStmt,
			String statement, ObjectCache objectCache); boolean hasNextThrow(); @Override boolean hasNext(); @Override T first(); @Override T previous(); @Override T current(); @Override T nextThrow(); @Override T next(); @Override T moveRelative(int offset); void removeThrow(); @Override void remove(); @Override void close(); @Override void closeQuietly(); @Override DatabaseResults getRawResults(); @Override void moveToNext();  }### Answer:
@Test(expected = IllegalStateException.class) public void testRemoveThrow() throws Exception { ConnectionSource cs = createMock(ConnectionSource.class); cs.releaseConnection(null); CompiledStatement stmt = createMock(CompiledStatement.class); DatabaseResults results = createMock(DatabaseResults.class); expect(results.first()).andReturn(true); expect(stmt.runQuery(null)).andReturn(results); @SuppressWarnings("unchecked") GenericRowMapper<Foo> mapper = (GenericRowMapper<Foo>) createMock(GenericRowMapper.class); Foo foo = new Foo(); expect(mapper.mapRow(results)).andReturn(foo); @SuppressWarnings("unchecked") Dao<Foo, Integer> dao = (Dao<Foo, Integer>) createMock(Dao.class); expect(dao.delete(foo)).andThrow(new SQLException("some dao problem")); stmt.close(); replay(stmt, dao, results, mapper, cs); SelectIterator<Foo, Integer> iterator = new SelectIterator<Foo, Integer>(Foo.class, dao, mapper, cs, null, stmt, "statement", null); try { iterator.hasNext(); iterator.next(); iterator.remove(); } finally { iterator.close(); } }