### Question:
CloseableIterableOnce implements CloseableIterable<T> { @Override public Iterator<T> iterator() { Iterator<T> temp = iterator.getAndSet(null); if (temp == null) { throw new IllegalStateException("iterator is exhausted"); } return temp; } CloseableIterableOnce(Iterator<T> iterator); @Override Iterator<T> iterator(); @Override void close();  }### Answer:
@Test public void testIterator() { List<String> list = ImmutableList.of("foo"); CloseableIterable<String> iterable = new CloseableIterableOnce<>(list.iterator()); assertEquals(list, ImmutableList.copyOf(iterable.iterator())); thrown.expect(IllegalStateException.class); iterable.iterator(); }