През пролетта
С MongoTemplate#indexOps(String collection) можете да извлечете списък с IndexInfo , представляващи индексите на колекцията MongoDB. Тъй като това е обикновен списък, можете да правите вашите твърдения с комбинация от hasItem(Matcher<? super T> itemMatcher) и hasProperty(String propertyName, Matcher<?> valueMatcher) :
final List<IndexInfo> indexes = mongoTemplate.indexOps("myCollection").getIndexInfo();
assertThat(indexes, hasSize(3));
assertThat(indexes, hasItem(hasProperty("name", is("_id_"))));
assertThat(indexes, hasItem(hasProperty("name", is("index1"))));
assertThat(indexes, hasItem(hasProperty("name", is("index2"))));
assertThat(indexes, hasItem(hasProperty("indexFields", hasItem(hasProperty("key", is("field1"))))));
Ако смятате, че това е твърде нечетливо или неудобно, може да е по-добре с персонализиран съпоставител на Hamcrest.