MetadataEngine { public <A extends Comparable<A>> SortedAttributeMetadata<A, O> getSortedAttributeMetadata(Attribute<O, A> attribute) { @SuppressWarnings("unchecked") SortedKeyStatisticsIndex<A, O> index = getIndexOnAttribute(SortedKeyStatisticsAttributeIndex.class, attribute); return new SortedAttributeMetadata<>(index, openResourcesHandler, closeResourcesHandler); } MetadataEngine(IndexedCollection<O> indexedCollection, Supplier<QueryOptions> openResourcesHandler, Consumer<QueryOptions> closeResourcesHandler); AttributeMetadata<A, O> getAttributeMetadata(Attribute<O, A> attribute); SortedAttributeMetadata<A, O> getSortedAttributeMetadata(Attribute<O, A> attribute);  }
@Test public void testAttemptToAccessMetadataWithoutSortedIndex() { IndexedCollection<Car> cars = createIndexedCollectionOfCars(5); @SuppressWarnings("unchecked") Attribute<Car, Integer> ATTRIBUTE = Mockito.mock(SimpleAttribute.class); Mockito.when(ATTRIBUTE.toString()).thenReturn("ATTRIBUTE"); IllegalStateException expected = null; try { cars.getMetadataEngine().getSortedAttributeMetadata(ATTRIBUTE); } catch (IllegalStateException e) { expected = e; } assertNotNull(expected); assertEquals("A SortedKeyStatisticsAttributeIndex has not been added to the collection, and must be added first, to enable metadata to be examined for attribute: ATTRIBUTE", expected.getMessage()); }