### Question:
CombiningResourceIterator extends CombiningIterator<T> implements ResourceIterator<T> { @Override public void close() { for ( ResourceIterator<T> seenIterator : seenIterators ) { seenIterator.close(); } while ( iterators.hasNext() ) { iterators.next().close(); } } CombiningResourceIterator( Iterator<ResourceIterator<T>> iterators ); @Override void close();  }### Answer:
@Test void shouldNotCloseDuringIteration() { ResourceIterator<Long> it1 = spy( asResourceIterator( iterator( 1L, 2L, 3L ) ) ); ResourceIterator<Long> it2 = spy( asResourceIterator( iterator( 5L, 6L, 7L ) ) ); CombiningResourceIterator<Long> combingIterator = new CombiningResourceIterator<>( iterator(it1, it2) ); assertThat( Iterators.asList( combingIterator ), equalTo(asList( 1L, 2L, 3L, 5L, 6L, 7L )) ); verify(it1, never()).close(); verify(it2, never()).close(); }
@Test void closesAllIteratorsOnShutdown() { ResourceIterator<Long> it1 = spy( asResourceIterator( iterator( 1L, 2L, 3L ) ) ); ResourceIterator<Long> it2 = spy( asResourceIterator( iterator( 5L, 6L, 7L ) ) ); CombiningResourceIterator<Long> combingIterator = new CombiningResourceIterator<>( iterator(it1, it2) ); int iterations = 4; while ( iterations-- > 0 ) { combingIterator.next(); } combingIterator.close(); verify(it1).close(); verify(it2).close(); }