@Test
public void testGetDistinctKeysDescending() {

    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.getDistinctKeysDescending() to retrieve distinct keys in descending order.
    // We retrieve into a List in order to assert the ordering of values returned...
    assertEquals(
            asList("Taurus", "Prius", "M6", "Insight", "Hilux", "Fusion", "Focus", "Civic", "Avensis", "Accord"),
            sortedAttributeMetadata.getDistinctKeysDescending().collect(toList())
    );
    // Test specifying range explicitly...
    assertEquals(
            asList("Hilux", "Fusion", "Focus"),
            sortedAttributeMetadata.getDistinctKeysDescending("Civic", false, "Insight", false).collect(toList())
    );
    assertEquals(
            asList("Prius", "M6", "Insight", "Hilux", "Fusion", "Focus", "Civic", "Avensis"),
            sortedAttributeMetadata.getDistinctKeysDescending("Alpha", false, "Tango", false).collect(toList())
    );
}