Skip to content

Commit 9ab47dc

Browse files
committed
Move tests for specific issues to own package
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1742173 13f79535-47bb-0310-9956-ffa450edef68
1 parent 20eac69 commit 9ab47dc

3 files changed

Lines changed: 123 additions & 106 deletions

File tree

src/test/java/org/apache/commons/csv/CSVFormatTest.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -383,32 +383,6 @@ public void testWithEmptyEnum() throws Exception {
383383
Assert.assertTrue(formatWithHeader.getHeader().length == 0);
384384
}
385385

386-
@Test
387-
public void testJiraCsv154_withCommentMarker() throws IOException {
388-
final String comment = "This is a header comment";
389-
final CSVFormat format = CSVFormat.EXCEL.withHeader("H1", "H2").withCommentMarker('#').withHeaderComments(comment);
390-
final StringBuilder out = new StringBuilder();
391-
final CSVPrinter printer = format.print(out);
392-
printer.print("A");
393-
printer.print("B");
394-
printer.close();
395-
final String s = out.toString();
396-
Assert.assertTrue(s, s.contains(comment));
397-
}
398-
399-
@Test
400-
public void testJiraCsv154_withHeaderComments() throws IOException {
401-
final String comment = "This is a header comment";
402-
final CSVFormat format = CSVFormat.EXCEL.withHeader("H1", "H2").withHeaderComments(comment).withCommentMarker('#');
403-
final StringBuilder out = new StringBuilder();
404-
final CSVPrinter printer = format.print(out);
405-
printer.print("A");
406-
printer.print("B");
407-
printer.close();
408-
final String s = out.toString();
409-
Assert.assertTrue(s, s.contains(comment));
410-
}
411-
412386
@Test
413387
public void testWithIgnoreEmptyLines() throws Exception {
414388
assertFalse(CSVFormat.DEFAULT.withIgnoreEmptyLines(false).getIgnoreEmptyLines());
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.apache.commons.csv.bugs;
2+
3+
import static org.junit.Assert.assertTrue;
4+
5+
import java.io.IOException;
6+
7+
import org.apache.commons.csv.CSVFormat;
8+
import org.apache.commons.csv.CSVPrinter;
9+
import org.junit.Test;
10+
11+
public class JiraCsv164Test {
12+
13+
@Test
14+
public void testJiraCsv154_withCommentMarker() throws IOException {
15+
final String comment = "This is a header comment";
16+
final CSVFormat format = CSVFormat.EXCEL.withHeader("H1", "H2").withCommentMarker('#').withHeaderComments(comment);
17+
final StringBuilder out = new StringBuilder();
18+
final CSVPrinter printer = format.print(out);
19+
printer.print("A");
20+
printer.print("B");
21+
printer.close();
22+
final String s = out.toString();
23+
assertTrue(s, s.contains(comment));
24+
}
25+
26+
@Test
27+
public void testJiraCsv154_withHeaderComments() throws IOException {
28+
final String comment = "This is a header comment";
29+
final CSVFormat format = CSVFormat.EXCEL.withHeader("H1", "H2").withHeaderComments(comment).withCommentMarker('#');
30+
final StringBuilder out = new StringBuilder();
31+
final CSVPrinter printer = format.print(out);
32+
printer.print("A");
33+
printer.print("B");
34+
printer.close();
35+
final String s = out.toString();
36+
assertTrue(s, s.contains(comment));
37+
}
38+
39+
}

src/test/java/org/apache/commons/csv/JiraCsv167Test.java renamed to src/test/java/org/apache/commons/csv/bugs/JiraCsv167Test.java

Lines changed: 84 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,84 @@
1-
/*
2-
* Licensed to the Apache Software Foundation (ASF) under one or more
3-
* contributor license agreements. See the NOTICE file distributed with
4-
* this work for additional information regarding copyright ownership.
5-
* The ASF licenses this file to You under the Apache License, Version 2.0
6-
* (the "License"); you may not use this file except in compliance with
7-
* the License. You may obtain a copy of the License at
8-
*
9-
* http://www.apache.org/licenses/LICENSE-2.0
10-
*
11-
* Unless required by applicable law or agreed to in writing, software
12-
* distributed under the License is distributed on an "AS IS" BASIS,
13-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
* See the License for the specific language governing permissions and
15-
* limitations under the License.
16-
*/
17-
package org.apache.commons.csv;
18-
19-
import java.io.BufferedReader;
20-
import java.io.File;
21-
import java.io.FileReader;
22-
import java.io.IOException;
23-
import java.nio.charset.Charset;
24-
25-
import org.junit.Assert;
26-
import org.junit.Test;
27-
28-
public class JiraCsv167Test {
29-
30-
@Test
31-
public void parse() throws IOException {
32-
final File csvData = new File("src/test/resources/csv-167/sample1.csv");
33-
final BufferedReader br = new BufferedReader(new FileReader(csvData));
34-
String s = null;
35-
int totcomment = 0;
36-
int totrecs = 0;
37-
boolean lastWasComment = false;
38-
while((s=br.readLine()) != null) {
39-
if (s.startsWith("#")) {
40-
if (!lastWasComment) { // comments are merged
41-
totcomment++;
42-
}
43-
lastWasComment = true;
44-
} else {
45-
totrecs++;
46-
lastWasComment = false;
47-
}
48-
}
49-
br.close();
50-
CSVFormat format = CSVFormat.DEFAULT;
51-
//
52-
format = format.withAllowMissingColumnNames(false);
53-
format = format.withCommentMarker('#');
54-
format = format.withDelimiter(',');
55-
format = format.withEscape('\\');
56-
format = format.withHeader("author", "title", "publishDate");
57-
format = format.withHeaderComments("headerComment");
58-
format = format.withNullString("NULL");
59-
format = format.withIgnoreEmptyLines(true);
60-
format = format.withIgnoreSurroundingSpaces(true);
61-
format = format.withQuote('"');
62-
format = format.withQuoteMode(QuoteMode.ALL);
63-
format = format.withRecordSeparator('\n');
64-
format = format.withSkipHeaderRecord(false);
65-
//
66-
final CSVParser parser = CSVParser.parse(csvData, Charset.defaultCharset(), format);
67-
int comments = 0;
68-
int records = 0;
69-
for (final CSVRecord csvRecord : parser) {
70-
// System.out.println(csvRecord.isComment() + "[" + csvRecord.toString() + "]");
71-
records++;
72-
if (csvRecord.hasComment()) {
73-
comments++;
74-
}
75-
}
76-
// Comment lines are concatenated, in this example 4 lines become 2 comments.
77-
Assert.assertEquals(totcomment, comments);
78-
Assert.assertEquals(totrecs, records); // records includes the header
79-
}
80-
}
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.commons.csv.bugs;
18+
19+
import java.io.BufferedReader;
20+
import java.io.File;
21+
import java.io.FileReader;
22+
import java.io.IOException;
23+
import java.nio.charset.Charset;
24+
25+
import org.apache.commons.csv.CSVFormat;
26+
import org.apache.commons.csv.CSVParser;
27+
import org.apache.commons.csv.CSVRecord;
28+
import org.apache.commons.csv.QuoteMode;
29+
import org.junit.Assert;
30+
import org.junit.Test;
31+
32+
public class JiraCsv167Test {
33+
34+
@Test
35+
public void parse() throws IOException {
36+
final File csvData = new File("src/test/resources/csv-167/sample1.csv");
37+
final BufferedReader br = new BufferedReader(new FileReader(csvData));
38+
String s = null;
39+
int totcomment = 0;
40+
int totrecs = 0;
41+
boolean lastWasComment = false;
42+
while((s=br.readLine()) != null) {
43+
if (s.startsWith("#")) {
44+
if (!lastWasComment) { // comments are merged
45+
totcomment++;
46+
}
47+
lastWasComment = true;
48+
} else {
49+
totrecs++;
50+
lastWasComment = false;
51+
}
52+
}
53+
br.close();
54+
CSVFormat format = CSVFormat.DEFAULT;
55+
//
56+
format = format.withAllowMissingColumnNames(false);
57+
format = format.withCommentMarker('#');
58+
format = format.withDelimiter(',');
59+
format = format.withEscape('\\');
60+
format = format.withHeader("author", "title", "publishDate");
61+
format = format.withHeaderComments("headerComment");
62+
format = format.withNullString("NULL");
63+
format = format.withIgnoreEmptyLines(true);
64+
format = format.withIgnoreSurroundingSpaces(true);
65+
format = format.withQuote('"');
66+
format = format.withQuoteMode(QuoteMode.ALL);
67+
format = format.withRecordSeparator('\n');
68+
format = format.withSkipHeaderRecord(false);
69+
//
70+
final CSVParser parser = CSVParser.parse(csvData, Charset.defaultCharset(), format);
71+
int comments = 0;
72+
int records = 0;
73+
for (final CSVRecord csvRecord : parser) {
74+
// System.out.println(csvRecord.isComment() + "[" + csvRecord.toString() + "]");
75+
records++;
76+
if (csvRecord.hasComment()) {
77+
comments++;
78+
}
79+
}
80+
// Comment lines are concatenated, in this example 4 lines become 2 comments.
81+
Assert.assertEquals(totcomment, comments);
82+
Assert.assertEquals(totrecs, records); // records includes the header
83+
}
84+
}

0 commit comments

Comments
 (0)