@Test
public void testGetFrequencyDistribution() {

    IndexedCollection<Car> cars = createIndexedCollectionOfCars(20);
    // Add an unsorted index on Car.MANUFACTURER (a HashIndex)...
    cars.addIndex(HashIndex.onAttribute(Car.MANUFACTURER));
    MetadataEngine<Car> metadataEngine = cars.getMetadataEngine();
    // Access metadata for Car.MANUFACTURER attribute.
    // Because we call getAttributeMetadata() (and not getSortedAttributeMetadata()),
    // values will be returned in no particular order...
    AttributeMetadata<String, Car> sortedAttributeMetadata = metadataEngine.getAttributeMetadata(Car.MANUFACTURER);
    // Call AttributeMetadata.getFrequencyDistribution() to retrieve distinct keys and counts in no particular order.
    // We retrieve into a Set (not a List), to assert the expected values were returned, without asserting any order...
    assertEquals(
            asSet(frequency("Ford", 6), frequency("BMW", 2), frequency("Toyota", 6), frequency("Honda", 6)),
            sortedAttributeMetadata.getFrequencyDistribution().collect(toSet())
    );
}