IndexFactory { public static Index newInstanceWithCustomKeys(final String name, final List<IndexKey> keys, final boolean unique) { final BsonDocument keysDocument = createKeysDocument(requireNonNull(keys)); return Index.of(keysDocument, name, unique, unique, BACKGROUND_OPTION_DEFAULT); } private  IndexFactory(); static Index newInstance(final String name, final List<String> fields, final boolean unique); static Index newInstanceWithCustomKeys(final String name, final List<IndexKey> keys, final boolean unique); static Index newExpirationIndex(final String name, final String field, final long expireAfterSeconds);  }
@Test public void newInstanceWithCustomKeys() { final IndexKey key1 = DefaultIndexKey.of(FIELD_1_NAME, IndexDirection.ASCENDING); final IndexKey key2 = DefaultIndexKey.of(FIELD_2_NAME, IndexDirection.DESCENDING); final List<IndexKey> keys = Arrays.asList(key1, key2); final Index actual = IndexFactory.newInstanceWithCustomKeys(INDEX_NAME, keys, UNIQUE); final BsonDocument expectedKeys = new BsonDocument(); expectedKeys.put(FIELD_1_NAME, IndexDirection.ASCENDING.getBsonInt()); expectedKeys.put(FIELD_2_NAME, IndexDirection.DESCENDING.getBsonInt()); final Index expected = Index.of(expectedKeys, INDEX_NAME, UNIQUE, UNIQUE, BACKGROUND); assertThat(actual).isEqualTo(expected); }