### Question:
Catalogs { @VisibleForTesting static Optional<Catalog> loadCatalog(Configuration conf) { String catalogLoaderClass = conf.get(InputFormatConfig.CATALOG_LOADER_CLASS); if (catalogLoaderClass != null) { CatalogLoader loader = (CatalogLoader) DynConstructors.builder(CatalogLoader.class) .impl(catalogLoaderClass) .build() .newInstance(); Catalog catalog = loader.load(conf); LOG.info("Loaded catalog {} using {}", catalog, catalogLoaderClass); return Optional.of(catalog); } String catalogName = conf.get(InputFormatConfig.CATALOG); if (catalogName != null) { Catalog catalog; switch (catalogName.toLowerCase()) { case HADOOP: String warehouseLocation = conf.get(InputFormatConfig.HADOOP_CATALOG_WAREHOUSE_LOCATION); catalog = (warehouseLocation != null) ? new HadoopCatalog(conf, warehouseLocation) : new HadoopCatalog(conf); LOG.info("Loaded Hadoop catalog {}", catalog); return Optional.of(catalog); case HIVE: catalog = HiveCatalogs.loadCatalog(conf); LOG.info("Loaded Hive Metastore catalog {}", catalog); return Optional.of(catalog); default: throw new NoSuchNamespaceException("Catalog %s is not supported.", catalogName); } } LOG.info("Catalog is not configured"); return Optional.empty(); } private  Catalogs(); static Table loadTable(Configuration conf); static Table loadTable(Configuration conf, Properties props); static Table createTable(Configuration conf, Properties props); static boolean dropTable(Configuration conf, Properties props);  }### Answer:
@Test public void testLoadCatalog() throws IOException { Assert.assertFalse(Catalogs.loadCatalog(conf).isPresent()); conf.set(InputFormatConfig.CATALOG, "foo"); AssertHelpers.assertThrows( "Should complain about catalog not supported", NoSuchNamespaceException.class, "is not supported", () -> Catalogs.loadCatalog(conf)); conf.set(InputFormatConfig.CATALOG, "hadoop"); Optional<Catalog> hadoopCatalog = Catalogs.loadCatalog(conf); Assert.assertTrue(hadoopCatalog.isPresent()); Assert.assertTrue(hadoopCatalog.get() instanceof HadoopCatalog); conf.set(InputFormatConfig.CATALOG, "hive"); Optional<Catalog> hiveCatalog = Catalogs.loadCatalog(conf); Assert.assertTrue(hiveCatalog.isPresent()); Assert.assertTrue(hiveCatalog.get() instanceof HiveCatalog); conf.set("warehouse.location", temp.newFolder("hadoop", "warehouse").toString()); conf.setClass(InputFormatConfig.CATALOG_LOADER_CLASS, CustomHadoopCatalogLoader.class, CatalogLoader.class); Optional<Catalog> customHadoopCatalog = Catalogs.loadCatalog(conf); Assert.assertTrue(customHadoopCatalog.isPresent()); Assert.assertTrue(customHadoopCatalog.get() instanceof CustomHadoopCatalog); }