MongoMetadataEngine extends CommonsMetadataEngine<MongoClient> { @Override protected void dropIndex(IndexMetadata indexMetadata, Connection<MongoClient> connection) throws ExecutionException { DB db = connection.getNativeConnection().getDB( indexMetadata.getName().getTableName().getCatalogName().getName()); String indexName = null; if (indexMetadata.getName() != null) { indexName = indexMetadata.getName().getName(); } if (indexName != null) { try { db.getCollection(indexMetadata.getName().getTableName().getName()).dropIndex(indexName); } catch (MongoException e) { logger.error("Error dropping the index: " + e.getMessage()); throw new ExecutionException(e.getMessage(), e); } } else { IndexUtils.dropIndexWithDefaultName(indexMetadata, db); } } private  MongoMetadataEngine(MongoConnectionHandler connectionHandler); static MongoMetadataEngine getInstance(MongoConnectionHandler connectionHandler);  }
@Test public void dropIndexTest() throws ExecutionException, UnsupportedException { IndexMetadataBuilder indexMetadataBuilder = new IndexMetadataBuilder(DB_NAME, TABLE_NAME, INDEX_NAME, IndexType.DEFAULT); indexMetadataBuilder.addColumn(COLUMN_NAME, new ColumnType(DataType.VARCHAR)); indexMetadataBuilder.addColumn(COLUMN_NAME2, new ColumnType(DataType.INT)); IndexMetadata indexMetadata = indexMetadataBuilder.build(); DBCollection collection = mock(DBCollection.class); when(client.getDB(DB_NAME)).thenReturn(database); when(database.getCollection(TABLE_NAME)).thenReturn(collection); PowerMockito.mockStatic(IndexUtils.class); mongoMetadataEngine.dropIndex(indexMetadata, connection); PowerMockito.verifyStatic(Mockito.never()); IndexUtils.dropIndexWithDefaultName(indexMetadata, database); verify(client, times(1)).getDB(DB_NAME); verify(collection, times(1)).dropIndex(INDEX_NAME); }