### Question:
FeatureSetWrapper extends AbstractCollection<Feature> implements FeatureCollection { @Override public FeatureIterator iterator() throws FeatureStoreRuntimeException { final Stream<Feature> features; try { features = featureSet.features(false); } catch (DataStoreException ex) { throw new FeatureStoreRuntimeException(ex); } final WrapFeatureIterator it = new WrapFeatureIterator(features.iterator()) {}; it.onClose(features::close); return it; } FeatureSetWrapper(FeatureSet featureSet, DataStore store); @Override Optional<GenericName> getIdentifier(); @Override FeatureType getType(); @Override Optional<Envelope> getEnvelope(); @Override FeatureCollection subset(Query query); @Override FeatureIterator iterator(); @Override FeatureIterator iterator(Hints hints); @Override void addListener(Class<T> eventType, StoreListener<? super T> listener); @Override void removeListener(Class<T> eventType, StoreListener<? super T> listener); @Override boolean isWritable(); @Override void updateType(FeatureType newType); @Override void add(Iterator<? extends Feature> features); @Override boolean add(Feature e); @Override void replaceIf(Predicate<? super Feature> filter, UnaryOperator<Feature> updater); @Override void update(Feature feature); @Override void update(Filter filter, Map<String, ?> values); @Override void remove(Filter filter); @Override boolean remove(Object o); @Override Session getSession(); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override boolean containsAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); @Override void clear(); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override boolean addAll(Collection<? extends Feature> clctn); @Override boolean removeAll(Collection<?> clctn);  }### Answer:
@Test public void ensureProperClosing() { final Semaphore closeSignal = new Semaphore(1); final FeatureSetWrapper features = new FeatureSetWrapper(new SynchronizedSet(closeSignal), null); try (final FeatureIterator it = features.iterator()) { if (it.hasNext()) it.next(); } Assert.assertTrue("Feature set wrapper iterator has not been properly closed", closeSignal.tryAcquire()); }