snuyanzin commented on code in PR #28110:
URL: https://github.com/apache/flink/pull/28110#discussion_r3183273316


##########
flink-table/flink-table-common/src/test/java/org/apache/flink/table/data/binary/BinaryStringDataFromUtf8BytesTest.java:
##########
@@ -0,0 +1,106 @@
+/*
+ * 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.flink.table.data.binary;
+
+import org.apache.flink.table.data.StringData;
+
+import org.junit.jupiter.api.Test;
+
+import java.nio.charset.StandardCharsets;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/**
+ * Tests for {@link BinaryStringData#fromUtf8Bytes(byte[])} and {@link 
StringData#fromUtf8Bytes}.
+ */
+class BinaryStringDataFromUtf8BytesTest {
+
+    @Test
+    void testFromUtf8Bytes() {
+        // Valid input: ASCII, multi-byte, empty, and the offset/length 
variant all yield the
+        // same instance you would get from the unchecked fromBytes / 
fromString factory.
+        final byte[] hello = "Hello, world!".getBytes(StandardCharsets.UTF_8);
+        assertThat(BinaryStringData.fromUtf8Bytes(hello))
+                .isEqualTo(BinaryStringData.fromBytes(hello));
+
+        final byte[] multibyte = "é€😀".getBytes(StandardCharsets.UTF_8);
+        assertThat(BinaryStringData.fromUtf8Bytes(multibyte))
+                .isEqualTo(BinaryStringData.fromBytes(multibyte));
+
+        assertThat(BinaryStringData.fromUtf8Bytes(new byte[0]))
+                .isEqualTo(BinaryStringData.EMPTY_UTF8);
+
+        // Offset/length variant validates only the inner range.
+        final byte[] padded = {(byte) 0x80, 'O', 'K', (byte) 0x80};
+        assertThat(BinaryStringData.fromUtf8Bytes(padded, 1, 2))
+                .isEqualTo(BinaryStringData.fromString("OK"));
+
+        // null in -> null out so connector authors can forward upstream 
nullability without
+        // an extra guard at every call site.
+        assertThat(BinaryStringData.fromUtf8Bytes((byte[]) null)).isNull();
+        assertThat(BinaryStringData.fromUtf8Bytes(null, 0, 0)).isNull();
+
+        // StringData facade delegates with the same null behavior.
+        assertThat(StringData.fromUtf8Bytes(hello))
+                .isEqualTo(StringData.fromString("Hello, world!"));
+        assertThat(StringData.fromUtf8Bytes((byte[]) null)).isNull();
+        assertThat(StringData.fromUtf8Bytes(null, 0, 0)).isNull();
+    }
+
+    @Test
+    void testFromUtf8BytesRejectsInvalid() {

Review Comment:
   can we parameterize tests here?



-- 
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]

Reply via email to