ObjectSet implements CloseableIterable<O>, Closeable { public static <O> ObjectSet<O> fromCollection(final Collection<O> collection) { return new CollectionAsObjectSet<O>(collection); }  @Override abstract void close(); abstract boolean isEmpty(); static ObjectSet<O> fromObjectStore(final ObjectStore<O> objectStore, final QueryOptions queryOptions); static ObjectSet<O> fromCollection(final Collection<O> collection);  }
@Test @SuppressWarnings("unchecked") public void testFromCollection_IteratorRemove() throws Exception { Collection<Car> collection = mock(Collection.class); Iterator<Car> iterator = mock(Iterator.class); when(iterator.hasNext()).thenReturn(true); when(iterator.next()).thenReturn(CarFactory.createCar(1)); when(collection.iterator()).thenReturn(iterator); ObjectSet<Car> objectSet = ObjectSet.fromCollection(collection); CloseableIterator<Car> objectSetIterator = objectSet.iterator(); Assert.assertTrue(objectSetIterator.hasNext()); Assert.assertNotNull(objectSetIterator.next()); objectSetIterator.remove(); Mockito.verify(iterator, times(1)).remove(); }