MongoMetadataEngine extends CommonsMetadataEngine<MongoClient> { @Override protected List<CatalogMetadata> provideMetadata(ClusterName clusterName, Connection<MongoClient> connection) throws ConnectorException { List<String> databaseNames = connection.getNativeConnection().getDatabaseNames(); List<CatalogMetadata> catalogMetadataList = new ArrayList<>(); for (String databaseName : databaseNames) { CatalogName dbName = new CatalogName(databaseName); catalogMetadataList.add(provideCatalogMetadata(dbName, clusterName, connection)); } return catalogMetadataList; } private  MongoMetadataEngine(MongoConnectionHandler connectionHandler); static MongoMetadataEngine getInstance(MongoConnectionHandler connectionHandler);  }
@Test public void provideMetadataTest() throws ConnectorException { ClusterName clusterName = new ClusterName(CLUSTER_NAME); MongoMetadataEngine spyMetadataEngine = PowerMockito.spy(MongoMetadataEngine.getInstance(connectionHandler)); CatalogMetadata catalogMetadata1 = mock(CatalogMetadata.class); CatalogMetadata catalogMetadata2 = mock(CatalogMetadata.class); when(client.getDatabaseNames()).thenReturn(Arrays.asList(DB_NAME, DB_NAME_SEC)); PowerMockito.doReturn(catalogMetadata1) .doReturn(catalogMetadata2) .when(spyMetadataEngine) .provideCatalogMetadata(Matchers.any(CatalogName.class), Matchers.eq(clusterName), Matchers.eq(connection)); List<CatalogMetadata> providedMetadata = spyMetadataEngine.provideMetadata(clusterName, connection); Assert.assertEquals(providedMetadata.size(), 2); Assert.assertEquals(providedMetadata.get(0), catalogMetadata1); Assert.assertEquals(providedMetadata.get(1), catalogMetadata2); }