nastra commented on code in PR #7759:
URL: https://github.com/apache/iceberg/pull/7759#discussion_r1226826922


##########
core/src/test/java/org/apache/iceberg/view/TestViewMetadata.java:
##########
@@ -0,0 +1,280 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.view;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.types.Types;
+import org.junit.jupiter.api.Test;
+
+public class TestViewMetadata {
+
+  @Test
+  public void nullAndMissingFields() {
+    assertThatThrownBy(() -> ImmutableViewMetadata.builder().build())
+        .isInstanceOf(IllegalStateException.class)
+        .hasMessage(
+            "Cannot build ViewMetadata, some of required attributes are not 
set [formatVersion, location, currentSchemaId, currentVersionId]");
+
+    assertThatThrownBy(() -> 
ImmutableViewMetadata.builder().formatVersion(1).build())
+        .isInstanceOf(IllegalStateException.class)
+        .hasMessage(
+            "Cannot build ViewMetadata, some of required attributes are not 
set [location, currentSchemaId, currentVersionId]");
+
+    assertThatThrownBy(
+            () -> 
ImmutableViewMetadata.builder().formatVersion(1).location("location").build())
+        .isInstanceOf(IllegalStateException.class)
+        .hasMessage(
+            "Cannot build ViewMetadata, some of required attributes are not 
set [currentSchemaId, currentVersionId]");
+
+    assertThatThrownBy(
+            () ->
+                ImmutableViewMetadata.builder()
+                    .formatVersion(1)
+                    .location("location")
+                    .currentSchemaId(1)
+                    .build())
+        .isInstanceOf(IllegalStateException.class)
+        .hasMessage(
+            "Cannot build ViewMetadata, some of required attributes are not 
set [currentVersionId]");
+
+    assertThatThrownBy(
+            () ->
+                ImmutableViewMetadata.builder()
+                    .formatVersion(1)
+                    .location("location")
+                    .currentSchemaId(1)
+                    .currentVersionId(1)
+                    .build())
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Invalid view versions: empty");
+  }
+
+  @Test
+  public void unsupportedFormatVersion() {
+    assertThatThrownBy(
+            () ->
+                ImmutableViewMetadata.builder()
+                    .formatVersion(23)
+                    .location("location")
+                    .currentSchemaId(1)
+                    .currentVersionId(1)
+                    .build())
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Unsupported format version: 23");
+  }
+
+  @Test
+  public void emptyViewVersion() {
+    assertThatThrownBy(
+            () ->
+                ImmutableViewMetadata.builder()
+                    .formatVersion(1)
+                    .location("location")
+                    .currentSchemaId(1)
+                    .currentVersionId(1)
+                    .build())
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Invalid view versions: empty");
+  }
+
+  @Test
+  public void emptySchemas() {
+    assertThatThrownBy(
+            () ->
+                ImmutableViewMetadata.builder()
+                    .formatVersion(1)
+                    .location("location")
+                    .currentSchemaId(1)
+                    .currentVersionId(1)
+                    .addVersions(
+                        ImmutableViewVersion.builder()
+                            .schemaId(1)
+                            .versionId(1)
+                            .timestampMillis(23L)
+                            .putSummary("operation", "op")
+                            .build())
+                    .addHistory(
+                        ImmutableViewHistoryEntry.builder()
+                            .timestampMillis(23L)

Review Comment:
   I've updated the values used for format version, current schema/version id. 
Does it matter if we use `System.currentTimeMillis()` in these tests here? It 
just adds less predictable values (and also we don't care about the current 
timestamp anywhere in the tests)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to