From a51761bb201c588a872de36b787c4824a31b5831 Mon Sep 17 00:00:00 2001 From: Eduard Tudenhoefner Date: Wed, 18 Oct 2023 12:25:46 +0200 Subject: [PATCH] improve error checks --- .../apache/iceberg/view/ViewCatalogTests.java | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java b/core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java index 1c0900111ec3..4ec449b8fc1d 100644 --- a/core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java +++ b/core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java @@ -36,7 +36,6 @@ import org.apache.iceberg.exceptions.NoSuchTableException; import org.apache.iceberg.exceptions.NoSuchViewException; import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; -import org.apache.iceberg.rest.RESTCatalog; import org.apache.iceberg.types.Types; import org.assertj.core.api.Assumptions; import org.junit.jupiter.api.Test; @@ -1284,14 +1283,16 @@ public void updateViewPropertiesConflict() { catalog().dropView(identifier); assertThat(catalog().viewExists(identifier)).as("View should not exist").isFalse(); - String expectedMessage = - catalog() instanceof RESTCatalog ? "View does not exist: ns.view" : "Cannot commit"; - Class expectedException = - catalog() instanceof RESTCatalog ? NoSuchViewException.class : CommitFailedException.class; - assertThatThrownBy(() -> updateViewProperties.set("key1", "val1").commit()) - .isInstanceOf(expectedException) - .hasMessageContaining(expectedMessage); + .satisfiesAnyOf( + x -> + assertThat(x) + .isInstanceOf(NoSuchViewException.class) + .hasMessageContaining("View does not exist: ns.view"), + x -> + assertThat(x) + .isInstanceOf(CommitFailedException.class) + .hasMessageContaining("Cannot commit")); } @Test @@ -1319,11 +1320,6 @@ public void replaceViewVersionConflict() { catalog().dropView(identifier); assertThat(catalog().viewExists(identifier)).as("View should not exist").isFalse(); - String expectedMessage = - catalog() instanceof RESTCatalog ? "View does not exist: ns.view" : "Cannot commit"; - Class expectedException = - catalog() instanceof RESTCatalog ? NoSuchViewException.class : CommitFailedException.class; - assertThatThrownBy( () -> replaceViewVersion @@ -1331,8 +1327,15 @@ public void replaceViewVersionConflict() { .withSchema(SCHEMA) .withDefaultNamespace(identifier.namespace()) .commit()) - .isInstanceOf(expectedException) - .hasMessageContaining(expectedMessage); + .satisfiesAnyOf( + x -> + assertThat(x) + .isInstanceOf(NoSuchViewException.class) + .hasMessageContaining("View does not exist: ns.view"), + x -> + assertThat(x) + .isInstanceOf(CommitFailedException.class) + .hasMessageContaining("Cannot commit")); } @Test @@ -1522,14 +1525,16 @@ public void updateViewLocationConflict() { catalog().dropView(identifier); assertThat(catalog().viewExists(identifier)).as("View should not exist").isFalse(); - String expectedMessage = - catalog() instanceof RESTCatalog ? "View does not exist: ns.view" : "Cannot commit"; - Class expectedException = - catalog() instanceof RESTCatalog ? NoSuchViewException.class : CommitFailedException.class; - // the view was already dropped concurrently assertThatThrownBy(() -> updateViewLocation.setLocation("new-location").commit()) - .isInstanceOf(expectedException) - .hasMessageContaining(expectedMessage); + .satisfiesAnyOf( + x -> + assertThat(x) + .isInstanceOf(NoSuchViewException.class) + .hasMessageContaining("View does not exist: ns.view"), + x -> + assertThat(x) + .isInstanceOf(CommitFailedException.class) + .hasMessageContaining("Cannot commit")); } }