public static Catalog loadIcebergCatalog(SparkSession spark, String catalogName) {
    CatalogPlugin catalogPlugin = spark.sessionState().catalogManager().catalog(catalogName);
    Preconditions.checkArgument(
        catalogPlugin instanceof HasIcebergCatalog,
        String.format(
            "Cannot load Iceberg catalog from catalog %s because it does not contain an Iceberg Catalog. "
                + "Actual Class: %s",
            catalogName, catalogPlugin.getClass().getName()));
    return ((HasIcebergCatalog) catalogPlugin).icebergCatalog();
  }
@Test
  public void testLoadIcebergCatalog() throws Exception {
    spark.conf().set("spark.sql.catalog.test_cat", SparkCatalog.class.getName());
    spark.conf().set("spark.sql.catalog.test_cat.type", "hive");
    Catalog catalog = Spark3Util.loadIcebergCatalog(spark, "test_cat");
    assertThat(catalog)
        .as("Should retrieve underlying catalog class")
        .isInstanceOf(CachingCatalog.class);
  }