@Test
public void testGetKeysAndValues() {

    IndexedCollection<Car> cars = new ConcurrentIndexedCollection<>();
    Car car1 = new Car(1, "Ford", "Taurus", Car.Color.GREEN, 4, 1000.0, emptyList(), Collections.emptyList());
    Car car2 = new Car(2, "Toyota", "Prius", Car.Color.BLUE, 4, 2000.0, emptyList(), Collections.emptyList());
    Car car3 = new Car(3, "Honda", "Civic", Car.Color.BLUE, 4, 2000.0, emptyList(), Collections.emptyList());
    cars.addAll(asList(car1, car2, car3));
    // 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.
    SortedAttributeMetadata<String, Car> attributeMetadata = metadataEngine.getSortedAttributeMetadata(Car.MANUFACTURER);
    // Call SortedAttributeMetadata.getKeysAndValues() to retrieve keys and values in ascending order.
    // We retrieve into a List in order to assert the ordering of values returned...
    assertEquals(
            asList(keyValue("Ford", car1), keyValue("Honda", car3), keyValue("Toyota", car2)),
            attributeMetadata.getKeysAndValues().collect(toList())
    );
    // Test specifying range explicitly...
    assertEquals(
            asList(keyValue("Ford", car1), keyValue("Honda", car3)),
            attributeMetadata.getKeysAndValues("Alpha", true, "Toyota", false).collect(toList())
    );
}