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()"
This commit is contained in:
Chen 2020-03-25 09:04:14 +08:00 committed by GitHub
parent 72edc56862
commit 5591444148
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 10 deletions

View File

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

View File

@ -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());

View File

@ -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
1 a,b,c,e,f
2 # Very Long
3 # Comment 2
4 g,h,i,j,k
5 # Very Long
6 # Comment 3
7 l,m,n,o,p

View File

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