春に
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"))))));
これが読みにくい、または手に負えない場合は、カスタムのハムクレストマッチャーを使用したほうがよい場合があります。