ObjectSet implements CloseableIterable<O>, Closeable { public static <O> ObjectSet<O> fromObjectStore(final ObjectStore<O> objectStore, final QueryOptions queryOptions) { return new ObjectStoreAsObjectSet<O>(objectStore, queryOptions); }  @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 testFromObjectStore_IteratorRemove() throws Exception { ObjectStore<Car> objectStore = mock(ObjectStore.class); CloseableIterator<Car> closeableIterator = mock(CloseableIterator.class); when(closeableIterator.hasNext()).thenReturn(true); when(closeableIterator.next()).thenReturn(CarFactory.createCar(1)); when(objectStore.iterator(Mockito.<QueryOptions>any())).thenReturn(closeableIterator); ObjectSet<Car> objectSet = ObjectSet.fromObjectStore(objectStore, noQueryOptions()); CloseableIterator<Car> objectSetIterator = objectSet.iterator(); Assert.assertTrue(objectSetIterator.hasNext()); Assert.assertNotNull(objectSetIterator.next()); objectSetIterator.remove(); Mockito.verify(closeableIterator, times(1)).remove(); }