dan-s1 commented on code in PR #8417:
URL: https://github.com/apache/nifi/pull/8417#discussion_r1492777648


##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEncodeContent.java:
##########
@@ -123,43 +122,275 @@ public void testFailDecodeNotBase32() throws IOException 
{
         testRunner.assertAllFlowFilesTransferred(EncodeContent.REL_FAILURE, 1);
     }
 
-    @Test
-    public void testHexRoundTrip() throws IOException {
-        final TestRunner testRunner = TestRunners.newTestRunner(new 
EncodeContent());
+    @Test void testEncodeDecodeSpecialCharsBase64() {
+        final String specialChars = "!@#$%^&*()_+{}:\"<>?[];',./~`-=";
+        final String expectedOutput = 
"IUAjJCVeJiooKV8re306Ijw+P1tdOycsLi9+YC09" + System.lineSeparator();
 
-        testRunner.setProperty(EncodeContent.MODE, EncodeContent.ENCODE_MODE);
-        testRunner.setProperty(EncodeContent.ENCODING, 
EncodeContent.HEX_ENCODING);
+        executeTestSuccessHelper(EncodingMode.ENCODE, 
EncodingType.BASE64_ENCODING, specialChars, expectedOutput);
+        testRunner.clearTransferState(); // clear the state for the next test
+        executeTestSuccessHelper(EncodingMode.DECODE, 
EncodingType.BASE64_ENCODING, expectedOutput, specialChars);
+    }
 
-        testRunner.enqueue(FILE_PATH);
-        testRunner.clearTransferState();
-        testRunner.run();
+    @Test void testBasicDecodeBase32() {
+        executeTestSuccessHelper(EncodingMode.DECODE, 
EncodingType.BASE32_ENCODING, "NBSWY3DP", "hello");
+    }

Review Comment:
   This test as well as tests on lines 138-140 and 142-144 should be combined 
into a single parameterized test.



##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEncodeContent.java:
##########
@@ -123,43 +122,275 @@ public void testFailDecodeNotBase32() throws IOException 
{
         testRunner.assertAllFlowFilesTransferred(EncodeContent.REL_FAILURE, 1);
     }
 
-    @Test
-    public void testHexRoundTrip() throws IOException {
-        final TestRunner testRunner = TestRunners.newTestRunner(new 
EncodeContent());
+    @Test void testEncodeDecodeSpecialCharsBase64() {
+        final String specialChars = "!@#$%^&*()_+{}:\"<>?[];',./~`-=";
+        final String expectedOutput = 
"IUAjJCVeJiooKV8re306Ijw+P1tdOycsLi9+YC09" + System.lineSeparator();
 
-        testRunner.setProperty(EncodeContent.MODE, EncodeContent.ENCODE_MODE);
-        testRunner.setProperty(EncodeContent.ENCODING, 
EncodeContent.HEX_ENCODING);
+        executeTestSuccessHelper(EncodingMode.ENCODE, 
EncodingType.BASE64_ENCODING, specialChars, expectedOutput);
+        testRunner.clearTransferState(); // clear the state for the next test
+        executeTestSuccessHelper(EncodingMode.DECODE, 
EncodingType.BASE64_ENCODING, expectedOutput, specialChars);
+    }
 
-        testRunner.enqueue(FILE_PATH);
-        testRunner.clearTransferState();
-        testRunner.run();
+    @Test void testBasicDecodeBase32() {
+        executeTestSuccessHelper(EncodingMode.DECODE, 
EncodingType.BASE32_ENCODING, "NBSWY3DP", "hello");
+    }
 
-        testRunner.assertAllFlowFilesTransferred(EncodeContent.REL_SUCCESS, 1);
+    @Test void testBasicDecodeBase64() {
+        executeTestSuccessHelper(EncodingMode.DECODE, 
EncodingType.BASE64_ENCODING, "Zm9v", "foo");
+    }
 
-        MockFlowFile flowFile = 
testRunner.getFlowFilesForRelationship(EncodeContent.REL_SUCCESS).get(0);
-        testRunner.assertQueueEmpty();
+    @Test void testBasicDecodeHex() {
+        executeTestSuccessHelper(EncodingMode.DECODE, 
EncodingType.HEX_ENCODING, "666F6F", "foo");
+    }
 
-        testRunner.setProperty(EncodeContent.MODE, EncodeContent.DECODE_MODE);
-        testRunner.enqueue(flowFile);
-        testRunner.clearTransferState();
-        testRunner.run();
-        testRunner.assertAllFlowFilesTransferred(EncodeContent.REL_SUCCESS, 1);
+    @Test void testBasicEncodeHex0() {
+        executeTestSuccessHelper(EncodingMode.ENCODE, 
EncodingType.HEX_ENCODING, "hello", "68656C6C6F");
+    }
 
-        flowFile = 
testRunner.getFlowFilesForRelationship(EncodeContent.REL_SUCCESS).get(0);
-        flowFile.assertContentEquals(FILE_PATH);
+    @Test void testBasicEncodeHex1() {
+        executeTestSuccessHelper(EncodingMode.ENCODE, 
EncodingType.HEX_ENCODING, "foo", "666F6F");
     }
 
-    @Test
-    public void testFailDecodeNotHex() throws IOException {
-        final TestRunner testRunner = TestRunners.newTestRunner(new 
EncodeContent());
+    @Test void testBasicEncodeBase320() {
+        executeTestSuccessHelper(EncodingMode.ENCODE, 
EncodingType.BASE32_ENCODING, "hello", "NBSWY3DP" + System.lineSeparator());
+    }

Review Comment:
   Instead of this test and the test on line 158-160 use JUnit 5 parameterize 
test
    ```suggestion
       @ParameterizedTest
       @MethodSource("encodeBase32Args")
       void testBasicEncodeBase32(String input, String expectedOutput) {
           executeTestSuccessHelper(EncodingMode.ENCODE, 
EncodingType.BASE32_ENCODING, input, expectedOutput);
       }
       
       private static Stream<Arguments> encodeBase32Args() {
           return Stream.of(
                   Arguments.of("hello", "NBSWY3DP" + System.lineSeparator()),
                   Arguments.of("foo", "MZXW6===" + System.lineSeparator())
           );
       }
   ```
   
   Please remember to remove the test on lines 158-160 and include imports
   ```
   import java.util.stream.Stream;
   import org.junit.jupiter.params.ParameterizedTest;
   import org.junit.jupiter.params.provider.Arguments;
   import org.junit.jupiter.params.provider.MethodSource;
   ```
   



##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEncodeContent.java:
##########
@@ -123,43 +122,275 @@ public void testFailDecodeNotBase32() throws IOException 
{
         testRunner.assertAllFlowFilesTransferred(EncodeContent.REL_FAILURE, 1);
     }
 
-    @Test
-    public void testHexRoundTrip() throws IOException {
-        final TestRunner testRunner = TestRunners.newTestRunner(new 
EncodeContent());
+    @Test void testEncodeDecodeSpecialCharsBase64() {
+        final String specialChars = "!@#$%^&*()_+{}:\"<>?[];',./~`-=";
+        final String expectedOutput = 
"IUAjJCVeJiooKV8re306Ijw+P1tdOycsLi9+YC09" + System.lineSeparator();
 
-        testRunner.setProperty(EncodeContent.MODE, EncodeContent.ENCODE_MODE);
-        testRunner.setProperty(EncodeContent.ENCODING, 
EncodeContent.HEX_ENCODING);
+        executeTestSuccessHelper(EncodingMode.ENCODE, 
EncodingType.BASE64_ENCODING, specialChars, expectedOutput);
+        testRunner.clearTransferState(); // clear the state for the next test
+        executeTestSuccessHelper(EncodingMode.DECODE, 
EncodingType.BASE64_ENCODING, expectedOutput, specialChars);
+    }
 
-        testRunner.enqueue(FILE_PATH);
-        testRunner.clearTransferState();
-        testRunner.run();
+    @Test void testBasicDecodeBase32() {
+        executeTestSuccessHelper(EncodingMode.DECODE, 
EncodingType.BASE32_ENCODING, "NBSWY3DP", "hello");
+    }
 
-        testRunner.assertAllFlowFilesTransferred(EncodeContent.REL_SUCCESS, 1);
+    @Test void testBasicDecodeBase64() {
+        executeTestSuccessHelper(EncodingMode.DECODE, 
EncodingType.BASE64_ENCODING, "Zm9v", "foo");
+    }
 
-        MockFlowFile flowFile = 
testRunner.getFlowFilesForRelationship(EncodeContent.REL_SUCCESS).get(0);
-        testRunner.assertQueueEmpty();
+    @Test void testBasicDecodeHex() {
+        executeTestSuccessHelper(EncodingMode.DECODE, 
EncodingType.HEX_ENCODING, "666F6F", "foo");
+    }
 
-        testRunner.setProperty(EncodeContent.MODE, EncodeContent.DECODE_MODE);
-        testRunner.enqueue(flowFile);
-        testRunner.clearTransferState();
-        testRunner.run();
-        testRunner.assertAllFlowFilesTransferred(EncodeContent.REL_SUCCESS, 1);
+    @Test void testBasicEncodeHex0() {
+        executeTestSuccessHelper(EncodingMode.ENCODE, 
EncodingType.HEX_ENCODING, "hello", "68656C6C6F");
+    }

Review Comment:
   Replace this test and the test on lines 150-151 with a single parameterized 
test as was demonstrated.



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