Na primavera
Com
MongoTemplate#indexOps(String collection) você pode buscar uma lista de IndexInfo , representando os índices da coleção MongoDB. Como esta é uma lista regular, você pode fazer suas afirmações com uma combinação de hasItem(Matcher<? super T> itemMatcher) e 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"))))));
Se você achar isso muito ilegível ou inútil, talvez seja melhor usar um matcher Hamcrest personalizado.