tpalfy commented on code in PR #6769:
URL: https://github.com/apache/nifi/pull/6769#discussion_r1159894693


##########
nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/preprocess/AsnPreprocessorEngineTest.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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.nifi.jasn1.preprocess;
+
+import org.apache.nifi.logging.ComponentLog;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+import java.util.StringJoiner;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class AsnPreprocessorEngineTest {
+    private AsnPreprocessorEngine testSubject;
+    private AsnPreprocessorEngine helper;
+
+    private AsnPreprocessor mockPreprocessor1;
+    private AsnPreprocessor mockPreprocessor2;
+    private List<AsnPreprocessor> preprocessors;
+
+    private ComponentLog log;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        mockPreprocessor1 = mock(AsnPreprocessor.class);
+        mockPreprocessor2 = mock(AsnPreprocessor.class);
+
+        preprocessors = Arrays.asList(
+                mockPreprocessor1,
+                mockPreprocessor2
+        );
+
+        log = mock(ComponentLog.class);
+
+        helper = mock(AsnPreprocessorEngine.class);
+        testSubject = new AsnPreprocessorEngine() {
+            @Override
+            List<String> readAsnLines(ComponentLog componentLog, String 
inputFile, Path inputFilePath) {
+                return helper.readAsnLines(componentLog, inputFile, 
inputFilePath);
+            }
+
+            @Override
+            void writePreprocessedAsn(ComponentLog componentLog, String 
preprocessedAsn, Path preprocessedAsnPath) {
+                helper.writePreprocessedAsn(componentLog, preprocessedAsn, 
preprocessedAsnPath);
+            }
+
+            @Override
+            List<AsnPreprocessor> getPreprocessors() {
+                return preprocessors;
+            }
+        };
+
+        Files.createDirectories(Path.of("target/" + 
this.getClass().getSimpleName()));
+    }
+
+    @AfterEach
+    void tearDown() throws Exception {
+        Files.walk(Path.of("target/" + this.getClass().getSimpleName()))
+                .sorted(Comparator.reverseOrder())
+                .map(Path::toFile)
+                .forEach(File::delete);
+    }
+
+    @Test
+    void testPreprocess() {
+        // GIVEN
+        Path asnFile1Path = Paths.get("path", "to", "asn_file_1");
+        Path asnFile2Path = Paths.get("path", "to", "asn_file_2");
+
+        String asnFilesString = new StringJoiner(",")
+                .add(asnFile1Path.toString())
+                .add(asnFile2Path.toString())
+                .toString();
+
+        String outputDirectory = Paths.get("path", "to", 
"directory_for_transformed_asn_files").toString();
+
+        List<String> originalLines1 = Arrays.asList("original_lines_1_1", 
"original_lines_1_2");
+        List<String> preprocessedLines1_1 = 
Arrays.asList("preprocessed_lines_1_1_1", "preprocessed_lines_1_1_2");
+        List<String> preprocessedLines1_2 = Arrays.asList("final_lines_1_1", 
"final_lines_1_2");
+
+        List<String> originalLines2 = Arrays.asList("original_lines_2_1", 
"original_lines_2_2");
+        List<String> preprocessedLines2_1 = 
Arrays.asList("preprocessed_lines_2_1_1", "preprocessed_lines_2_1_2");
+        List<String> preprocessedLines2_2 = Arrays.asList("final_lines_2_1", 
"final_lines_2_2");
+
+        when(helper.readAsnLines(eq(log), eq(asnFile1Path.toString()), 
eq(asnFile1Path)))
+                .thenReturn(originalLines1);
+        
when(mockPreprocessor1.preprocessAsn(originalLines1)).thenReturn(preprocessedLines1_1);
+        
when(mockPreprocessor2.preprocessAsn(preprocessedLines1_1)).thenReturn(preprocessedLines1_2);
+
+        when(helper.readAsnLines(eq(log), eq(asnFile2Path.toString()), 
eq(asnFile2Path)))
+                .thenReturn(originalLines2);
+        
when(mockPreprocessor1.preprocessAsn(originalLines2)).thenReturn(preprocessedLines2_1);
+        
when(mockPreprocessor2.preprocessAsn(preprocessedLines2_1)).thenReturn(preprocessedLines2_2);
+
+        String expected = new StringJoiner(",")
+                .add(Paths.get("path", "to", 
"directory_for_transformed_asn_files", "asn_file_1").toString())
+                .add(Paths.get("path", "to", 
"directory_for_transformed_asn_files", "asn_file_2").toString())
+                .toString();
+
+        // WHEN

Review Comment:
   I think we have discussed this earlier and agreed that it's not a strict 
policy, we can leave them there.
   
   It has basically zero disadvantage and significant advantage to some. Tests 
inherently do at least 3 different things:  prepare a scenario, execute 
production code and then check the results. It's not practical to extract 
these, hence these fairly standard comments.
   
   I think it's good to remember: we cannot predict, let alone guarantee how 
people are trying to read the code. It's up to the reader to decide. And they 
can decide that they want to start at the WHERE section. I myself am falling 
into to this category. Stripping them off of the help that make this easier for 
them (for no practical benefit in return) is not fair in my opinion.



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