TableMetaDataManager { String getCatalogNameFromMetaData(DatabaseMetaData metaData, RegionMapping regionMapping) throws SQLException { String catalogFilter = regionMapping.getCatalog(); if (catalogFilter == null || catalogFilter.isEmpty()) { return DEFAULT_CATALOG; } try (ResultSet catalogs = metaData.getCatalogs()) { return findMatchInResultSet(catalogFilter, catalogs, "TABLE_CAT", "catalog"); } }  TableMetaDataView getTableMetaDataView(Connection connection,
      RegionMapping regionMapping);  }
@Test public void getCatalogNameFromMetaDataGivenNullCatalogReturnsEmptyString() throws SQLException { when(regionMapping.getCatalog()).thenReturn(null); String result = tableMetaDataManager.getCatalogNameFromMetaData(null, regionMapping); assertThat(result).isEqualTo(""); }
@Test public void getCatalogNameFromMetaDataGivenEmptyCatalogReturnsEmptyString() throws SQLException { when(regionMapping.getCatalog()).thenReturn(""); String result = tableMetaDataManager.getCatalogNameFromMetaData(null, regionMapping); assertThat(result).isEqualTo(""); }
@Test public void getCatalogNameFromMetaDataGivenCatalogReturnIt() throws SQLException { String myCatalog = "myCatalog"; when(regionMapping.getCatalog()).thenReturn(myCatalog); ResultSet catalogsResultSet = mock(ResultSet.class); when(catalogsResultSet.next()).thenReturn(true).thenReturn(false); when(catalogsResultSet.getString("TABLE_CAT")).thenReturn(myCatalog); when(databaseMetaData.getCatalogs()).thenReturn(catalogsResultSet); String result = tableMetaDataManager.getCatalogNameFromMetaData(databaseMetaData, regionMapping); assertThat(result).isEqualTo(myCatalog); }