@Test
public void testGetFrequencyDistributionDescending() {

    IndexedCollection<Car> cars = createIndexedCollectionOfCars(20);
    // Add a sorted index on Car.MANUFACTURER (a NavigableIndex)...
    cars.addIndex(NavigableIndex.onAttribute(Car.MANUFACTURER));
    MetadataEngine<Car> metadataEngine = cars.getMetadataEngine();
    // Access metadata for Car.MANUFACTURER attribute.
    // Because we call getSortedAttributeMetadata() values will be returned in ascending order...
    SortedAttributeMetadata<String, Car> sortedAttributeMetadata = metadataEngine.getSortedAttributeMetadata(Car.MANUFACTURER);
    // Call AttributeMetadata.getFrequencyDistribution() to retrieve distinct keys and counts in ascending order.
    // We retrieve into a List in order to assert the ordering of values returned...
    assertEquals(
            asList(frequency("Toyota", 6), frequency("Honda", 6), frequency("Ford", 6), frequency("BMW", 2)),
            sortedAttributeMetadata.getFrequencyDistributionDescending().collect(toList())
    );
}