Na jaře
Pomocí MongoTemplate#indexOps(String collection) můžete načíst seznam IndexInfo , představující indexy kolekce MongoDB. Protože se jedná o běžný seznam, můžete svá tvrzení provádět pomocí kombinace hasItem(Matcher<? super T> itemMatcher) a 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"))))));
Pokud se vám to zdá příliš nečitelné nebo nepraktické, možná byste na tom byli lépe s přizpůsobeným Hamcrest matcherem.