Wiosną
Z MongoTemplate#indexOps(String collection) możesz pobrać listę IndexInfo , reprezentujący indeksy kolekcji MongoDB. Ponieważ jest to zwykła lista, możesz wykonać swoje asercje za pomocą kombinacji hasItem(Matcher<? super T> itemMatcher) i 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"))))));
Jeśli uznasz to za zbyt nieczytelne lub nieprzydatne, może być lepiej, jeśli skorzystasz z niestandardowego dopasowywania Hamcrest.