C0urante commented on code in PR #15379:
URL: https://github.com/apache/kafka/pull/15379#discussion_r1570998105


##########
connect/transforms/src/test/java/org/apache/kafka/connect/transforms/field/FieldPathNotationTest.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * 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.kafka.connect.transforms.field;
+
+import org.apache.kafka.common.config.ConfigException;
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class FieldPathNotationTest {

Review Comment:
   We can simplify these tests with a few utility methods:
   
   ```java
   private void assertParseV1(String path) {
       assertArrayEquals(
               new String[] {path},
               new SingleFieldPath(path, FieldSyntaxVersion.V1).path());
   }
   
   private void assertParseV2(String inputPath, String... expectedSteps) {
       assertArrayEquals(
               expectedSteps,
               new SingleFieldPath(inputPath, FieldSyntaxVersion.V2).path()
       );
   }
   
   private void assertParseV2Error(String inputPath, String expectedMessage) {
       ConfigException exception = assertThrows(
               ConfigException.class,
               () -> new SingleFieldPath(inputPath, FieldSyntaxVersion.V2)
       );
       assertEquals(expectedMessage, exception.getMessage());
   }
   ```
   
   Some simplified test cases would look like this:
   ```java
   @Test
   void shouldBuildV1WithDotsAndBacktickPair() {
       // Given v1
       // When path contains dots, then single step path
       assertParseV1("foo.bar.baz");
       // When path contains backticks, then single step path
       assertParseV1("foo`bar`");
       // When path contains dots and backticks, then single step path
       assertParseV1("foo.`bar.baz`");
   }
   
   @Test
   void shouldBuildV2WhenIncludesDotsAndBacktickPair() {
       // Given v2 and fields including dots
       // When backticks are wrapping a field name (i.e. withing edges or 
between dots)
       // Then build a path with steps separated by dots and not including 
backticks
       assertParseV2("`foo.bar.baz`", "foo.bar.baz");
       assertParseV2("foo.`bar.baz`", "foo", "bar.baz");
       assertParseV2("`foo.bar`.baz", "foo.bar", "baz");
       assertParseV2("foo.`bar`.baz", "foo", "bar", "baz");
   }
   
   @Test
   void shouldFailV2WhenIncompleteBackticks() {
       // Given v2
       // When backticks are not closed and not escaped
       // Then it should fail
       assertParseV2Error(
               "`foo.bar.baz",
               "Incomplete backtick pair in path: [`foo.bar.baz], consider 
adding a backslash before backtick at position 0 to escape it"
       );
   
       assertParseV2Error(
               "foo.`bar.baz",
               "Incomplete backtick pair in path: [foo.`bar.baz], consider 
adding a backslash before backtick at position 4 to escape it"
       );
   
       assertParseV2Error(
               "foo.bar.`baz",
               "Incomplete backtick pair in path: [foo.bar.`baz], consider 
adding a backslash before backtick at position 8 to escape it"
       );
   
       assertParseV2Error(
               "foo.bar.`baz\\`",
               "Incomplete backtick pair in path: [foo.bar.`baz\\`], consider 
adding a backslash before backtick at position 8 to escape it"
       );
   }
   ```



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to