Skip to content

Commit 6a11b89

Browse files
committed
Enable Checkstyle for test sources and fix issues
1 parent fce94ea commit 6a11b89

13 files changed

+223
-216
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@
206206
<configLocation>${checkstyle.config.file}</configLocation>
207207
<enableRulesSummary>false</enableRulesSummary>
208208
<suppressionsLocation>${checkstyle.suppress.file}</suppressionsLocation>
209+
<includeTestSourceDirectory>true</includeTestSourceDirectory>
209210
</configuration>
210211
</plugin>
211212
<plugin>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828
import java.util.concurrent.TimeUnit;
2929
import java.util.zip.GZIPInputStream;
3030

31-
import com.generationjava.io.CsvReader;
32-
import com.opencsv.CSVParserBuilder;
33-
import com.opencsv.CSVReaderBuilder;
34-
3531
import org.apache.commons.io.IOUtils;
3632
import org.apache.commons.lang3.StringUtils;
3733
import org.openjdk.jmh.annotations.Benchmark;
@@ -49,6 +45,10 @@
4945
import org.supercsv.io.CsvListReader;
5046
import org.supercsv.prefs.CsvPreference;
5147

48+
import com.generationjava.io.CsvReader;
49+
import com.opencsv.CSVParserBuilder;
50+
import com.opencsv.CSVReaderBuilder;
51+
5252
@BenchmarkMode(Mode.AverageTime)
5353
@Fork(value = 1, jvmArgs = {"-server", "-Xms1024M", "-Xmx1024M"})
5454
@Threads(1)

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -307,25 +307,24 @@ public void testCSVParser(final DuplicateHeaderMode duplicateHeaderMode,
307307
final boolean allowMissingColumnNames,
308308
final boolean ignoreHeaderCase,
309309
final String[] headers,
310-
final boolean valid) throws IOException {
311-
final CSVFormat format =
312-
CSVFormat.DEFAULT.builder()
313-
.setDuplicateHeaderMode(duplicateHeaderMode)
314-
.setAllowMissingColumnNames(allowMissingColumnNames)
315-
.setIgnoreHeaderCase(ignoreHeaderCase)
316-
.setNullString("NULL")
317-
.setHeader()
318-
.build();
310+
final boolean valid) throws IOException {
311+
// @formatter:off
312+
final CSVFormat format = CSVFormat.DEFAULT.builder()
313+
.setDuplicateHeaderMode(duplicateHeaderMode)
314+
.setAllowMissingColumnNames(allowMissingColumnNames)
315+
.setIgnoreHeaderCase(ignoreHeaderCase)
316+
.setNullString("NULL")
317+
.setHeader()
318+
.build();
319+
// @formatter:on
319320
final String input = Arrays.stream(headers)
320321
.map(s -> s == null ? format.getNullString() : s)
321322
.collect(Collectors.joining(format.getDelimiterString()));
323+
// @formatter:off
322324
if (valid) {
323-
try(CSVParser parser = CSVParser.parse(input, format)) {
325+
try (CSVParser parser = CSVParser.parse(input, format)) {
324326
// Parser ignores null headers
325-
final List<String> expected =
326-
Arrays.stream(headers)
327-
.filter(s -> s != null)
328-
.collect(Collectors.toList());
327+
final List<String> expected = Arrays.stream(headers).filter(s -> s != null).collect(Collectors.toList());
329328
Assertions.assertEquals(expected, parser.getHeaderNames(), "HeaderNames");
330329
}
331330
} else {

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -715,11 +715,21 @@ public void testFormatThrowsNullPointerException() {
715715

716716
@Test
717717
public void testFormatToString() {
718-
final CSVFormat format = CSVFormat.RFC4180.withEscape('?').withDelimiter(',').withQuoteMode(QuoteMode.MINIMAL).withRecordSeparator(CRLF).withQuote('"')
719-
.withNullString("").withIgnoreHeaderCase(true).withHeaderComments("This is HeaderComments").withHeader("col1", "col2", "col3");
718+
// @formatter:off
719+
final CSVFormat format = CSVFormat.RFC4180
720+
.withEscape('?')
721+
.withDelimiter(',')
722+
.withQuoteMode(QuoteMode.MINIMAL)
723+
.withRecordSeparator(CRLF)
724+
.withQuote('"')
725+
.withNullString("")
726+
.withIgnoreHeaderCase(true)
727+
.withHeaderComments("This is HeaderComments")
728+
.withHeader("col1", "col2", "col3");
729+
// @formatter:on
720730
assertEquals(
721-
"Delimiter=<,> Escape=<?> QuoteChar=<\"> QuoteMode=<MINIMAL> NullString=<> RecordSeparator=<" + CRLF
722-
+ "> IgnoreHeaderCase:ignored SkipHeaderRecord:false HeaderComments:[This is HeaderComments] Header:[col1, col2, col3]",
731+
"Delimiter=<,> Escape=<?> QuoteChar=<\"> QuoteMode=<MINIMAL> NullString=<> RecordSeparator=<" + CRLF +
732+
"> IgnoreHeaderCase:ignored SkipHeaderRecord:false HeaderComments:[This is HeaderComments] Header:[col1, col2, col3]",
723733
format.toString());
724734
}
725735

@@ -960,12 +970,14 @@ public void testQuoteCharSameAsDelimiterThrowsException_Deprecated() {
960970

961971
@Test
962972
public void testQuoteModeNoneShouldReturnMeaningfulExceptionMessage() {
963-
final Exception exception = assertThrows(IllegalArgumentException.class, () -> {
973+
final Exception exception = assertThrows(IllegalArgumentException.class, () ->
974+
// @formatter:off
964975
CSVFormat.DEFAULT.builder()
965976
.setHeader("Col1", "Col2", "Col3", "Col4")
966977
.setQuoteMode(QuoteMode.NONE)
967-
.build();
968-
});
978+
.build()
979+
// @formatter:on
980+
);
969981
final String actualMessage = exception.getMessage();
970982
final String expectedMessage = "Quote mode set to NONE but no escape character is set";
971983
assertEquals(expectedMessage, actualMessage);

0 commit comments

Comments
 (0)