Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.

Commit d2ed0ba

Browse files
committed
Sort test members
1 parent 72bdd97 commit d2ed0ba

3 files changed

Lines changed: 102 additions & 102 deletions

File tree

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

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,21 @@
5858
@State(Scope.Benchmark)
5959
public class CSVBenchmark {
6060

61+
private static final class CountingReaderCallback implements org.skife.csv.ReaderCallback {
62+
public int count;
63+
64+
@Override
65+
public void onRow(final String[] fields) {
66+
count++;
67+
}
68+
}
69+
6170
private String data;
6271

72+
private Reader getReader() {
73+
return new StringReader(data);
74+
}
75+
6376
/**
6477
* Load the data in memory before running the benchmarks, this takes out IO from the results.
6578
*/
@@ -72,55 +85,6 @@ public void init() throws IOException {
7285
}
7386
}
7487

75-
private Reader getReader() {
76-
return new StringReader(data);
77-
}
78-
79-
@Benchmark
80-
public int read(final Blackhole bh) throws Exception {
81-
int count = 0;
82-
83-
try (BufferedReader reader = new BufferedReader(getReader())) {
84-
while (reader.readLine() != null) {
85-
count++;
86-
}
87-
}
88-
89-
bh.consume(count);
90-
return count;
91-
}
92-
93-
@Benchmark
94-
public int scan(final Blackhole bh) throws Exception {
95-
int count = 0;
96-
97-
try (Scanner scanner = new Scanner(getReader())) {
98-
while (scanner.hasNextLine()) {
99-
scanner.nextLine();
100-
count++;
101-
}
102-
}
103-
104-
bh.consume(count);
105-
return count;
106-
}
107-
108-
@Benchmark
109-
public int split(final Blackhole bh) throws Exception {
110-
int count = 0;
111-
112-
try (BufferedReader reader = new BufferedReader(getReader())) {
113-
String line;
114-
while ((line = reader.readLine()) != null) {
115-
final String[] values = StringUtils.split(line, ',');
116-
count += values.length;
117-
}
118-
}
119-
120-
bh.consume(count);
121-
return count;
122-
}
123-
12488
@Benchmark
12589
public int parseCommonsCSV(final Blackhole bh) throws Exception {
12690
int count = 0;
@@ -202,15 +166,6 @@ public int parseSkifeCSV(final Blackhole bh) throws Exception {
202166
return callback.count;
203167
}
204168

205-
private static final class CountingReaderCallback implements org.skife.csv.ReaderCallback {
206-
public int count;
207-
208-
@Override
209-
public void onRow(final String[] fields) {
210-
count++;
211-
}
212-
}
213-
214169
@Benchmark
215170
public int parseSuperCSV(final Blackhole bh) throws Exception {
216171
int count = 0;
@@ -224,4 +179,49 @@ public int parseSuperCSV(final Blackhole bh) throws Exception {
224179
bh.consume(count);
225180
return count;
226181
}
182+
183+
@Benchmark
184+
public int read(final Blackhole bh) throws Exception {
185+
int count = 0;
186+
187+
try (BufferedReader reader = new BufferedReader(getReader())) {
188+
while (reader.readLine() != null) {
189+
count++;
190+
}
191+
}
192+
193+
bh.consume(count);
194+
return count;
195+
}
196+
197+
@Benchmark
198+
public int scan(final Blackhole bh) throws Exception {
199+
int count = 0;
200+
201+
try (Scanner scanner = new Scanner(getReader())) {
202+
while (scanner.hasNextLine()) {
203+
scanner.nextLine();
204+
count++;
205+
}
206+
}
207+
208+
bh.consume(count);
209+
return count;
210+
}
211+
212+
@Benchmark
213+
public int split(final Blackhole bh) throws Exception {
214+
int count = 0;
215+
216+
try (BufferedReader reader = new BufferedReader(getReader())) {
217+
String line;
218+
while ((line = reader.readLine()) != null) {
219+
final String[] values = StringUtils.split(line, ',');
220+
count += values.length;
221+
}
222+
}
223+
224+
bh.consume(count);
225+
return count;
226+
}
227227
}

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,19 @@ public void testQuoteCharSameAsDelimiterThrowsException_Deprecated() {
935935
assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withQuote('!').withDelimiter('!'));
936936
}
937937

938+
@Test
939+
public void testQuoteModeNoneShouldReturnMeaningfulExceptionMessage() {
940+
Exception exception = assertThrows(IllegalArgumentException.class, () -> {
941+
CSVFormat.DEFAULT.builder()
942+
.setHeader("Col1", "Col2", "Col3", "Col4")
943+
.setQuoteMode(QuoteMode.NONE)
944+
.build();
945+
});
946+
String actualMessage = exception.getMessage();
947+
String expectedMessage = "Quote mode set to NONE but no escape character is set";
948+
assertEquals(expectedMessage, actualMessage);
949+
}
950+
938951
@Test
939952
public void testQuotePolicyNoneWithoutEscapeThrowsException() {
940953
assertThrows(IllegalArgumentException.class, () -> CSVFormat.newFormat('!').builder().setQuoteMode(QuoteMode.NONE).build());
@@ -1477,17 +1490,4 @@ public void testWithSystemRecordSeparator() {
14771490
final CSVFormat formatWithRecordSeparator = CSVFormat.DEFAULT.withSystemRecordSeparator();
14781491
assertEquals(System.lineSeparator(), formatWithRecordSeparator.getRecordSeparator());
14791492
}
1480-
1481-
@Test
1482-
public void testQuoteModeNoneShouldReturnMeaningfulExceptionMessage() {
1483-
Exception exception = assertThrows(IllegalArgumentException.class, () -> {
1484-
CSVFormat.DEFAULT.builder()
1485-
.setHeader("Col1", "Col2", "Col3", "Col4")
1486-
.setQuoteMode(QuoteMode.NONE)
1487-
.build();
1488-
});
1489-
String actualMessage = exception.getMessage();
1490-
String expectedMessage = "Quote mode set to NONE but no escape character is set";
1491-
assertEquals(expectedMessage, actualMessage);
1492-
}
14931493
}

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

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,37 @@ public void testCSVRecordNULLValues() throws IOException {
8989
assertThrows(IllegalArgumentException.class, () -> csvRecord.get("B"));
9090
}
9191

92+
@Test
93+
public void testDuplicateHeaderGet() throws IOException {
94+
final String csv = "A,A,B,B\n1,2,5,6\n";
95+
final CSVFormat format = CSVFormat.DEFAULT.builder().setHeader().build();
96+
97+
try (final CSVParser parser = CSVParser.parse(csv, format)) {
98+
final CSVRecord record = parser.nextRecord();
99+
100+
assertAll("Test that it gets the last instance of a column when there are duplicate headings",
101+
() -> assertEquals("2", record.get("A")),
102+
() -> assertEquals("6", record.get("B"))
103+
);
104+
}
105+
}
106+
107+
@Test
108+
public void testDuplicateHeaderToMap() throws IOException {
109+
final String csv = "A,A,B,B\n1,2,5,6\n";
110+
final CSVFormat format = CSVFormat.DEFAULT.builder().setHeader().build();
111+
112+
try (final CSVParser parser = CSVParser.parse(csv, format)) {
113+
final CSVRecord record = parser.nextRecord();
114+
final Map<String, String> map = record.toMap();
115+
116+
assertAll("Test that it gets the last instance of a column when there are duplicate headings",
117+
() -> assertEquals("2", map.get("A")),
118+
() -> assertEquals("6", map.get("B"))
119+
);
120+
}
121+
}
122+
92123
@Test
93124
public void testGetInt() {
94125
assertEquals(values[0], record.get(0));
@@ -337,37 +368,6 @@ public void testToString() {
337368
assertTrue(recordWithHeader.toString().contains("values="));
338369
}
339370

340-
@Test
341-
public void testDuplicateHeaderGet() throws IOException {
342-
final String csv = "A,A,B,B\n1,2,5,6\n";
343-
final CSVFormat format = CSVFormat.DEFAULT.builder().setHeader().build();
344-
345-
try (final CSVParser parser = CSVParser.parse(csv, format)) {
346-
final CSVRecord record = parser.nextRecord();
347-
348-
assertAll("Test that it gets the last instance of a column when there are duplicate headings",
349-
() -> assertEquals("2", record.get("A")),
350-
() -> assertEquals("6", record.get("B"))
351-
);
352-
}
353-
}
354-
355-
@Test
356-
public void testDuplicateHeaderToMap() throws IOException {
357-
final String csv = "A,A,B,B\n1,2,5,6\n";
358-
final CSVFormat format = CSVFormat.DEFAULT.builder().setHeader().build();
359-
360-
try (final CSVParser parser = CSVParser.parse(csv, format)) {
361-
final CSVRecord record = parser.nextRecord();
362-
final Map<String, String> map = record.toMap();
363-
364-
assertAll("Test that it gets the last instance of a column when there are duplicate headings",
365-
() -> assertEquals("2", map.get("A")),
366-
() -> assertEquals("6", map.get("B"))
367-
);
368-
}
369-
}
370-
371371
private void validateMap(final Map<String, String> map, final boolean allowsNulls) {
372372
assertTrue(map.containsKey(EnumHeader.FIRST.name()));
373373
assertTrue(map.containsKey(EnumHeader.SECOND.name()));

0 commit comments

Comments
 (0)