You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/03/25 01:04:21 UTC

[commons-csv] branch master updated: Fix the old test case record.getComment() will never be null (#62)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-csv.git


The following commit(s) were added to refs/heads/master by this push:
     new 5591444  Fix the old test case record.getComment() will never be null (#62)
5591444 is described below

commit 5591444148679d77107f108d0a40ac044076ba0d
Author: Chen <50...@users.noreply.github.com>
AuthorDate: Wed Mar 25 09:04:14 2020 +0800

    Fix the old test case record.getComment() will never be null (#62)
    
    * The old test case record.getComment() will never be null and if record.getComment() be null the test code misplace the null test.
    Add a new test file that record.getComment() will be null and test record.getComment() no null before using
    
    * keep the caching of "record.getComment()"
---
 pom.xml                                                  |  4 ++++
 .../java/org/apache/commons/csv/CSVFileParserTest.java   | 16 ++++++----------
 src/test/resources/CSVFileParser/testCSV246.csv          |  8 ++++++++
 .../CSVFileParser/testCSV246_checkWithNoComment.txt      | 10 ++++++++++
 4 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/pom.xml b/pom.xml
index 0b37e30..5788fb3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -257,6 +257,8 @@
             <exclude>src/test/resources/ferc.gov/transaction.txt</exclude>
             <exclude>src/test/resources/**/*.bin</exclude>
             <exclude>src/test/resources/CSV-259/sample.txt</exclude>
+            <exclude>src/test/resources/CSVFileParser/testCSV246.csv</exclude>
+            <exclude>src/test/resources/CSVFileParser/testCSV246_checkWithNoComment.txt</exclude>
           </excludes>
         </configuration>
       </plugin>
@@ -375,6 +377,8 @@
             <exclude>src/test/resources/ferc.gov/transaction.txt</exclude>
             <exclude>src/test/resources/**/*.bin</exclude>
             <exclude>src/test/resources/CSV-259/sample.txt</exclude>
+            <exclude>src/test/resources/CSVFileParser/testCSV246.csv</exclude>
+            <exclude>src/test/resources/CSVFileParser/testCSV246_checkWithNoComment.txt</exclude>
           </excludes>
         </configuration>
       </plugin>
diff --git a/src/test/java/org/apache/commons/csv/CSVFileParserTest.java b/src/test/java/org/apache/commons/csv/CSVFileParserTest.java
index 8e274f9..413ef61 100644
--- a/src/test/java/org/apache/commons/csv/CSVFileParserTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVFileParserTest.java
@@ -93,11 +93,9 @@ public class CSVFileParserTest {
             try (final CSVParser parser = CSVParser.parse(new File(BASE, split[0]), Charset.defaultCharset(), format)) {
                 for (final CSVRecord record : parser) {
                     String parsed = Arrays.toString(record.values());
-                    if (checkComments) {
-                        final String comment = record.getComment().replace("\n", "\\n");
-                        if (comment != null) {
-                            parsed += "#" + comment;
-                        }
+                    String comment = record.getComment();
+                    if (checkComments && comment != null) {
+                        parsed += "#" + comment.replace("\n", "\\n");
                     }
                     final int count = record.size();
                     assertEquals(readTestData(testData), count + ":" + parsed, testFile.getName());
@@ -140,11 +138,9 @@ public class CSVFileParserTest {
             try (final CSVParser parser = CSVParser.parse(resource, Charset.forName("UTF-8"), format)) {
                 for (final CSVRecord record : parser) {
                     String parsed = Arrays.toString(record.values());
-                    if (checkComments) {
-                        final String comment = record.getComment().replace("\n", "\\n");
-                        if (comment != null) {
-                            parsed += "#" + comment;
-                        }
+                    String comment = record.getComment();
+                    if (checkComments && comment != null) {
+                        parsed += "#" + comment.replace("\n", "\\n");
                     }
                     final int count = record.size();
                     assertEquals(readTestData(testData), count + ":" + parsed, testFile.getName());
diff --git a/src/test/resources/CSVFileParser/testCSV246.csv b/src/test/resources/CSVFileParser/testCSV246.csv
new file mode 100644
index 0000000..f01a214
--- /dev/null
+++ b/src/test/resources/CSVFileParser/testCSV246.csv
@@ -0,0 +1,8 @@
+a,b,c,e,f
+# Very Long
+# Comment 2
+g,h,i,j,k
+# Very Long
+
+# Comment 3
+l,m,n,o,p
\ No newline at end of file
diff --git a/src/test/resources/CSVFileParser/testCSV246_checkWithNoComment.txt b/src/test/resources/CSVFileParser/testCSV246_checkWithNoComment.txt
new file mode 100644
index 0000000..cb7d21f
--- /dev/null
+++ b/src/test/resources/CSVFileParser/testCSV246_checkWithNoComment.txt
@@ -0,0 +1,10 @@
+testCSV246.csv CommentStart=# CheckComments
+Delimiter=<,> QuoteChar=<"> CommentStart=<#> SkipHeaderRecord:false
+5:[a, b, c, e, f]
+# Very Long
+# Comment 2
+5:[g, h, i, j, k]#Very Long\nComment 2
+# Very Long
+1:[]#Very Long
+# Comment 3
+5:[l, m, n, o, p]#Comment 3
\ No newline at end of file