@Test
public void testGetDistinctKeys() {

    IndexedCollection<Car> cars = createIndexedCollectionOfCars(20); // the 20 cars will contain 10 distinct models
    // Add a sorted index on Car.MODEL (a NavigableIndex)...
    cars.addIndex(NavigableIndex.onAttribute(Car.MODEL));
    MetadataEngine<Car> metadataEngine = cars.getMetadataEngine();
    // Access metadata for Car.MODEL attribute.
    // Because we call getSortedAttributeMetadata(), values will be returned in sorted order...
    SortedAttributeMetadata<String, Car> sortedAttributeMetadata = metadataEngine.getSortedAttributeMetadata(Car.MODEL);
    // Call SortedAttributeMetadata.getDistinctKeys() to retrieve distinct keys in ascending order.
    // We retrieve into a List in order to assert the ordering of values returned...
    assertEquals(
            asList("Accord", "Avensis", "Civic", "Focus", "Fusion", "Hilux", "Insight", "M6", "Prius", "Taurus"),
            sortedAttributeMetadata.getDistinctKeys().collect(toList())
    );
    // Test specifying range explicitly...
    assertEquals(
            asList("Civic", "Focus", "Fusion", "Hilux", "Insight"),
            sortedAttributeMetadata.getDistinctKeys("Civic", true, "Insight", true).collect(toList())
    );
    assertEquals(
            asList("Focus", "Fusion", "Hilux"),
            sortedAttributeMetadata.getDistinctKeys("Civic", false, "Insight", false).collect(toList())
    );
    assertEquals(
            asList("Avensis", "Civic", "Focus", "Fusion", "Hilux", "Insight", "M6", "Prius"),
            sortedAttributeMetadata.getDistinctKeys("Alpha", false, "Tango", false).collect(toList())
    );
}