@Test
public void testDeduplicatingResultSet() {

    Collection<Car> cars = CarFactory.createCollectionOfCars(10);
    DeduplicatingResultSet<Car, String> deduplicatingResultSet = new DeduplicatingResultSet<Car, String>(
            Car.MANUFACTURER,
            new StoredSetBasedResultSet<Car>(new LinkedHashSet<Car>(cars)),
            QueryFactory.all(Car.class), QueryFactory.noQueryOptions()
    );
    List<Integer> carIdsReturned = new ArrayList<Integer>();
    IndexedCollectionFunctionalTest.extractCarIds(deduplicatingResultSet, carIdsReturned);
    // Should return the first distinct Manufacturer...
    Assert.assertEquals(4, deduplicatingResultSet.size());
    Assert.assertEquals(0, deduplicatingResultSet.getRetrievalCost());
    Assert.assertEquals(10, deduplicatingResultSet.getMergeCost());
    Assert.assertEquals(4, carIdsReturned.size());
    Assert.assertEquals(0, carIdsReturned.get(0).intValue());
    Assert.assertEquals(3, carIdsReturned.get(1).intValue());
    Assert.assertEquals(6, carIdsReturned.get(2).intValue());
    Assert.assertEquals(9, carIdsReturned.get(3).intValue());
    Assert.assertTrue(deduplicatingResultSet.contains(CarFactory.createCar(0)));
    Assert.assertTrue(deduplicatingResultSet.contains(CarFactory.createCar(3)));
    Assert.assertTrue(deduplicatingResultSet.contains(CarFactory.createCar(6)));
    Assert.assertTrue(deduplicatingResultSet.contains(CarFactory.createCar(9)));
    Assert.assertFalse(deduplicatingResultSet.contains(CarFactory.createCar(1)));
    deduplicatingResultSet.close(); // No op.
}