From 25f4ebca61df02f811c597b84ec1653a8c87ceda Mon Sep 17 00:00:00 2001 From: Ivan Capobianco Date: Sun, 5 Nov 2023 15:58:37 +0100 Subject: [PATCH 01/18] test: fix issued from sonarcloud --- .DS_Store | Bin 0 -> 8196 bytes .../org/apache/commons/csv/CSVParserTest.java | 18 ++++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..3383833de59286ad59b7a52f158db75dfe94a9dc GIT binary patch literal 8196 zcmeHM-EPw`82#LhHC_2BFr?ieMdEfV8&WqRZc5hz6=Rc@7K8wmrY&2vG#UM&plMRC z;T?DdZg~>kg)2Cp?Nv#ZU4u4TvX2v=W5>sF(k~?bby}^ zHZo&b<5Z!1bfAzS0B|0sWkMZsfYjI;%NnN&r4)Ut=s{?y&>@CUaPMJsQp$H>J$GNH!X zy-54y(Wvgncs~-n>?w~9XiRRLE$$}Ri!-)|-UAA0K)rq6senNK(ie0Kg+X6m8$;Uf5 z(?qS2)`#@+d&J8dTGPO&bzDaix;pxJnyO}pqv||ugS{oM-a%QU5q(asi*!1wT15Z5 zavWBsYuM?iCJR?Xcv3|F@(WLN4 zSIAC^>k%jOVAkM8Q##q8*JvaDNP_6JKd|ERE$(hDUl|{B)0eZ#Y_8`z11S z^H&zKR@TZ}@0^2h;*8p(@vzb!yy2rp82avMz3smAdXrXRX)6pyZ7=8zq`>R;KzaMh z3%cQ?5{`rJP--33VCAe_tFU~0yjfaXvDY_CCoA^x!w0Bulr~OIa@L)D_aE)G4*h-* ze#J^43H_p^YwCDb^1A9de{u$a9|n9^GkXE|4)36S?488U7Es0fh;c87E3r8xyqVc& zD#n2e;=r7m$8sK6JOBIt1(~gxhH=0+kmi7xuR7HVT26m5BuN}=+sN;cIWcdlP)bn9 oa2zPZap3F^L)2|hSyR?HRfsc4|L8+N+OHz>{+BCaip$`@Ux6TIEdT%j literal 0 HcmV?d00001 diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java b/src/test/java/org/apache/commons/csv/CSVParserTest.java index e0d0c077d4..cca3b3fcb0 100644 --- a/src/test/java/org/apache/commons/csv/CSVParserTest.java +++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java @@ -1362,10 +1362,20 @@ public void testParseWithDelimiterWithQuote() throws IOException { } @Test public void testParseWithQuoteThrowsException() { - final CSVFormat csvFormat = CSVFormat.DEFAULT.withQuote('\''); - assertThrows(IOException.class, () -> csvFormat.parse(new StringReader("'a,b,c','")).nextRecord()); - assertThrows(IOException.class, () -> csvFormat.parse(new StringReader("'a,b,c'abc,xyz")).nextRecord()); - assertThrows(IOException.class, () -> csvFormat.parse(new StringReader("'abc'a,b,c',xyz")).nextRecord()); + final CSVFormat csvFormat = CSVFormat.DEFAULT.withQuote('\''); + final String source1 = "'a,b,c','"; + final String source2 = "'a,b,c'abc,xyz"; + final String source3 = "'abc'a,b,c',xyz"; + + try (CSVParser csvParser = csvFormat.parse(new StringReader(source1))) { + assertThrows(IOException.class, () -> csvParser.nextRecord()); + } + try (CSVParser csvParser = csvFormat.parse(new StringReader(source2))) { + assertThrows(IOException.class, () -> csvParser.nextRecord()); + } + try (CSVParser csvParser = csvFormat.parse(new StringReader(source3))) { + assertThrows(IOException.class, () -> csvParser.nextRecord()); + } } @Test public void testParseWithQuoteWithEscape() throws IOException { From af56063e3693b4fc813e3c5d8d4000746d711c6a Mon Sep 17 00:00:00 2001 From: Ivan Capobianco Date: Sat, 25 Nov 2023 11:07:32 +0100 Subject: [PATCH 02/18] fix: sonarcloud code smell --- .../org/apache/commons/csv/CSVFormat.java | 26 ++++++++++++++----- .../org/apache/commons/csv/CSVParserTest.java | 2 +- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index 43d9c64f82..9647821139 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -2133,7 +2133,7 @@ private void printWithEscapes(final CharSequence charSeq, final Appendable appen while (pos < end) { char c = charSeq.charAt(pos); final boolean isDelimiterStart = isDelimiter(c, charSeq, pos, delim, delimLength); - if (c == CR || c == LF || c == escape || isDelimiterStart) { + if (isCRLFEscape(c) || isDelimiterStart) { // write out segment up until this char if (pos > start) { appendable.append(charSeq, start, pos); @@ -2148,12 +2148,7 @@ private void printWithEscapes(final CharSequence charSeq, final Appendable appen appendable.append(c); if (isDelimiterStart) { - for (int i = 1; i < delimLength; i++) { - pos++; - c = charSeq.charAt(pos); - appendable.append(escape); - appendable.append(c); - } + pos = appendUntilDelimiter(delimLength, pos, charSeq, appendable); } start = pos + 1; // start on the current char after this one @@ -2167,6 +2162,23 @@ private void printWithEscapes(final CharSequence charSeq, final Appendable appen } } + private int appendUntilDelimiter(int delimLength, int pos, CharSequence charSeq, Appendable appendable) throws IOException { + final char escape = getEscapeCharacter().charValue(); + + for (int i = 1; i < delimLength; i++) { + pos++; + char c = charSeq.charAt(pos); + appendable.append(escape); + appendable.append(c); + } + + return pos; + } + + private boolean isCRLFEscape(char c) { + return c == CR || c == LF || c == getEscapeCharacter().charValue(); + } + private void printWithEscapes(final Reader reader, final Appendable appendable) throws IOException { int start = 0; int pos = 0; diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java b/src/test/java/org/apache/commons/csv/CSVParserTest.java index cca3b3fcb0..228dcb9441 100644 --- a/src/test/java/org/apache/commons/csv/CSVParserTest.java +++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java @@ -1361,7 +1361,7 @@ public void testParseWithDelimiterWithQuote() throws IOException { } } @Test - public void testParseWithQuoteThrowsException() { + public void testParseWithQuoteThrowsException() throws IOException { final CSVFormat csvFormat = CSVFormat.DEFAULT.withQuote('\''); final String source1 = "'a,b,c','"; final String source2 = "'a,b,c'abc,xyz"; From 03efc311ff4bd9b0127250f3d5c2d3fb07e36cf3 Mon Sep 17 00:00:00 2001 From: Ivan Capobianco Date: Sat, 25 Nov 2023 11:41:42 +0100 Subject: [PATCH 03/18] fix: sonarcloud code smell --- .../org/apache/commons/csv/CSVFormat.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index 9647821139..4b26880ba7 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -2148,7 +2148,7 @@ private void printWithEscapes(final CharSequence charSeq, final Appendable appen appendable.append(c); if (isDelimiterStart) { - pos = appendUntilDelimiter(delimLength, pos, charSeq, appendable); + pos = appendUntilDelimiterGetPosition(delimLength, pos, charSeq, appendable); } start = pos + 1; // start on the current char after this one @@ -2162,7 +2162,7 @@ private void printWithEscapes(final CharSequence charSeq, final Appendable appen } } - private int appendUntilDelimiter(int delimLength, int pos, CharSequence charSeq, Appendable appendable) throws IOException { + private int appendUntilDelimiterGetPosition(int delimLength, int pos, CharSequence charSeq, Appendable appendable) throws IOException { final char escape = getEscapeCharacter().charValue(); for (int i = 1; i < delimLength; i++) { @@ -2175,9 +2175,24 @@ private int appendUntilDelimiter(int delimLength, int pos, CharSequence charSeq, return pos; } + private void appendUntilDelimiter(ExtendedBufferedReader bufferedReader, Appendable appendable, int delimLength) throws IOException { + final char escape = getEscapeCharacter().charValue(); + + for (int i = 1; i < delimLength; i++) { + int c = bufferedReader.read(); + append(escape, appendable); + append((char) c, appendable); + } + + } + private boolean isCRLFEscape(char c) { return c == CR || c == LF || c == getEscapeCharacter().charValue(); } + // private boolean isCRLFEscape(int x) { + // char c = (char) x; + // return c == CR || c == LF || c == getEscapeCharacter().charValue(); + // } private void printWithEscapes(final Reader reader, final Appendable appendable) throws IOException { int start = 0; @@ -2195,7 +2210,7 @@ private void printWithEscapes(final Reader reader, final Appendable appendable) builder.append((char) c); final boolean isDelimiterStart = isDelimiter((char) c, builder.toString() + new String(bufferedReader.lookAhead(delimLength - 1)), pos, delim, delimLength); - if (c == CR || c == LF || c == escape || isDelimiterStart) { + if (isCRLFEscape((char) c) || isDelimiterStart) { // write out segment up until this char if (pos > start) { append(builder.substring(start, pos), appendable); @@ -2212,11 +2227,7 @@ private void printWithEscapes(final Reader reader, final Appendable appendable) append((char) c, appendable); if (isDelimiterStart) { - for (int i = 1; i < delimLength; i++) { - c = bufferedReader.read(); - append(escape, appendable); - append((char) c, appendable); - } + appendUntilDelimiter(bufferedReader, appendable, delimLength); } start = pos + 1; // start on the current char after this one From 4e968ec651bde486339b3104640cd121d38085a6 Mon Sep 17 00:00:00 2001 From: Ivan Capobianco Date: Sun, 26 Nov 2023 16:59:52 +0100 Subject: [PATCH 04/18] fix: sonarcloud code smell --- .../org/apache/commons/csv/CSVFormat.java | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index 4b26880ba7..38885d0df1 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -2464,27 +2464,27 @@ private void validate() throws IllegalArgumentException { throw new IllegalArgumentException("The delimiter cannot be a line break"); } - if (quoteCharacter != null && contains(delimiter, quoteCharacter.charValue())) { + if (areQuoteCharAndDelimiterEqual(quoteCharacter, delimiter)) { throw new IllegalArgumentException("The quoteChar character and the delimiter cannot be the same ('" + quoteCharacter + "')"); } - if (escapeCharacter != null && contains(delimiter, escapeCharacter.charValue())) { + if (areEscapeCharAndDelimiterEqual(escapeCharacter, delimiter)) { throw new IllegalArgumentException("The escape character and the delimiter cannot be the same ('" + escapeCharacter + "')"); } - if (commentMarker != null && contains(delimiter, commentMarker.charValue())) { + if (areCommentStartCharAndDelimiterEqual(commentMarker, delimiter)) { throw new IllegalArgumentException("The comment start character and the delimiter cannot be the same ('" + commentMarker + "')"); } - if (quoteCharacter != null && quoteCharacter.equals(commentMarker)) { + if (areCommentStartCharAndQuoteCharEqual(commentMarker, delimiter)) { throw new IllegalArgumentException("The comment start character and the quoteChar cannot be the same ('" + commentMarker + "')"); } - if (escapeCharacter != null && escapeCharacter.equals(commentMarker)) { + if (areCommentStartCharAndEscapeCharEqual(commentMarker, delimiter)) { throw new IllegalArgumentException("The comment start and the escape character cannot be the same ('" + commentMarker + "')"); } - if (escapeCharacter == null && quoteMode == QuoteMode.NONE) { + if (isEscapeCharSetForQuoteModeNone(escapeCharacter, quoteMode)) { throw new IllegalArgumentException("Quote mode set to NONE but no escape character is set"); } @@ -2506,6 +2506,29 @@ private void validate() throws IllegalArgumentException { } } + private boolean areQuoteCharAndDelimiterEqual(Character quoteCharacter, String delimiter) { + return quoteCharacter != null && contains(delimiter, quoteCharacter.charValue()); + } + + private boolean areEscapeCharAndDelimiterEqual(Character escapeCharacter, String delimiter) { + return escapeCharacter != null && contains(delimiter, escapeCharacter.charValue()); + } + + private boolean areCommentStartCharAndDelimiterEqual(Character commentMarker, String delimiter) { + return commentMarker != null && contains(delimiter, commentMarker.charValue()); + } + + private boolean areCommentStartCharAndQuoteCharEqual(Character commentMarker, String delimiter) { + return quoteCharacter != null && quoteCharacter.equals(commentMarker); + } + + private boolean areCommentStartCharAndEscapeCharEqual(Character commentMarker, String delimiter) { + return escapeCharacter != null && escapeCharacter.equals(commentMarker); + } + + private boolean isEscapeCharSetForQuoteModeNone(Character escapeCharacter, QuoteMode quoteMode) { + return escapeCharacter == null && quoteMode == QuoteMode.NONE; + } /** * Builds a new {@code CSVFormat} that allows duplicate header names. * From 3d7d6361ce2ce7815e0bb789a74f6dcf887c503c Mon Sep 17 00:00:00 2001 From: Ivan Capobianco Date: Sun, 26 Nov 2023 18:39:09 +0100 Subject: [PATCH 05/18] fix: sonarcloud code smell fix --- src/main/java/org/apache/commons/csv/CSVFormat.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index 38885d0df1..5ac81923fb 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -2189,10 +2189,6 @@ private void appendUntilDelimiter(ExtendedBufferedReader bufferedReader, Appenda private boolean isCRLFEscape(char c) { return c == CR || c == LF || c == getEscapeCharacter().charValue(); } - // private boolean isCRLFEscape(int x) { - // char c = (char) x; - // return c == CR || c == LF || c == getEscapeCharacter().charValue(); - // } private void printWithEscapes(final Reader reader, final Appendable appendable) throws IOException { int start = 0; @@ -2476,11 +2472,11 @@ private void validate() throws IllegalArgumentException { throw new IllegalArgumentException("The comment start character and the delimiter cannot be the same ('" + commentMarker + "')"); } - if (areCommentStartCharAndQuoteCharEqual(commentMarker, delimiter)) { + if (areCommentStartCharAndQuoteCharEqual(quoteCharacter, commentMarker)) { throw new IllegalArgumentException("The comment start character and the quoteChar cannot be the same ('" + commentMarker + "')"); } - if (areCommentStartCharAndEscapeCharEqual(commentMarker, delimiter)) { + if (areCommentStartCharAndEscapeCharEqual(escapeCharacter, commentMarker)) { throw new IllegalArgumentException("The comment start and the escape character cannot be the same ('" + commentMarker + "')"); } @@ -2518,11 +2514,11 @@ private boolean areCommentStartCharAndDelimiterEqual(Character commentMarker, St return commentMarker != null && contains(delimiter, commentMarker.charValue()); } - private boolean areCommentStartCharAndQuoteCharEqual(Character commentMarker, String delimiter) { + private boolean areCommentStartCharAndQuoteCharEqual(Character quoteCharacter, Character commentMarker) { return quoteCharacter != null && quoteCharacter.equals(commentMarker); } - private boolean areCommentStartCharAndEscapeCharEqual(Character commentMarker, String delimiter) { + private boolean areCommentStartCharAndEscapeCharEqual(Character escapeCharacter, Character commentMarker) { return escapeCharacter != null && escapeCharacter.equals(commentMarker); } From a1d11343e8b03adf128ca0999437d50f7528f405 Mon Sep 17 00:00:00 2001 From: Ivan Capobianco Date: Sun, 26 Nov 2023 18:43:09 +0100 Subject: [PATCH 06/18] fix: sonarcloud code smell fix 2 --- .../org/apache/commons/csv/CSVFormat.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index 5ac81923fb..df6b66666f 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -2485,21 +2485,7 @@ private void validate() throws IllegalArgumentException { } // Validate headers - if (headers != null && duplicateHeaderMode != DuplicateHeaderMode.ALLOW_ALL) { - final Set dupCheckSet = new HashSet<>(headers.length); - final boolean emptyDuplicatesAllowed = duplicateHeaderMode == DuplicateHeaderMode.ALLOW_EMPTY; - for (final String header : headers) { - final boolean blank = isBlank(header); - // Sanitise all empty headers to the empty string "" when checking duplicates - final boolean containsHeader = !dupCheckSet.add(blank ? "" : header); - if (containsHeader && !(blank && emptyDuplicatesAllowed)) { - throw new IllegalArgumentException( - String.format( - "The header contains a duplicate name: \"%s\" in %s. If this is valid then use CSVFormat.Builder.setDuplicateHeaderMode().", - header, Arrays.toString(headers))); - } - } - } + validateHeaders(); } private boolean areQuoteCharAndDelimiterEqual(Character quoteCharacter, String delimiter) { @@ -2525,6 +2511,24 @@ private boolean areCommentStartCharAndEscapeCharEqual(Character escapeCharacter, private boolean isEscapeCharSetForQuoteModeNone(Character escapeCharacter, QuoteMode quoteMode) { return escapeCharacter == null && quoteMode == QuoteMode.NONE; } + + private void validateHeaders() throws IllegalArgumentException { + if (headers != null && duplicateHeaderMode != DuplicateHeaderMode.ALLOW_ALL) { + final Set dupCheckSet = new HashSet<>(headers.length); + final boolean emptyDuplicatesAllowed = duplicateHeaderMode == DuplicateHeaderMode.ALLOW_EMPTY; + for (final String header : headers) { + final boolean blank = isBlank(header); + // Sanitise all empty headers to the empty string "" when checking duplicates + final boolean containsHeader = !dupCheckSet.add(blank ? "" : header); + if (containsHeader && !(blank && emptyDuplicatesAllowed)) { + throw new IllegalArgumentException( + String.format( + "The header contains a duplicate name: \"%s\" in %s. If this is valid then use CSVFormat.Builder.setDuplicateHeaderMode().", + header, Arrays.toString(headers))); + } + } + } + } /** * Builds a new {@code CSVFormat} that allows duplicate header names. * From cfb1f16d60346c9a750b021d7da4f0893807aaa1 Mon Sep 17 00:00:00 2001 From: Ivan Capobianco Date: Sun, 26 Nov 2023 18:48:32 +0100 Subject: [PATCH 07/18] fix: sonarcloud code smell --- .../org/apache/commons/csv/CSVParser.java | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java index 055e2a292b..574098e6cd 100644 --- a/src/main/java/org/apache/commons/csv/CSVParser.java +++ b/src/main/java/org/apache/commons/csv/CSVParser.java @@ -142,6 +142,16 @@ */ public final class CSVParser implements Iterable, Closeable { + private final static String kFILE = "file"; + private final static String kINPUT_STREAM = "inputStream"; + private final static String kFORMAT = "format"; + private final static String kPATH = "path"; + private final static String kSTRING = "string"; + private final static String kURL = "url"; + private final static String kCHARSET = "charset"; + private final static String kREADER = "reader"; + + final class CSVRecordIterator implements Iterator { private CSVRecord current; @@ -223,7 +233,7 @@ private static final class Headers { * If an I/O error occurs */ public static CSVParser parse(final File file, final Charset charset, final CSVFormat format) throws IOException { - Objects.requireNonNull(file, "file"); + Objects.requireNonNull(file, kFILE); return parse(file.toPath(), charset, format); } @@ -251,8 +261,8 @@ public static CSVParser parse(final File file, final Charset charset, final CSVF @SuppressWarnings("resource") public static CSVParser parse(final InputStream inputStream, final Charset charset, final CSVFormat format) throws IOException { - Objects.requireNonNull(inputStream, "inputStream"); - Objects.requireNonNull(format, "format"); + Objects.requireNonNull(inputStream, kINPUT_STREAM); + Objects.requireNonNull(format, kFORMAT); return parse(new InputStreamReader(inputStream, charset), format); } @@ -274,8 +284,8 @@ public static CSVParser parse(final InputStream inputStream, final Charset chars */ @SuppressWarnings("resource") public static CSVParser parse(final Path path, final Charset charset, final CSVFormat format) throws IOException { - Objects.requireNonNull(path, "path"); - Objects.requireNonNull(format, "format"); + Objects.requireNonNull(path, kPATH); + Objects.requireNonNull(format, kFORMAT); return parse(Files.newInputStream(path), charset, format); } @@ -316,8 +326,8 @@ public static CSVParser parse(final Reader reader, final CSVFormat format) throw * If an I/O error occurs */ public static CSVParser parse(final String string, final CSVFormat format) throws IOException { - Objects.requireNonNull(string, "string"); - Objects.requireNonNull(format, "format"); + Objects.requireNonNull(string, kSTRING); + Objects.requireNonNull(format, kFORMAT); return new CSVParser(new StringReader(string), format); } @@ -344,9 +354,9 @@ public static CSVParser parse(final String string, final CSVFormat format) throw */ @SuppressWarnings("resource") public static CSVParser parse(final URL url, final Charset charset, final CSVFormat format) throws IOException { - Objects.requireNonNull(url, "url"); - Objects.requireNonNull(charset, "charset"); - Objects.requireNonNull(format, "format"); + Objects.requireNonNull(url, kURL); + Objects.requireNonNull(charset, kCHARSET); + Objects.requireNonNull(format, kFORMAT); return new CSVParser(new InputStreamReader(url.openStream(), charset), format); } @@ -425,8 +435,8 @@ public CSVParser(final Reader reader, final CSVFormat format) throws IOException @SuppressWarnings("resource") public CSVParser(final Reader reader, final CSVFormat format, final long characterOffset, final long recordNumber) throws IOException { - Objects.requireNonNull(reader, "reader"); - Objects.requireNonNull(format, "format"); + Objects.requireNonNull(reader, kREADER); + Objects.requireNonNull(format, kFORMAT); this.format = format.copy(); this.lexer = new Lexer(format, new ExtendedBufferedReader(reader)); From 0076d4118f8773e9008a24fc97871afb6aa6a29f Mon Sep 17 00:00:00 2001 From: Ivan Capobianco Date: Sun, 26 Nov 2023 18:52:09 +0100 Subject: [PATCH 08/18] fix: sonarcloud code smell fix 3 --- .../org/apache/commons/csv/CSVParser.java | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java index 574098e6cd..397ded859d 100644 --- a/src/main/java/org/apache/commons/csv/CSVParser.java +++ b/src/main/java/org/apache/commons/csv/CSVParser.java @@ -142,14 +142,14 @@ */ public final class CSVParser implements Iterable, Closeable { - private final static String kFILE = "file"; - private final static String kINPUT_STREAM = "inputStream"; - private final static String kFORMAT = "format"; - private final static String kPATH = "path"; - private final static String kSTRING = "string"; - private final static String kURL = "url"; - private final static String kCHARSET = "charset"; - private final static String kREADER = "reader"; + private final static String KFILE = "file"; + private final static String KINPUT_STREAM = "inputStream"; + private final static String KFORMAT = "format"; + private final static String KPATH = "path"; + private final static String KSTRING = "string"; + private final static String KURL = "url"; + private final static String KCHARSET = "charset"; + private final static String KREADER = "reader"; final class CSVRecordIterator implements Iterator { @@ -233,7 +233,7 @@ private static final class Headers { * If an I/O error occurs */ public static CSVParser parse(final File file, final Charset charset, final CSVFormat format) throws IOException { - Objects.requireNonNull(file, kFILE); + Objects.requireNonNull(file, KFILE); return parse(file.toPath(), charset, format); } @@ -261,8 +261,8 @@ public static CSVParser parse(final File file, final Charset charset, final CSVF @SuppressWarnings("resource") public static CSVParser parse(final InputStream inputStream, final Charset charset, final CSVFormat format) throws IOException { - Objects.requireNonNull(inputStream, kINPUT_STREAM); - Objects.requireNonNull(format, kFORMAT); + Objects.requireNonNull(inputStream, KINPUT_STREAM); + Objects.requireNonNull(format, KFORMAT); return parse(new InputStreamReader(inputStream, charset), format); } @@ -284,8 +284,8 @@ public static CSVParser parse(final InputStream inputStream, final Charset chars */ @SuppressWarnings("resource") public static CSVParser parse(final Path path, final Charset charset, final CSVFormat format) throws IOException { - Objects.requireNonNull(path, kPATH); - Objects.requireNonNull(format, kFORMAT); + Objects.requireNonNull(path, KPATH); + Objects.requireNonNull(format, KFORMAT); return parse(Files.newInputStream(path), charset, format); } @@ -326,8 +326,8 @@ public static CSVParser parse(final Reader reader, final CSVFormat format) throw * If an I/O error occurs */ public static CSVParser parse(final String string, final CSVFormat format) throws IOException { - Objects.requireNonNull(string, kSTRING); - Objects.requireNonNull(format, kFORMAT); + Objects.requireNonNull(string, KSTRING); + Objects.requireNonNull(format, KFORMAT); return new CSVParser(new StringReader(string), format); } @@ -354,9 +354,9 @@ public static CSVParser parse(final String string, final CSVFormat format) throw */ @SuppressWarnings("resource") public static CSVParser parse(final URL url, final Charset charset, final CSVFormat format) throws IOException { - Objects.requireNonNull(url, kURL); - Objects.requireNonNull(charset, kCHARSET); - Objects.requireNonNull(format, kFORMAT); + Objects.requireNonNull(url, KURL); + Objects.requireNonNull(charset, KCHARSET); + Objects.requireNonNull(format, KFORMAT); return new CSVParser(new InputStreamReader(url.openStream(), charset), format); } @@ -435,8 +435,8 @@ public CSVParser(final Reader reader, final CSVFormat format) throws IOException @SuppressWarnings("resource") public CSVParser(final Reader reader, final CSVFormat format, final long characterOffset, final long recordNumber) throws IOException { - Objects.requireNonNull(reader, kREADER); - Objects.requireNonNull(format, kFORMAT); + Objects.requireNonNull(reader, KREADER); + Objects.requireNonNull(format, KFORMAT); this.format = format.copy(); this.lexer = new Lexer(format, new ExtendedBufferedReader(reader)); From 2da983f038fa6c7b0139c2e06002710a92284972 Mon Sep 17 00:00:00 2001 From: Ivan Capobianco Date: Sun, 26 Nov 2023 18:53:58 +0100 Subject: [PATCH 09/18] fix: sonarcloud code smell fix 4 --- .../java/org/apache/commons/csv/CSVParser.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java index 397ded859d..e0fddd2f7c 100644 --- a/src/main/java/org/apache/commons/csv/CSVParser.java +++ b/src/main/java/org/apache/commons/csv/CSVParser.java @@ -142,14 +142,14 @@ */ public final class CSVParser implements Iterable, Closeable { - private final static String KFILE = "file"; - private final static String KINPUT_STREAM = "inputStream"; - private final static String KFORMAT = "format"; - private final static String KPATH = "path"; - private final static String KSTRING = "string"; - private final static String KURL = "url"; - private final static String KCHARSET = "charset"; - private final static String KREADER = "reader"; + private static final String KFILE = "file"; + private static final String KINPUT_STREAM = "inputStream"; + private static final String KFORMAT = "format"; + private static final String KPATH = "path"; + private static final String KSTRING = "string"; + private static final String KURL = "url"; + private static final String KCHARSET = "charset"; + private static final String KREADER = "reader"; final class CSVRecordIterator implements Iterator { From b7fbac941ff40d85506b6a303a6b5202de3929ef Mon Sep 17 00:00:00 2001 From: Ivan Capobianco Date: Sun, 26 Nov 2023 19:00:47 +0100 Subject: [PATCH 10/18] fix: sonarcloud code smell --- .../commons/csv/ExtendedBufferedReader.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java b/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java index 429b07cb1f..1932ae949a 100644 --- a/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java +++ b/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java @@ -178,13 +178,11 @@ public int read(final char[] buf, final int offset, final int length) throws IOE for (int i = offset; i < offset + len; i++) { final char ch = buf[i]; - if (ch == LF) { - if (CR != (i > offset ? buf[i - 1] : lastChar)) { - eolCounter++; - } - } else if (ch == CR) { - eolCounter++; + + if (isEndOfLine(ch, i , offset, buf, lastChar)) { + eolCounter++; } + } lastChar = buf[offset + len - 1]; @@ -197,6 +195,17 @@ public int read(final char[] buf, final int offset, final int length) throws IOE return len; } + private boolean isEndOfLine(final char ch, int i, int offset, final char[] buf, int lastChar) { + if (ch == LF) { + if (CR != (i > offset ? buf[i - 1] : lastChar)) { + return true; + } + } else if (ch == CR) { + return true; + } + return false; + } + /** * Gets the next line, dropping the line terminator(s). This method should only be called when processing a * comment, otherwise, information can be lost. From 157b35aa22f4de13feb18eb245c8ab569c11cbfb Mon Sep 17 00:00:00 2001 From: Ivan Capobianco Date: Mon, 27 Nov 2023 09:22:44 +0100 Subject: [PATCH 11/18] fix: sonarcloud code smell --- src/main/java/org/apache/commons/csv/Lexer.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/Lexer.java b/src/main/java/org/apache/commons/csv/Lexer.java index 50aa176d3f..cf44d60b77 100644 --- a/src/main/java/org/apache/commons/csv/Lexer.java +++ b/src/main/java/org/apache/commons/csv/Lexer.java @@ -268,10 +268,16 @@ Token nextToken(final Token token) throws IOException { } // Important: make sure a new char gets consumed in each iteration + consumeTokenWhileInvalid(token, c, eol); + + return token; + } + + private void consumeTokenWhileInvalid(Token token, int c, boolean eol) throws IOException { while (token.type == INVALID) { // ignore whitespaces at beginning of a token if (ignoreSurroundingSpaces) { - while (Character.isWhitespace((char)c) && !isDelimiter(c) && !eol) { + while (Character.isWhitespace((char) c) && !isDelimiter(c) && !eol) { c = reader.read(); eol = readEndOfLine(c); } @@ -299,7 +305,6 @@ Token nextToken(final Token token) throws IOException { parseSimpleToken(token, c); } } - return token; } /** From 88d6886e9f2cbf10031c58322d4eeea1d6cb8814 Mon Sep 17 00:00:00 2001 From: Ivan Capobianco Date: Mon, 27 Nov 2023 09:26:14 +0100 Subject: [PATCH 12/18] fix: sonarcloud code smell --- .../org/apache/commons/csv/CSVParser.java | 69 ++++++++++--------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java index e0fddd2f7c..f8781ce27d 100644 --- a/src/main/java/org/apache/commons/csv/CSVParser.java +++ b/src/main/java/org/apache/commons/csv/CSVParser.java @@ -504,38 +504,7 @@ private Headers createHeaders() throws IOException { } // build the name to index mappings - if (headerRecord != null) { - // Track an occurrence of a null, empty or blank header. - boolean observedMissing = false; - for (int i = 0; i < headerRecord.length; i++) { - final String header = headerRecord[i]; - final boolean blankHeader = CSVFormat.isBlank(header); - if (blankHeader && !this.format.getAllowMissingColumnNames()) { - throw new IllegalArgumentException( - "A header name is missing in " + Arrays.toString(headerRecord)); - } - - final boolean containsHeader = blankHeader ? observedMissing : hdrMap.containsKey(header); - final DuplicateHeaderMode headerMode = this.format.getDuplicateHeaderMode(); - final boolean duplicatesAllowed = headerMode == DuplicateHeaderMode.ALLOW_ALL; - final boolean emptyDuplicatesAllowed = headerMode == DuplicateHeaderMode.ALLOW_EMPTY; - - if (containsHeader && !duplicatesAllowed && !(blankHeader && emptyDuplicatesAllowed)) { - throw new IllegalArgumentException( - String.format( - "The header contains a duplicate name: \"%s\" in %s. If this is valid then use CSVFormat.Builder.setDuplicateHeaderMode().", - header, Arrays.toString(headerRecord))); - } - observedMissing |= blankHeader; - if (header != null) { - hdrMap.put(header, Integer.valueOf(i)); - if (headerNames == null) { - headerNames = new ArrayList<>(headerRecord.length); - } - headerNames.add(header); - } - } - } + headerNames = getHeaderNames(headerRecord, hdrMap, headerNames); } if (headerNames == null) { headerNames = Collections.emptyList(); // immutable @@ -545,6 +514,42 @@ private Headers createHeaders() throws IOException { return new Headers(hdrMap, headerNames); } + private List getHeaderNames(String[] headerRecord, Map hdrMap, List headerNames) { + if (headerRecord != null) { + // Track an occurrence of a null, empty or blank header. + boolean observedMissing = false; + for (int i = 0; i < headerRecord.length; i++) { + final String header = headerRecord[i]; + final boolean blankHeader = CSVFormat.isBlank(header); + if (blankHeader && !this.format.getAllowMissingColumnNames()) { + throw new IllegalArgumentException( + "A header name is missing in " + Arrays.toString(headerRecord)); + } + + final boolean containsHeader = blankHeader ? observedMissing : hdrMap.containsKey(header); + final DuplicateHeaderMode headerMode = this.format.getDuplicateHeaderMode(); + final boolean duplicatesAllowed = headerMode == DuplicateHeaderMode.ALLOW_ALL; + final boolean emptyDuplicatesAllowed = headerMode == DuplicateHeaderMode.ALLOW_EMPTY; + + if (containsHeader && !duplicatesAllowed && !(blankHeader && emptyDuplicatesAllowed)) { + throw new IllegalArgumentException( + String.format( + "The header contains a duplicate name: \"%s\" in %s. If this is valid then use CSVFormat.Builder.setDuplicateHeaderMode().", + header, Arrays.toString(headerRecord))); + } + observedMissing |= blankHeader; + if (header != null) { + hdrMap.put(header, Integer.valueOf(i)); + if (headerNames == null) { + headerNames = new ArrayList<>(headerRecord.length); + } + headerNames.add(header); + } + } + } + return headerNames; + } + /** * Gets the current line number in the input stream. * From 81bd555ec518d7bcc0bcf1fdb2820567da7bb8f0 Mon Sep 17 00:00:00 2001 From: Ivan Capobianco Date: Mon, 27 Nov 2023 09:29:08 +0100 Subject: [PATCH 13/18] fix: sonarcloud code smell fix 5 --- .../org/apache/commons/csv/CSVParser.java | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java index f8781ce27d..0405c357eb 100644 --- a/src/main/java/org/apache/commons/csv/CSVParser.java +++ b/src/main/java/org/apache/commons/csv/CSVParser.java @@ -504,7 +504,9 @@ private Headers createHeaders() throws IOException { } // build the name to index mappings - headerNames = getHeaderNames(headerRecord, hdrMap, headerNames); + if (headerRecord != null) { + headerNames = getHeaderNames(headerRecord, hdrMap, headerNames); + } } if (headerNames == null) { headerNames = Collections.emptyList(); // immutable @@ -515,36 +517,34 @@ private Headers createHeaders() throws IOException { } private List getHeaderNames(String[] headerRecord, Map hdrMap, List headerNames) { - if (headerRecord != null) { - // Track an occurrence of a null, empty or blank header. - boolean observedMissing = false; - for (int i = 0; i < headerRecord.length; i++) { - final String header = headerRecord[i]; - final boolean blankHeader = CSVFormat.isBlank(header); - if (blankHeader && !this.format.getAllowMissingColumnNames()) { - throw new IllegalArgumentException( - "A header name is missing in " + Arrays.toString(headerRecord)); - } + // Track an occurrence of a null, empty or blank header. + boolean observedMissing = false; + for (int i = 0; i < headerRecord.length; i++) { + final String header = headerRecord[i]; + final boolean blankHeader = CSVFormat.isBlank(header); + if (blankHeader && !this.format.getAllowMissingColumnNames()) { + throw new IllegalArgumentException( + "A header name is missing in " + Arrays.toString(headerRecord)); + } - final boolean containsHeader = blankHeader ? observedMissing : hdrMap.containsKey(header); - final DuplicateHeaderMode headerMode = this.format.getDuplicateHeaderMode(); - final boolean duplicatesAllowed = headerMode == DuplicateHeaderMode.ALLOW_ALL; - final boolean emptyDuplicatesAllowed = headerMode == DuplicateHeaderMode.ALLOW_EMPTY; + final boolean containsHeader = blankHeader ? observedMissing : hdrMap.containsKey(header); + final DuplicateHeaderMode headerMode = this.format.getDuplicateHeaderMode(); + final boolean duplicatesAllowed = headerMode == DuplicateHeaderMode.ALLOW_ALL; + final boolean emptyDuplicatesAllowed = headerMode == DuplicateHeaderMode.ALLOW_EMPTY; - if (containsHeader && !duplicatesAllowed && !(blankHeader && emptyDuplicatesAllowed)) { - throw new IllegalArgumentException( - String.format( - "The header contains a duplicate name: \"%s\" in %s. If this is valid then use CSVFormat.Builder.setDuplicateHeaderMode().", - header, Arrays.toString(headerRecord))); - } - observedMissing |= blankHeader; - if (header != null) { - hdrMap.put(header, Integer.valueOf(i)); - if (headerNames == null) { - headerNames = new ArrayList<>(headerRecord.length); - } - headerNames.add(header); + if (containsHeader && !duplicatesAllowed && !(blankHeader && emptyDuplicatesAllowed)) { + throw new IllegalArgumentException( + String.format( + "The header contains a duplicate name: \"%s\" in %s. If this is valid then use CSVFormat.Builder.setDuplicateHeaderMode().", + header, Arrays.toString(headerRecord))); + } + observedMissing |= blankHeader; + if (header != null) { + hdrMap.put(header, Integer.valueOf(i)); + if (headerNames == null) { + headerNames = new ArrayList<>(headerRecord.length); } + headerNames.add(header); } } return headerNames; From bab5857f21b6ed622b4969cd1b8caf2cb4fec1ed Mon Sep 17 00:00:00 2001 From: Ivan Capobianco Date: Mon, 27 Nov 2023 09:44:05 +0100 Subject: [PATCH 14/18] fix: sonarcloud code smell --- src/main/java/org/apache/commons/csv/CSVFormat.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index df6b66666f..68f29b2355 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -2291,7 +2291,7 @@ private void printWithQuotes(final Object object, final CharSequence charSeq, fi } else { while (pos < len) { c = charSeq.charAt(pos); - if (c == LF || c == CR || c == quoteChar || c == escapeChar || isDelimiter(c, charSeq, pos, delim, delimLength)) { + if (isLFCRQuoteCharOrEscapeChar(c, quoteChar, escapeChar) || isDelimiter(c, charSeq, pos, delim, delimLength)) { quote = true; break; } @@ -2347,6 +2347,10 @@ private void printWithQuotes(final Object object, final CharSequence charSeq, fi out.append(quoteChar); } + private static boolean isLFCRQuoteCharOrEscapeChar(char c, char quoteChar, char escapeChar) { + return c == LF || c == CR || c == quoteChar || c == escapeChar; + } + /** * Always use quotes unless QuoteMode is NONE, so we do not have to look ahead. * From 5f58cecf1037cbaa4287ce361fbc0aeacfbb5d0e Mon Sep 17 00:00:00 2001 From: Ivan Capobianco Date: Mon, 27 Nov 2023 09:48:08 +0100 Subject: [PATCH 15/18] fix: sonarcloud code smell fix 6 --- src/main/java/org/apache/commons/csv/CSVFormat.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index 68f29b2355..128302c9a4 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -2333,7 +2333,7 @@ private void printWithQuotes(final Object object, final CharSequence charSeq, fi // the need for encapsulation. while (pos < len) { final char c = charSeq.charAt(pos); - if (c == quoteChar || c == escapeChar) { + if (isQuoteCharOrEscapeChar(c, quoteChar, escapeChar)) { // write out the chunk up until this point out.append(charSeq, start, pos); out.append(escapeChar); // now output the escape @@ -2351,6 +2351,11 @@ private static boolean isLFCRQuoteCharOrEscapeChar(char c, char quoteChar, char return c == LF || c == CR || c == quoteChar || c == escapeChar; } + private static boolean isQuoteCharOrEscapeChar(char c, char quoteChar, char escapeChar) { + return c == quoteChar || c == escapeChar; + + } + /** * Always use quotes unless QuoteMode is NONE, so we do not have to look ahead. * From 4f4be38b6e0ebd90e7ab7e3ced2e21ac6c73bc03 Mon Sep 17 00:00:00 2001 From: Ivan Capobianco Date: Mon, 27 Nov 2023 10:35:24 +0100 Subject: [PATCH 16/18] fix: sonarcloud code smell --- .../java/org/apache/commons/csv/CSVDuplicateHeaderTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/apache/commons/csv/CSVDuplicateHeaderTest.java b/src/test/java/org/apache/commons/csv/CSVDuplicateHeaderTest.java index 9eae51b055..fafb2ff5b1 100644 --- a/src/test/java/org/apache/commons/csv/CSVDuplicateHeaderTest.java +++ b/src/test/java/org/apache/commons/csv/CSVDuplicateHeaderTest.java @@ -32,7 +32,7 @@ * Tests parsing of duplicate column names in a CSV header. * The test verifies that headers are consistently handled by CSVFormat and CSVParser. */ -public class CSVDuplicateHeaderTest { +class CSVDuplicateHeaderTest { /** * Return test cases for duplicate header data for use in CSVFormat. @@ -270,7 +270,7 @@ static Stream duplicateHeaderData() { */ @ParameterizedTest @MethodSource(value = {"duplicateHeaderAllowsMissingColumnsNamesData"}) - public void testCSVFormat(final DuplicateHeaderMode duplicateHeaderMode, + void testCSVFormat(final DuplicateHeaderMode duplicateHeaderMode, final boolean allowMissingColumnNames, final boolean ignoreHeaderCase, final String[] headers, @@ -303,7 +303,7 @@ public void testCSVFormat(final DuplicateHeaderMode duplicateHeaderMode, */ @ParameterizedTest @MethodSource(value = {"duplicateHeaderData"}) - public void testCSVParser(final DuplicateHeaderMode duplicateHeaderMode, + void testCSVParser(final DuplicateHeaderMode duplicateHeaderMode, final boolean allowMissingColumnNames, final boolean ignoreHeaderCase, final String[] headers, From 2fd681cd8655a752e9289a2d1d993e6d95c3ab5a Mon Sep 17 00:00:00 2001 From: Ivan Capobianco Date: Mon, 27 Nov 2023 10:58:22 +0100 Subject: [PATCH 17/18] fix: sonarcloud code smell public test method --- .../apache/commons/csv/CSVFileParserTest.java | 4 +- .../commons/csv/CSVFormatPredefinedTest.java | 22 +- .../org/apache/commons/csv/CSVFormatTest.java | 212 ++++++++-------- .../org/apache/commons/csv/CSVParserTest.java | 234 +++++++++--------- .../apache/commons/csv/CSVPrinterTest.java | 232 ++++++++--------- .../org/apache/commons/csv/CSVRecordTest.java | 66 ++--- .../csv/ExtendedBufferedReaderTest.java | 14 +- .../org/apache/commons/csv/LexerTest.java | 66 ++--- 8 files changed, 425 insertions(+), 425 deletions(-) diff --git a/src/test/java/org/apache/commons/csv/CSVFileParserTest.java b/src/test/java/org/apache/commons/csv/CSVFileParserTest.java index 4d9b87118f..638ef46b82 100644 --- a/src/test/java/org/apache/commons/csv/CSVFileParserTest.java +++ b/src/test/java/org/apache/commons/csv/CSVFileParserTest.java @@ -57,7 +57,7 @@ private String readTestData(final BufferedReader reader) throws IOException { @ParameterizedTest @MethodSource("generateData") - public void testCSVFile(final File testFile) throws Exception { + void testCSVFile(final File testFile) throws Exception { try (FileReader fr = new FileReader(testFile); BufferedReader testData = new BufferedReader(fr)) { String line = readTestData(testData); assertNotNull("file must contain config line", line); @@ -102,7 +102,7 @@ public void testCSVFile(final File testFile) throws Exception { @ParameterizedTest @MethodSource("generateData") - public void testCSVUrl(final File testFile) throws Exception { + void testCSVUrl(final File testFile) throws Exception { try (FileReader fr = new FileReader(testFile); BufferedReader testData = new BufferedReader(fr)) { String line = readTestData(testData); assertNotNull("file must contain config line", line); diff --git a/src/test/java/org/apache/commons/csv/CSVFormatPredefinedTest.java b/src/test/java/org/apache/commons/csv/CSVFormatPredefinedTest.java index d62f41f3cb..9c54c70243 100644 --- a/src/test/java/org/apache/commons/csv/CSVFormatPredefinedTest.java +++ b/src/test/java/org/apache/commons/csv/CSVFormatPredefinedTest.java @@ -24,7 +24,7 @@ /** * Tests {@link CSVFormat.Predefined}. */ -public class CSVFormatPredefinedTest { +class CSVFormatPredefinedTest { private void test(final CSVFormat format, final String enumName) { assertEquals(format, CSVFormat.Predefined.valueOf(enumName).getFormat()); @@ -32,52 +32,52 @@ private void test(final CSVFormat format, final String enumName) { } @Test - public void testDefault() { + void testDefault() { test(CSVFormat.DEFAULT, "Default"); } @Test - public void testExcel() { + void testExcel() { test(CSVFormat.EXCEL, "Excel"); } @Test - public void testMongoDbCsv() { + void testMongoDbCsv() { test(CSVFormat.MONGODB_CSV, "MongoDBCsv"); } @Test - public void testMongoDbTsv() { + void testMongoDbTsv() { test(CSVFormat.MONGODB_TSV, "MongoDBTsv"); } @Test - public void testMySQL() { + void testMySQL() { test(CSVFormat.MYSQL, "MySQL"); } @Test - public void testOracle() { + void testOracle() { test(CSVFormat.ORACLE, "Oracle"); } @Test - public void testPostgreSqlCsv() { + void testPostgreSqlCsv() { test(CSVFormat.POSTGRESQL_CSV, "PostgreSQLCsv"); } @Test - public void testPostgreSqlText() { + void testPostgreSqlText() { test(CSVFormat.POSTGRESQL_TEXT, "PostgreSQLText"); } @Test - public void testRFC4180() { + void testRFC4180() { test(CSVFormat.RFC4180, "RFC4180"); } @Test - public void testTDF() { + void testTDF() { test(CSVFormat.TDF, "TDF"); } } diff --git a/src/test/java/org/apache/commons/csv/CSVFormatTest.java b/src/test/java/org/apache/commons/csv/CSVFormatTest.java index e3a284f76d..af3127e52f 100644 --- a/src/test/java/org/apache/commons/csv/CSVFormatTest.java +++ b/src/test/java/org/apache/commons/csv/CSVFormatTest.java @@ -52,7 +52,7 @@ /** * Tests {@link CSVFormat}. */ -public class CSVFormatTest { +class CSVFormatTest { public enum EmptyEnum { // empty enum. @@ -81,39 +81,39 @@ private void assertNotEquals(final String name, final String type, final Object } @Test - public void testDelimiterEmptyStringThrowsException1() { + void testDelimiterEmptyStringThrowsException1() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter("").build()); } @SuppressWarnings("deprecation") @Test - public void testDelimiterSameAsCommentStartThrowsException_Deprecated() { + void testDelimiterSameAsCommentStartThrowsException_Deprecated() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withDelimiter('!').withCommentMarker('!')); } @Test - public void testDelimiterSameAsCommentStartThrowsException1() { + void testDelimiterSameAsCommentStartThrowsException1() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter('!').setCommentMarker('!').build()); } @SuppressWarnings("deprecation") @Test - public void testDelimiterSameAsEscapeThrowsException_Deprecated() { + void testDelimiterSameAsEscapeThrowsException_Deprecated() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withDelimiter('!').withEscape('!')); } @Test - public void testDelimiterSameAsEscapeThrowsException1() { + void testDelimiterSameAsEscapeThrowsException1() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter('!').setEscape('!').build()); } @Test - public void testDelimiterSameAsRecordSeparatorThrowsException() { + void testDelimiterSameAsRecordSeparatorThrowsException() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.newFormat(CR)); } @Test - public void testDuplicateHeaderElements() { + void testDuplicateHeaderElements() { final String[] header = { "A", "A" }; final CSVFormat format = CSVFormat.DEFAULT.builder().setHeader(header).build(); assertEquals(2, format.getHeader().length); @@ -122,7 +122,7 @@ public void testDuplicateHeaderElements() { @SuppressWarnings("deprecation") @Test - public void testDuplicateHeaderElements_Deprecated() { + void testDuplicateHeaderElements_Deprecated() { final String[] header = { "A", "A" }; final CSVFormat format = CSVFormat.DEFAULT.withHeader(header); assertEquals(2, format.getHeader().length); @@ -130,44 +130,44 @@ public void testDuplicateHeaderElements_Deprecated() { } @Test - public void testDuplicateHeaderElementsFalse() { + void testDuplicateHeaderElementsFalse() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setAllowDuplicateHeaderNames(false).setHeader("A", "A").build()); } @SuppressWarnings("deprecation") @Test - public void testDuplicateHeaderElementsFalse_Deprecated() { + void testDuplicateHeaderElementsFalse_Deprecated() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withAllowDuplicateHeaderNames(false).withHeader("A", "A")); } @Test - public void testDuplicateHeaderElementsTrue() { + void testDuplicateHeaderElementsTrue() { CSVFormat.DEFAULT.builder().setAllowDuplicateHeaderNames(true).setHeader("A", "A").build(); } @SuppressWarnings("deprecation") @Test - public void testDuplicateHeaderElementsTrue_Deprecated() { + void testDuplicateHeaderElementsTrue_Deprecated() { CSVFormat.DEFAULT.withAllowDuplicateHeaderNames(true).withHeader("A", "A"); } @Test - public void testDuplicateHeaderElementsTrueContainsEmpty1() { + void testDuplicateHeaderElementsTrueContainsEmpty1() { CSVFormat.DEFAULT.builder().setAllowDuplicateHeaderNames(false).setHeader("A", "", "B", "").build(); } @Test - public void testDuplicateHeaderElementsTrueContainsEmpty2() { + void testDuplicateHeaderElementsTrueContainsEmpty2() { CSVFormat.DEFAULT.builder().setDuplicateHeaderMode(DuplicateHeaderMode.ALLOW_EMPTY).setHeader("A", "", "B", "").build(); } @Test - public void testDuplicateHeaderElementsTrueContainsEmpty3() { + void testDuplicateHeaderElementsTrueContainsEmpty3() { CSVFormat.DEFAULT.builder().setAllowDuplicateHeaderNames(false).setAllowMissingColumnNames(true).setHeader("A", "", "B", "").build(); } @Test - public void testEquals() { + void testEquals() { final CSVFormat right = CSVFormat.DEFAULT; final CSVFormat left = copy(right); @@ -183,7 +183,7 @@ public void testEquals() { } @Test - public void testEqualsCommentStart() { + void testEqualsCommentStart() { final CSVFormat right = CSVFormat.newFormat('\'').builder().setQuote('"').setCommentMarker('#').setQuoteMode(QuoteMode.ALL).build(); final CSVFormat left = right.builder().setCommentMarker('!').build(); @@ -192,7 +192,7 @@ public void testEqualsCommentStart() { @SuppressWarnings("deprecation") @Test - public void testEqualsCommentStart_Deprecated() { + void testEqualsCommentStart_Deprecated() { final CSVFormat right = CSVFormat.newFormat('\'').withQuote('"').withCommentMarker('#').withQuoteMode(QuoteMode.ALL); final CSVFormat left = right.withCommentMarker('!'); @@ -200,7 +200,7 @@ public void testEqualsCommentStart_Deprecated() { } @Test - public void testEqualsDelimiter() { + void testEqualsDelimiter() { final CSVFormat right = CSVFormat.newFormat('!'); final CSVFormat left = CSVFormat.newFormat('?'); @@ -208,7 +208,7 @@ public void testEqualsDelimiter() { } @Test - public void testEqualsEscape() { + void testEqualsEscape() { final CSVFormat right = CSVFormat.newFormat('\'').builder().setQuote('"').setCommentMarker('#').setEscape('+').setQuoteMode(QuoteMode.ALL).build(); final CSVFormat left = right.builder().setEscape('!').build(); @@ -217,7 +217,7 @@ public void testEqualsEscape() { @SuppressWarnings("deprecation") @Test - public void testEqualsEscape_Deprecated() { + void testEqualsEscape_Deprecated() { final CSVFormat right = CSVFormat.newFormat('\'').withQuote('"').withCommentMarker('#').withEscape('+').withQuoteMode(QuoteMode.ALL); final CSVFormat left = right.withEscape('!'); @@ -225,7 +225,7 @@ public void testEqualsEscape_Deprecated() { } @Test - public void testEqualsHash() throws Exception { + void testEqualsHash() throws Exception { final Method[] methods = CSVFormat.class.getDeclaredMethods(); for (final Method method : methods) { if (Modifier.isPublic(method.getModifiers())) { @@ -277,7 +277,7 @@ public void testEqualsHash() throws Exception { } @Test - public void testEqualsHeader() { + void testEqualsHeader() { final CSVFormat right = CSVFormat.newFormat('\'').builder().setRecordSeparator(CR).setCommentMarker('#').setEscape('+').setHeader("One", "Two", "Three") .setIgnoreEmptyLines(true).setIgnoreSurroundingSpaces(true).setQuote('"').setQuoteMode(QuoteMode.ALL).build(); final CSVFormat left = right.builder().setHeader("Three", "Two", "One").build(); @@ -287,7 +287,7 @@ public void testEqualsHeader() { @SuppressWarnings("deprecation") @Test - public void testEqualsHeader_Deprecated() { + void testEqualsHeader_Deprecated() { final CSVFormat right = CSVFormat.newFormat('\'').withRecordSeparator(CR).withCommentMarker('#').withEscape('+').withHeader("One", "Two", "Three") .withIgnoreEmptyLines().withIgnoreSurroundingSpaces().withQuote('"').withQuoteMode(QuoteMode.ALL); final CSVFormat left = right.withHeader("Three", "Two", "One"); @@ -296,7 +296,7 @@ public void testEqualsHeader_Deprecated() { } @Test - public void testEqualsIgnoreEmptyLines() { + void testEqualsIgnoreEmptyLines() { final CSVFormat right = CSVFormat.newFormat('\'').builder().setCommentMarker('#').setEscape('+').setIgnoreEmptyLines(true) .setIgnoreSurroundingSpaces(true).setQuote('"').setQuoteMode(QuoteMode.ALL).build(); final CSVFormat left = right.builder().setIgnoreEmptyLines(false).build(); @@ -306,7 +306,7 @@ public void testEqualsIgnoreEmptyLines() { @SuppressWarnings("deprecation") @Test - public void testEqualsIgnoreEmptyLines_Deprecated() { + void testEqualsIgnoreEmptyLines_Deprecated() { final CSVFormat right = CSVFormat.newFormat('\'').withCommentMarker('#').withEscape('+').withIgnoreEmptyLines().withIgnoreSurroundingSpaces() .withQuote('"').withQuoteMode(QuoteMode.ALL); final CSVFormat left = right.withIgnoreEmptyLines(false); @@ -315,7 +315,7 @@ public void testEqualsIgnoreEmptyLines_Deprecated() { } @Test - public void testEqualsIgnoreSurroundingSpaces() { + void testEqualsIgnoreSurroundingSpaces() { final CSVFormat right = CSVFormat.newFormat('\'').builder().setCommentMarker('#').setEscape('+').setIgnoreSurroundingSpaces(true).setQuote('"') .setQuoteMode(QuoteMode.ALL).build(); final CSVFormat left = right.builder().setIgnoreSurroundingSpaces(false).build(); @@ -325,7 +325,7 @@ public void testEqualsIgnoreSurroundingSpaces() { @SuppressWarnings("deprecation") @Test - public void testEqualsIgnoreSurroundingSpaces_Deprecated() { + void testEqualsIgnoreSurroundingSpaces_Deprecated() { final CSVFormat right = CSVFormat.newFormat('\'').withCommentMarker('#').withEscape('+').withIgnoreSurroundingSpaces().withQuote('"') .withQuoteMode(QuoteMode.ALL); final CSVFormat left = right.withIgnoreSurroundingSpaces(false); @@ -334,7 +334,7 @@ public void testEqualsIgnoreSurroundingSpaces_Deprecated() { } @Test - public void testEqualsLeftNoQuoteRightQuote() { + void testEqualsLeftNoQuoteRightQuote() { final CSVFormat left = CSVFormat.newFormat(',').builder().setQuote(null).build(); final CSVFormat right = left.builder().setQuote('#').build(); @@ -343,7 +343,7 @@ public void testEqualsLeftNoQuoteRightQuote() { @SuppressWarnings("deprecation") @Test - public void testEqualsLeftNoQuoteRightQuote_Deprecated() { + void testEqualsLeftNoQuoteRightQuote_Deprecated() { final CSVFormat left = CSVFormat.newFormat(',').withQuote(null); final CSVFormat right = left.withQuote('#'); @@ -351,7 +351,7 @@ public void testEqualsLeftNoQuoteRightQuote_Deprecated() { } @Test - public void testEqualsNoQuotes() { + void testEqualsNoQuotes() { final CSVFormat left = CSVFormat.newFormat(',').builder().setQuote(null).build(); final CSVFormat right = left.builder().setQuote(null).build(); @@ -360,7 +360,7 @@ public void testEqualsNoQuotes() { @SuppressWarnings("deprecation") @Test - public void testEqualsNoQuotes_Deprecated() { + void testEqualsNoQuotes_Deprecated() { final CSVFormat left = CSVFormat.newFormat(',').withQuote(null); final CSVFormat right = left.withQuote(null); @@ -368,7 +368,7 @@ public void testEqualsNoQuotes_Deprecated() { } @Test - public void testEqualsNullString() { + void testEqualsNullString() { final CSVFormat right = CSVFormat.newFormat('\'').builder().setRecordSeparator(CR).setCommentMarker('#').setEscape('+').setIgnoreEmptyLines(true) .setIgnoreSurroundingSpaces(true).setQuote('"').setQuoteMode(QuoteMode.ALL).setNullString("null").build(); final CSVFormat left = right.builder().setNullString("---").build(); @@ -378,7 +378,7 @@ public void testEqualsNullString() { @SuppressWarnings("deprecation") @Test - public void testEqualsNullString_Deprecated() { + void testEqualsNullString_Deprecated() { final CSVFormat right = CSVFormat.newFormat('\'').withRecordSeparator(CR).withCommentMarker('#').withEscape('+').withIgnoreEmptyLines() .withIgnoreSurroundingSpaces().withQuote('"').withQuoteMode(QuoteMode.ALL).withNullString("null"); final CSVFormat left = right.withNullString("---"); @@ -387,7 +387,7 @@ public void testEqualsNullString_Deprecated() { } @Test - public void testEqualsOne() { + void testEqualsOne() { final CSVFormat csvFormatOne = CSVFormat.INFORMIX_UNLOAD; final CSVFormat csvFormatTwo = CSVFormat.MYSQL; @@ -514,7 +514,7 @@ public void testEqualsOne() { } @Test - public void testEqualsQuoteChar() { + void testEqualsQuoteChar() { final CSVFormat right = CSVFormat.newFormat('\'').builder().setQuote('"').build(); final CSVFormat left = right.builder().setQuote('!').build(); @@ -523,7 +523,7 @@ public void testEqualsQuoteChar() { @SuppressWarnings("deprecation") @Test - public void testEqualsQuoteChar_Deprecated() { + void testEqualsQuoteChar_Deprecated() { final CSVFormat right = CSVFormat.newFormat('\'').withQuote('"'); final CSVFormat left = right.withQuote('!'); @@ -531,7 +531,7 @@ public void testEqualsQuoteChar_Deprecated() { } @Test - public void testEqualsQuotePolicy() { + void testEqualsQuotePolicy() { final CSVFormat right = CSVFormat.newFormat('\'').builder().setQuote('"').setQuoteMode(QuoteMode.ALL).build(); final CSVFormat left = right.builder().setQuoteMode(QuoteMode.MINIMAL).build(); @@ -540,7 +540,7 @@ public void testEqualsQuotePolicy() { @SuppressWarnings("deprecation") @Test - public void testEqualsQuotePolicy_Deprecated() { + void testEqualsQuotePolicy_Deprecated() { final CSVFormat right = CSVFormat.newFormat('\'').withQuote('"').withQuoteMode(QuoteMode.ALL); final CSVFormat left = right.withQuoteMode(QuoteMode.MINIMAL); @@ -548,7 +548,7 @@ public void testEqualsQuotePolicy_Deprecated() { } @Test - public void testEqualsRecordSeparator() { + void testEqualsRecordSeparator() { final CSVFormat right = CSVFormat.newFormat('\'').builder().setRecordSeparator(CR).setCommentMarker('#').setEscape('+').setIgnoreEmptyLines(true) .setIgnoreSurroundingSpaces(true).setQuote('"').setQuoteMode(QuoteMode.ALL).build(); final CSVFormat left = right.builder().setRecordSeparator(LF).build(); @@ -558,7 +558,7 @@ public void testEqualsRecordSeparator() { @SuppressWarnings("deprecation") @Test - public void testEqualsRecordSeparator_Deprecated() { + void testEqualsRecordSeparator_Deprecated() { final CSVFormat right = CSVFormat.newFormat('\'').withRecordSeparator(CR).withCommentMarker('#').withEscape('+').withIgnoreEmptyLines() .withIgnoreSurroundingSpaces().withQuote('"').withQuoteMode(QuoteMode.ALL); final CSVFormat left = right.withRecordSeparator(LF); @@ -566,7 +566,7 @@ public void testEqualsRecordSeparator_Deprecated() { assertNotEquals(right, left); } - public void testEqualsSkipHeaderRecord() { + void testEqualsSkipHeaderRecord() { final CSVFormat right = CSVFormat.newFormat('\'').builder().setRecordSeparator(CR).setCommentMarker('#').setEscape('+').setIgnoreEmptyLines(true) .setIgnoreSurroundingSpaces(true).setQuote('"').setQuoteMode(QuoteMode.ALL).setNullString("null").setSkipHeaderRecord(true).build(); final CSVFormat left = right.builder().setSkipHeaderRecord(false).build(); @@ -576,7 +576,7 @@ public void testEqualsSkipHeaderRecord() { @SuppressWarnings("deprecation") @Test - public void testEqualsSkipHeaderRecord_Deprecated() { + void testEqualsSkipHeaderRecord_Deprecated() { final CSVFormat right = CSVFormat.newFormat('\'').withRecordSeparator(CR).withCommentMarker('#').withEscape('+').withIgnoreEmptyLines() .withIgnoreSurroundingSpaces().withQuote('"').withQuoteMode(QuoteMode.ALL).withNullString("null").withSkipHeaderRecord(); final CSVFormat left = right.withSkipHeaderRecord(false); @@ -585,7 +585,7 @@ public void testEqualsSkipHeaderRecord_Deprecated() { } @Test - public void testEqualsWithNull() { + void testEqualsWithNull() { final CSVFormat csvFormat = CSVFormat.POSTGRESQL_TEXT; @@ -648,18 +648,18 @@ public void testEqualsWithNull() { } @Test - public void testEscapeSameAsCommentStartThrowsException() { + void testEscapeSameAsCommentStartThrowsException() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setEscape('!').setCommentMarker('!').build()); } @SuppressWarnings("deprecation") @Test - public void testEscapeSameAsCommentStartThrowsException_Deprecated() { + void testEscapeSameAsCommentStartThrowsException_Deprecated() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withEscape('!').withCommentMarker('!')); } @Test - public void testEscapeSameAsCommentStartThrowsExceptionForWrapperType() { + void testEscapeSameAsCommentStartThrowsExceptionForWrapperType() { // Cannot assume that callers won't use different Character objects assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setEscape(Character.valueOf('!')).setCommentMarker(Character.valueOf('!')).build()); @@ -667,13 +667,13 @@ public void testEscapeSameAsCommentStartThrowsExceptionForWrapperType() { @SuppressWarnings("deprecation") @Test - public void testEscapeSameAsCommentStartThrowsExceptionForWrapperType_Deprecated() { + void testEscapeSameAsCommentStartThrowsExceptionForWrapperType_Deprecated() { // Cannot assume that callers won't use different Character objects assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withEscape(Character.valueOf('!')).withCommentMarker(Character.valueOf('!'))); } @Test - public void testFormat() { + void testFormat() { final CSVFormat format = CSVFormat.DEFAULT; assertEquals("", format.format()); @@ -682,7 +682,7 @@ public void testFormat() { } @Test // I assume this to be a defect. - public void testFormatThrowsNullPointerException() { + void testFormatThrowsNullPointerException() { final CSVFormat csvFormat = CSVFormat.MYSQL; @@ -691,7 +691,7 @@ public void testFormatThrowsNullPointerException() { } @Test - public void testFormatToString() { + void testFormatToString() { final CSVFormat format = CSVFormat.RFC4180.withEscape('?').withDelimiter(',').withQuoteMode(QuoteMode.MINIMAL).withRecordSeparator(CRLF).withQuote('"') .withNullString("").withIgnoreHeaderCase(true).withHeaderComments("This is HeaderComments").withHeader("col1", "col2", "col3"); assertEquals( @@ -701,7 +701,7 @@ public void testFormatToString() { } @Test - public void testGetAllowDuplicateHeaderNames() { + void testGetAllowDuplicateHeaderNames() { final Builder builder = CSVFormat.DEFAULT.builder(); assertTrue(builder.build().getAllowDuplicateHeaderNames()); assertTrue(builder.setDuplicateHeaderMode(DuplicateHeaderMode.ALLOW_ALL).build().getAllowDuplicateHeaderNames()); @@ -710,7 +710,7 @@ public void testGetAllowDuplicateHeaderNames() { } @Test - public void testGetDuplicateHeaderMode() { + void testGetDuplicateHeaderMode() { final Builder builder = CSVFormat.DEFAULT.builder(); assertEquals(DuplicateHeaderMode.ALLOW_ALL, builder.build().getDuplicateHeaderMode()); @@ -720,7 +720,7 @@ public void testGetDuplicateHeaderMode() { } @Test - public void testGetHeader() { + void testGetHeader() { final String[] header = { "one", "two", "three" }; final CSVFormat formatWithHeader = CSVFormat.DEFAULT.withHeader(header); // getHeader() makes a copy of the header array. @@ -733,7 +733,7 @@ public void testGetHeader() { } @Test - public void testHashCodeAndWithIgnoreHeaderCase() { + void testHashCodeAndWithIgnoreHeaderCase() { final CSVFormat csvFormat = CSVFormat.INFORMIX_UNLOAD_CSV; final CSVFormat csvFormatTwo = csvFormat.withIgnoreHeaderCase(); @@ -751,18 +751,18 @@ public void testHashCodeAndWithIgnoreHeaderCase() { } @Test - public void testJiraCsv236() { + void testJiraCsv236() { CSVFormat.DEFAULT.builder().setAllowDuplicateHeaderNames(true).setHeader("CC", "VV", "VV").build(); } @SuppressWarnings("deprecation") @Test - public void testJiraCsv236__Deprecated() { + void testJiraCsv236__Deprecated() { CSVFormat.DEFAULT.withAllowDuplicateHeaderNames().withHeader("CC", "VV", "VV"); } @Test - public void testNewFormat() { + void testNewFormat() { final CSVFormat csvFormat = CSVFormat.newFormat('X'); @@ -823,7 +823,7 @@ public void testNewFormat() { } @Test - public void testNullRecordSeparatorCsv106() { + void testNullRecordSeparatorCsv106() { final CSVFormat format = CSVFormat.newFormat(';').builder().setSkipHeaderRecord(true).setHeader("H1", "H2").build(); final String formatStr = format.format("A", "B"); assertNotNull(formatStr); @@ -832,7 +832,7 @@ public void testNullRecordSeparatorCsv106() { @SuppressWarnings("deprecation") @Test - public void testNullRecordSeparatorCsv106__Deprecated() { + void testNullRecordSeparatorCsv106__Deprecated() { final CSVFormat format = CSVFormat.newFormat(';').withSkipHeaderRecord().withHeader("H1", "H2"); final String formatStr = format.format("A", "B"); assertNotNull(formatStr); @@ -840,7 +840,7 @@ public void testNullRecordSeparatorCsv106__Deprecated() { } @Test - public void testPrintRecord() throws IOException { + void testPrintRecord() throws IOException { final Appendable out = new StringBuilder(); final CSVFormat format = CSVFormat.RFC4180; format.printRecord(out, "a", "b", "c"); @@ -848,7 +848,7 @@ public void testPrintRecord() throws IOException { } @Test - public void testPrintRecordEmpty() throws IOException { + void testPrintRecordEmpty() throws IOException { final Appendable out = new StringBuilder(); final CSVFormat format = CSVFormat.RFC4180; format.printRecord(out); @@ -856,7 +856,7 @@ public void testPrintRecordEmpty() throws IOException { } @Test - public void testPrintWithEscapesEndWithCRLF() throws IOException { + void testPrintWithEscapesEndWithCRLF() throws IOException { final Reader in = new StringReader("x,y,x\r\na,?b,c\r\n"); final Appendable out = new StringBuilder(); final CSVFormat format = CSVFormat.RFC4180.withEscape('?').withDelimiter(',').withQuote(null).withRecordSeparator(CRLF); @@ -865,7 +865,7 @@ public void testPrintWithEscapesEndWithCRLF() throws IOException { } @Test - public void testPrintWithEscapesEndWithoutCRLF() throws IOException { + void testPrintWithEscapesEndWithoutCRLF() throws IOException { final Reader in = new StringReader("x,y,x"); final Appendable out = new StringBuilder(); final CSVFormat format = CSVFormat.RFC4180.withEscape('?').withDelimiter(',').withQuote(null).withRecordSeparator(CRLF); @@ -874,7 +874,7 @@ public void testPrintWithEscapesEndWithoutCRLF() throws IOException { } @Test - public void testPrintWithoutQuotes() throws IOException { + void testPrintWithoutQuotes() throws IOException { final Reader in = new StringReader(""); final Appendable out = new StringBuilder(); final CSVFormat format = CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NON_NUMERIC); @@ -883,7 +883,7 @@ public void testPrintWithoutQuotes() throws IOException { } @Test - public void testPrintWithQuoteModeIsNONE() throws IOException { + void testPrintWithQuoteModeIsNONE() throws IOException { final Reader in = new StringReader("a,b,c"); final Appendable out = new StringBuilder(); final CSVFormat format = CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NONE); @@ -892,7 +892,7 @@ public void testPrintWithQuoteModeIsNONE() throws IOException { } @Test - public void testPrintWithQuotes() throws IOException { + void testPrintWithQuotes() throws IOException { final Reader in = new StringReader("\"a,b,c\r\nx,y,z"); final Appendable out = new StringBuilder(); final CSVFormat format = CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NON_NUMERIC); @@ -901,42 +901,42 @@ public void testPrintWithQuotes() throws IOException { } @Test - public void testQuoteCharSameAsCommentStartThrowsException() { + void testQuoteCharSameAsCommentStartThrowsException() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setQuote('!').setCommentMarker('!').build()); } @SuppressWarnings("deprecation") @Test - public void testQuoteCharSameAsCommentStartThrowsException_Deprecated() { + void testQuoteCharSameAsCommentStartThrowsException_Deprecated() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withQuote('!').withCommentMarker('!')); } @Test - public void testQuoteCharSameAsCommentStartThrowsExceptionForWrapperType() { + void testQuoteCharSameAsCommentStartThrowsExceptionForWrapperType() { // Cannot assume that callers won't use different Character objects assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setQuote(Character.valueOf('!')).setCommentMarker('!').build()); } @SuppressWarnings("deprecation") @Test - public void testQuoteCharSameAsCommentStartThrowsExceptionForWrapperType_Deprecated() { + void testQuoteCharSameAsCommentStartThrowsExceptionForWrapperType_Deprecated() { // Cannot assume that callers won't use different Character objects assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withQuote(Character.valueOf('!')).withCommentMarker('!')); } @Test - public void testQuoteCharSameAsDelimiterThrowsException() { + void testQuoteCharSameAsDelimiterThrowsException() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setQuote('!').setDelimiter('!').build()); } @SuppressWarnings("deprecation") @Test - public void testQuoteCharSameAsDelimiterThrowsException_Deprecated() { + void testQuoteCharSameAsDelimiterThrowsException_Deprecated() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withQuote('!').withDelimiter('!')); } @Test - public void testQuoteModeNoneShouldReturnMeaningfulExceptionMessage() { + void testQuoteModeNoneShouldReturnMeaningfulExceptionMessage() { Exception exception = assertThrows(IllegalArgumentException.class, () -> { CSVFormat.DEFAULT.builder() .setHeader("Col1", "Col2", "Col3", "Col4") @@ -949,18 +949,18 @@ public void testQuoteModeNoneShouldReturnMeaningfulExceptionMessage() { } @Test - public void testQuotePolicyNoneWithoutEscapeThrowsException() { + void testQuotePolicyNoneWithoutEscapeThrowsException() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.newFormat('!').builder().setQuoteMode(QuoteMode.NONE).build()); } @SuppressWarnings("deprecation") @Test - public void testQuotePolicyNoneWithoutEscapeThrowsException_Deprecated() { + void testQuotePolicyNoneWithoutEscapeThrowsException_Deprecated() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.newFormat('!').withQuoteMode(QuoteMode.NONE)); } @Test - public void testRFC4180() { + void testRFC4180() { assertNull(RFC4180.getCommentMarker()); assertEquals(',', RFC4180.getDelimiter()); assertNull(RFC4180.getEscapeCharacter()); @@ -972,7 +972,7 @@ public void testRFC4180() { @SuppressWarnings("boxing") // no need to worry about boxing here @Test - public void testSerialization() throws Exception { + void testSerialization() throws Exception { final ByteArrayOutputStream out = new ByteArrayOutputStream(); try (final ObjectOutputStream oos = new ObjectOutputStream(out)) { @@ -994,7 +994,7 @@ public void testSerialization() throws Exception { } @Test - public void testToString() { + void testToString() { final String string = CSVFormat.INFORMIX_UNLOAD.toString(); @@ -1003,7 +1003,7 @@ public void testToString() { } @Test - public void testToStringAndWithCommentMarkerTakingCharacter() { + void testToStringAndWithCommentMarkerTakingCharacter() { final CSVFormat.Predefined csvFormat_Predefined = CSVFormat.Predefined.Default; final CSVFormat csvFormat = csvFormat_Predefined.getFormat(); @@ -1164,7 +1164,7 @@ public void testToStringAndWithCommentMarkerTakingCharacter() { } @Test - public void testTrim() throws IOException { + void testTrim() throws IOException { final CSVFormat formatWithTrim = CSVFormat.DEFAULT.withDelimiter(',').withTrim().withQuote(null).withRecordSeparator(CRLF); CharSequence in = "a,b,c"; @@ -1189,29 +1189,29 @@ public void testTrim() throws IOException { } @Test - public void testWithCommentStart() { + void testWithCommentStart() { final CSVFormat formatWithCommentStart = CSVFormat.DEFAULT.withCommentMarker('#'); assertEquals(Character.valueOf('#'), formatWithCommentStart.getCommentMarker()); } @Test - public void testWithCommentStartCRThrowsException() { + void testWithCommentStartCRThrowsException() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withCommentMarker(CR)); } @Test - public void testWithDelimiter() { + void testWithDelimiter() { final CSVFormat formatWithDelimiter = CSVFormat.DEFAULT.withDelimiter('!'); assertEquals('!', formatWithDelimiter.getDelimiter()); } @Test - public void testWithDelimiterLFThrowsException() { + void testWithDelimiterLFThrowsException() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withDelimiter(LF)); } @Test - public void testWithEmptyDuplicates() { + void testWithEmptyDuplicates() { final CSVFormat formatWithEmptyDuplicates = CSVFormat.DEFAULT.builder().setDuplicateHeaderMode(DuplicateHeaderMode.ALLOW_EMPTY).build(); assertEquals(DuplicateHeaderMode.ALLOW_EMPTY, formatWithEmptyDuplicates.getDuplicateHeaderMode()); @@ -1219,31 +1219,31 @@ public void testWithEmptyDuplicates() { } @Test - public void testWithEmptyEnum() { + void testWithEmptyEnum() { final CSVFormat formatWithHeader = CSVFormat.DEFAULT.withHeader(EmptyEnum.class); assertEquals(0, formatWithHeader.getHeader().length); } @Test - public void testWithEscape() { + void testWithEscape() { final CSVFormat formatWithEscape = CSVFormat.DEFAULT.withEscape('&'); assertEquals(Character.valueOf('&'), formatWithEscape.getEscapeCharacter()); } @Test - public void testWithEscapeCRThrowsExceptions() { + void testWithEscapeCRThrowsExceptions() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withEscape(CR)); } @Test - public void testWithFirstRecordAsHeader() { + void testWithFirstRecordAsHeader() { final CSVFormat formatWithFirstRecordAsHeader = CSVFormat.DEFAULT.withFirstRecordAsHeader(); assertTrue(formatWithFirstRecordAsHeader.getSkipHeaderRecord()); assertEquals(0, formatWithFirstRecordAsHeader.getHeader().length); } @Test - public void testWithHeader() { + void testWithHeader() { final String[] header = { "one", "two", "three" }; // withHeader() makes a copy of the header array. final CSVFormat formatWithHeader = CSVFormat.DEFAULT.withHeader(header); @@ -1252,7 +1252,7 @@ public void testWithHeader() { } @Test - public void testWithHeaderComments() { + void testWithHeaderComments() { final CSVFormat csvFormat = CSVFormat.DEFAULT; @@ -1413,80 +1413,80 @@ public void testWithHeaderComments() { } @Test - public void testWithHeaderEnum() { + void testWithHeaderEnum() { final CSVFormat formatWithHeader = CSVFormat.DEFAULT.withHeader(Header.class); assertArrayEquals(new String[] { "Name", "Email", "Phone" }, formatWithHeader.getHeader()); } @Test - public void testWithHeaderEnumNull() { + void testWithHeaderEnumNull() { final CSVFormat format = CSVFormat.DEFAULT; final Class> simpleName = null; format.withHeader(simpleName); } @Test - public void testWithHeaderResultSetNull() throws SQLException { + void testWithHeaderResultSetNull() throws SQLException { final CSVFormat format = CSVFormat.DEFAULT; final ResultSet resultSet = null; format.withHeader(resultSet); } @Test - public void testWithIgnoreEmptyLines() { + void testWithIgnoreEmptyLines() { assertFalse(CSVFormat.DEFAULT.withIgnoreEmptyLines(false).getIgnoreEmptyLines()); assertTrue(CSVFormat.DEFAULT.withIgnoreEmptyLines().getIgnoreEmptyLines()); } @Test - public void testWithIgnoreSurround() { + void testWithIgnoreSurround() { assertFalse(CSVFormat.DEFAULT.withIgnoreSurroundingSpaces(false).getIgnoreSurroundingSpaces()); assertTrue(CSVFormat.DEFAULT.withIgnoreSurroundingSpaces().getIgnoreSurroundingSpaces()); } @Test - public void testWithNullString() { + void testWithNullString() { final CSVFormat formatWithNullString = CSVFormat.DEFAULT.withNullString("null"); assertEquals("null", formatWithNullString.getNullString()); } @Test - public void testWithQuoteChar() { + void testWithQuoteChar() { final CSVFormat formatWithQuoteChar = CSVFormat.DEFAULT.withQuote('"'); assertEquals(Character.valueOf('"'), formatWithQuoteChar.getQuoteCharacter()); } @Test - public void testWithQuoteLFThrowsException() { + void testWithQuoteLFThrowsException() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withQuote(LF)); } @Test - public void testWithQuotePolicy() { + void testWithQuotePolicy() { final CSVFormat formatWithQuotePolicy = CSVFormat.DEFAULT.withQuoteMode(QuoteMode.ALL); assertEquals(QuoteMode.ALL, formatWithQuotePolicy.getQuoteMode()); } @Test - public void testWithRecordSeparatorCR() { + void testWithRecordSeparatorCR() { final CSVFormat formatWithRecordSeparator = CSVFormat.DEFAULT.withRecordSeparator(CR); assertEquals(String.valueOf(CR), formatWithRecordSeparator.getRecordSeparator()); } @Test - public void testWithRecordSeparatorCRLF() { + void testWithRecordSeparatorCRLF() { final CSVFormat formatWithRecordSeparator = CSVFormat.DEFAULT.withRecordSeparator(CRLF); assertEquals(CRLF, formatWithRecordSeparator.getRecordSeparator()); } @Test - public void testWithRecordSeparatorLF() { + void testWithRecordSeparatorLF() { final CSVFormat formatWithRecordSeparator = CSVFormat.DEFAULT.withRecordSeparator(LF); assertEquals(String.valueOf(LF), formatWithRecordSeparator.getRecordSeparator()); } @Test - public void testWithSystemRecordSeparator() { + void testWithSystemRecordSeparator() { final CSVFormat formatWithRecordSeparator = CSVFormat.DEFAULT.withSystemRecordSeparator(); assertEquals(System.lineSeparator(), formatWithRecordSeparator.getRecordSeparator()); } diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java b/src/test/java/org/apache/commons/csv/CSVParserTest.java index 228dcb9441..11918a09c5 100644 --- a/src/test/java/org/apache/commons/csv/CSVParserTest.java +++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java @@ -64,7 +64,7 @@ * parser section. In case a test fails, you should follow a top-down approach for fixing a potential bug (its likely * that the parser itself fails if the lexer has problems...). */ -public class CSVParserTest { +class CSVParserTest { private static final Charset UTF_8 = StandardCharsets.UTF_8; @@ -126,7 +126,7 @@ private void parseFully(final CSVParser parser) { } @Test - public void testBackslashEscaping() throws IOException { + void testBackslashEscaping() throws IOException { // To avoid confusion over the need for escaping chars in java code, // We will test with a forward slash as the escape char, and a single @@ -164,7 +164,7 @@ public void testBackslashEscaping() throws IOException { } @Test - public void testBackslashEscaping2() throws IOException { + void testBackslashEscaping2() throws IOException { // To avoid confusion over the need for escaping chars in java code, // We will test with a forward slash as the escape char, and a single @@ -191,7 +191,7 @@ public void testBackslashEscaping2() throws IOException { @Test @Disabled - public void testBackslashEscapingOld() throws IOException { + void testBackslashEscapingOld() throws IOException { final String code = "one,two,three\n" + "on\\\"e,two\n" + "on\"e,two\n" + "one,\"tw\\\"o\"\n" + "one,\"t\\,wo\"\n" + "one,two,\"th,ree\"\n" + "\"a\\\\\"\n" + "a\\,b\n" + "\"a\\\\,b\""; final String[][] res = {{"one", "two", "three"}, {"on\\\"e", "two"}, {"on\"e", "two"}, {"one", "tw\"o"}, {"one", "t\\,wo"}, // backslash in quotes only @@ -212,7 +212,7 @@ public void testBackslashEscapingOld() throws IOException { @Test @Disabled("CSV-107") - public void testBOM() throws IOException { + void testBOM() throws IOException { final URL url = ClassLoader.getSystemClassLoader().getResource("org/apache/commons/csv/CSVFileParser/bom.csv"); try (final CSVParser parser = CSVParser.parse(url, Charset.forName(UTF_8_NAME), CSVFormat.EXCEL.withHeader())) { parser.forEach(record -> assertNotNull(record.get("Date"))); @@ -220,7 +220,7 @@ public void testBOM() throws IOException { } @Test - public void testBOMInputStreamParserWithInputStream() throws IOException { + void testBOMInputStreamParserWithInputStream() throws IOException { try (final BOMInputStream inputStream = createBOMInputStream("org/apache/commons/csv/CSVFileParser/bom.csv"); final CSVParser parser = CSVParser.parse(inputStream, UTF_8, CSVFormat.EXCEL.withHeader())) { parser.forEach(record -> assertNotNull(record.get("Date"))); @@ -228,7 +228,7 @@ public void testBOMInputStreamParserWithInputStream() throws IOException { } @Test - public void testBOMInputStreamParserWithReader() throws IOException { + void testBOMInputStreamParserWithReader() throws IOException { try (final Reader reader = new InputStreamReader(createBOMInputStream("org/apache/commons/csv/CSVFileParser/bom.csv"), UTF_8_NAME); final CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader())) { parser.forEach(record -> assertNotNull(record.get("Date"))); @@ -236,7 +236,7 @@ public void testBOMInputStreamParserWithReader() throws IOException { } @Test - public void testBOMInputStreamParseWithReader() throws IOException { + void testBOMInputStreamParseWithReader() throws IOException { try (final Reader reader = new InputStreamReader(createBOMInputStream("org/apache/commons/csv/CSVFileParser/bom.csv"), UTF_8_NAME); final CSVParser parser = CSVParser.parse(reader, CSVFormat.EXCEL.withHeader())) { parser.forEach(record -> assertNotNull(record.get("Date"))); @@ -244,7 +244,7 @@ public void testBOMInputStreamParseWithReader() throws IOException { } @Test - public void testCarriageReturnEndings() throws IOException { + void testCarriageReturnEndings() throws IOException { final String code = "foo\rbaar,\rhello,world\r,kanu"; try (final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT)) { final List records = parser.getRecords(); @@ -253,7 +253,7 @@ public void testCarriageReturnEndings() throws IOException { } @Test - public void testCarriageReturnLineFeedEndings() throws IOException { + void testCarriageReturnLineFeedEndings() throws IOException { final String code = "foo\r\nbaar,\r\nhello,world\r\n,kanu"; try (final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT)) { final List records = parser.getRecords(); @@ -262,7 +262,7 @@ public void testCarriageReturnLineFeedEndings() throws IOException { } @Test - public void testClose() throws Exception { + void testClose() throws Exception { final Reader in = new StringReader("# comment\na,b,c\n1,2,3\nx,y,z"); final Iterator records; try (final CSVParser parser = CSVFormat.DEFAULT.withCommentMarker('#').withHeader().parse(in)) { @@ -274,34 +274,34 @@ public void testClose() throws Exception { } @Test - public void testCSV141CSVFormat_DEFAULT() throws Exception { + void testCSV141CSVFormat_DEFAULT() throws Exception { testCSV141Failure(CSVFormat.DEFAULT, 3); } @Test - public void testCSV141CSVFormat_INFORMIX_UNLOAD() throws Exception { + void testCSV141CSVFormat_INFORMIX_UNLOAD() throws Exception { testCSV141Failure(CSVFormat.INFORMIX_UNLOAD, 1); } @Test - public void testCSV141CSVFormat_INFORMIX_UNLOAD_CSV() throws Exception { + void testCSV141CSVFormat_INFORMIX_UNLOAD_CSV() throws Exception { testCSV141Failure(CSVFormat.INFORMIX_UNLOAD_CSV, 3); } @Test - public void testCSV141CSVFormat_ORACLE() throws Exception { + void testCSV141CSVFormat_ORACLE() throws Exception { testCSV141Failure(CSVFormat.ORACLE, 2); } @Test - public void testCSV141CSVFormat_POSTGRESQL_CSV() throws Exception { + void testCSV141CSVFormat_POSTGRESQL_CSV() throws Exception { testCSV141Failure(CSVFormat.POSTGRESQL_CSV, 3); } @Test @Disabled("PR 295 does not work") - public void testCSV141Excel() throws Exception { + void testCSV141Excel() throws Exception { testCSV141Ok(CSVFormat.EXCEL); } @@ -372,12 +372,12 @@ record = parser.nextRecord(); } @Test - public void testCSV141RFC4180() throws Exception { + void testCSV141RFC4180() throws Exception { testCSV141Failure(CSVFormat.RFC4180, 3); } @Test - public void testCSV235() throws IOException { + void testCSV235() throws IOException { final String dqString = "\"aaa\",\"b\"\"bb\",\"ccc\""; // "aaa","b""bb","ccc" try (final CSVParser parser = CSVFormat.RFC4180.parse(new StringReader(dqString))) { final Iterator records = parser.iterator(); @@ -391,7 +391,7 @@ public void testCSV235() throws IOException { } @Test - public void testCSV57() throws Exception { + void testCSV57() throws Exception { try (final CSVParser parser = CSVParser.parse("", CSVFormat.DEFAULT)) { final List list = parser.getRecords(); assertNotNull(list); @@ -400,7 +400,7 @@ public void testCSV57() throws Exception { } @Test - public void testDefaultFormat() throws IOException { + void testDefaultFormat() throws IOException { final String code = "" + "a,b#\n" // 1) + "\"\n\",\" \",#\n" // 2) + "#,\"\"\n" // 3) @@ -428,20 +428,20 @@ public void testDefaultFormat() throws IOException { } @Test - public void testDuplicateHeadersAllowedByDefault() throws Exception { + void testDuplicateHeadersAllowedByDefault() throws Exception { try (CSVParser parser = CSVParser.parse("a,b,a\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader())) { // noop } } @Test - public void testDuplicateHeadersNotAllowed() { + void testDuplicateHeadersNotAllowed() { assertThrows(IllegalArgumentException.class, () -> CSVParser.parse("a,b,a\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader().withAllowDuplicateHeaderNames(false))); } @Test - public void testEmptyFile() throws Exception { + void testEmptyFile() throws Exception { try (final CSVParser parser = CSVParser.parse(Paths.get("src/test/resources/org/apache/commons/csv/empty.txt"), StandardCharsets.UTF_8, CSVFormat.DEFAULT)) { assertNull(parser.nextRecord()); @@ -449,7 +449,7 @@ public void testEmptyFile() throws Exception { } @Test - public void testEmptyFileHeaderParsing() throws Exception { + void testEmptyFileHeaderParsing() throws Exception { try (final CSVParser parser = CSVParser.parse("", CSVFormat.DEFAULT.withFirstRecordAsHeader())) { assertNull(parser.nextRecord()); assertTrue(parser.getHeaderNames().isEmpty()); @@ -457,7 +457,7 @@ public void testEmptyFileHeaderParsing() throws Exception { } @Test - public void testEmptyLineBehaviorCSV() throws Exception { + void testEmptyLineBehaviorCSV() throws Exception { final String[] codes = {"hello,\r\n\r\n\r\n", "hello,\n\n\n", "hello,\"\"\r\n\r\n\r\n", "hello,\"\"\n\n\n"}; final String[][] res = {{"hello", ""} // CSV format ignores empty lines }; @@ -474,7 +474,7 @@ public void testEmptyLineBehaviorCSV() throws Exception { } @Test - public void testEmptyLineBehaviorExcel() throws Exception { + void testEmptyLineBehaviorExcel() throws Exception { final String[] codes = {"hello,\r\n\r\n\r\n", "hello,\n\n\n", "hello,\"\"\r\n\r\n\r\n", "hello,\"\"\n\n\n"}; final String[][] res = {{"hello", ""}, {""}, // Excel format does not ignore empty lines {""}}; @@ -491,14 +491,14 @@ public void testEmptyLineBehaviorExcel() throws Exception { } @Test - public void testEmptyString() throws Exception { + void testEmptyString() throws Exception { try (final CSVParser parser = CSVParser.parse("", CSVFormat.DEFAULT)) { assertNull(parser.nextRecord()); } } @Test - public void testEndOfFileBehaviorCSV() throws Exception { + void testEndOfFileBehaviorCSV() throws Exception { final String[] codes = {"hello,\r\n\r\nworld,\r\n", "hello,\r\n\r\nworld,", "hello,\r\n\r\nworld,\"\"\r\n", "hello,\r\n\r\nworld,\"\"", "hello,\r\n\r\nworld,\n", "hello,\r\n\r\nworld,", "hello,\r\n\r\nworld,\"\"\n", "hello,\r\n\r\nworld,\"\""}; final String[][] res = {{"hello", ""}, // CSV format ignores empty lines @@ -516,7 +516,7 @@ public void testEndOfFileBehaviorCSV() throws Exception { } @Test - public void testEndOfFileBehaviorExcel() throws Exception { + void testEndOfFileBehaviorExcel() throws Exception { final String[] codes = {"hello,\r\n\r\nworld,\r\n", "hello,\r\n\r\nworld,", "hello,\r\n\r\nworld,\"\"\r\n", "hello,\r\n\r\nworld,\"\"", "hello,\r\n\r\nworld,\n", "hello,\r\n\r\nworld,", "hello,\r\n\r\nworld,\"\"\n", "hello,\r\n\r\nworld,\"\""}; final String[][] res = {{"hello", ""}, {""}, // Excel format does not ignore empty lines @@ -535,7 +535,7 @@ public void testEndOfFileBehaviorExcel() throws Exception { } @Test - public void testExcelFormat1() throws IOException { + void testExcelFormat1() throws IOException { final String code = "value1,value2,value3,value4\r\na,b,c,d\r\n x,,," + "\r\n\r\n\"\"\"hello\"\"\",\" \"\"world\"\"\",\"abc\ndef\",\r\n"; final String[][] res = {{"value1", "value2", "value3", "value4"}, {"a", "b", "c", "d"}, {" x", "", "", ""}, {""}, {"\"hello\"", " \"world\"", "abc\ndef", ""}}; @@ -550,7 +550,7 @@ public void testExcelFormat1() throws IOException { } @Test - public void testExcelFormat2() throws Exception { + void testExcelFormat2() throws Exception { final String code = "foo,baar\r\n\r\nhello,\r\n\r\nworld,\r\n"; final String[][] res = {{"foo", "baar"}, {""}, {"hello", ""}, {""}, {"world", ""}}; try (final CSVParser parser = CSVParser.parse(code, CSVFormat.EXCEL)) { @@ -567,7 +567,7 @@ public void testExcelFormat2() throws Exception { * Tests an exported Excel worksheet with a header row and rows that have more columns than the headers */ @Test - public void testExcelHeaderCountLessThanData() throws Exception { + void testExcelHeaderCountLessThanData() throws Exception { final String code = "A,B,C,,\r\na,b,c,d,e\r\n"; try (final CSVParser parser = CSVParser.parse(code, CSVFormat.EXCEL.withHeader())) { parser.getRecords().forEach(record -> { @@ -579,7 +579,7 @@ public void testExcelHeaderCountLessThanData() throws Exception { } @Test - public void testFirstEndOfLineCr() throws IOException { + void testFirstEndOfLineCr() throws IOException { final String data = "foo\rbaar,\rhello,world\r,kanu"; try (final CSVParser parser = CSVParser.parse(data, CSVFormat.DEFAULT)) { final List records = parser.getRecords(); @@ -589,7 +589,7 @@ public void testFirstEndOfLineCr() throws IOException { } @Test - public void testFirstEndOfLineCrLf() throws IOException { + void testFirstEndOfLineCrLf() throws IOException { final String data = "foo\r\nbaar,\r\nhello,world\r\n,kanu"; try (final CSVParser parser = CSVParser.parse(data, CSVFormat.DEFAULT)) { final List records = parser.getRecords(); @@ -599,7 +599,7 @@ public void testFirstEndOfLineCrLf() throws IOException { } @Test - public void testFirstEndOfLineLf() throws IOException { + void testFirstEndOfLineLf() throws IOException { final String data = "foo\nbaar,\nhello,world\n,kanu"; try (final CSVParser parser = CSVParser.parse(data, CSVFormat.DEFAULT)) { final List records = parser.getRecords(); @@ -609,7 +609,7 @@ public void testFirstEndOfLineLf() throws IOException { } @Test - public void testForEach() throws Exception { + void testForEach() throws Exception { try (final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z"); final CSVParser parser = CSVFormat.DEFAULT.parse(in)) { final List records = new ArrayList<>(); for (final CSVRecord record : parser) { @@ -623,7 +623,7 @@ public void testForEach() throws Exception { } @Test - public void testGetHeaderComment_HeaderComment1() throws IOException { + void testGetHeaderComment_HeaderComment1() throws IOException { try (CSVParser parser = CSVParser.parse(CSV_INPUT_HEADER_COMMENT, FORMAT_AUTO_HEADER)) { parser.getRecords(); // Expect a header comment @@ -633,7 +633,7 @@ public void testGetHeaderComment_HeaderComment1() throws IOException { } @Test - public void testGetHeaderComment_HeaderComment2() throws IOException { + void testGetHeaderComment_HeaderComment2() throws IOException { try (CSVParser parser = CSVParser.parse(CSV_INPUT_HEADER_COMMENT, FORMAT_EXPLICIT_HEADER)) { parser.getRecords(); // Expect a header comment @@ -643,7 +643,7 @@ public void testGetHeaderComment_HeaderComment2() throws IOException { } @Test - public void testGetHeaderComment_HeaderComment3() throws IOException { + void testGetHeaderComment_HeaderComment3() throws IOException { try (CSVParser parser = CSVParser.parse(CSV_INPUT_HEADER_COMMENT, FORMAT_EXPLICIT_HEADER_NOSKIP)) { parser.getRecords(); // Expect no header comment - the text "comment" is attached to the first record @@ -653,7 +653,7 @@ public void testGetHeaderComment_HeaderComment3() throws IOException { } @Test - public void testGetHeaderComment_HeaderTrailerComment() throws IOException { + void testGetHeaderComment_HeaderTrailerComment() throws IOException { try (CSVParser parser = CSVParser.parse(CSV_INPUT_MULTILINE_HEADER_TRAILER_COMMENT, FORMAT_AUTO_HEADER)) { parser.getRecords(); // Expect a header comment @@ -663,7 +663,7 @@ public void testGetHeaderComment_HeaderTrailerComment() throws IOException { } @Test - public void testGetHeaderComment_NoComment1() throws IOException { + void testGetHeaderComment_NoComment1() throws IOException { try (CSVParser parser = CSVParser.parse(CSV_INPUT_NO_COMMENT, FORMAT_AUTO_HEADER)) { parser.getRecords(); // Expect no header comment @@ -673,7 +673,7 @@ public void testGetHeaderComment_NoComment1() throws IOException { } @Test - public void testGetHeaderComment_NoComment2() throws IOException { + void testGetHeaderComment_NoComment2() throws IOException { try (CSVParser parser = CSVParser.parse(CSV_INPUT_NO_COMMENT, FORMAT_EXPLICIT_HEADER)) { parser.getRecords(); // Expect no header comment @@ -683,7 +683,7 @@ public void testGetHeaderComment_NoComment2() throws IOException { } @Test - public void testGetHeaderComment_NoComment3() throws IOException { + void testGetHeaderComment_NoComment3() throws IOException { try (CSVParser parser = CSVParser.parse(CSV_INPUT_NO_COMMENT, FORMAT_EXPLICIT_HEADER_NOSKIP)) { parser.getRecords(); // Expect no header comment @@ -693,7 +693,7 @@ public void testGetHeaderComment_NoComment3() throws IOException { } @Test - public void testGetHeaderMap() throws Exception { + void testGetHeaderMap() throws Exception { try (final CSVParser parser = CSVParser.parse("a,b,c\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader("A", "B", "C"))) { final Map headerMap = parser.getHeaderMap(); final Iterator columnNames = headerMap.keySet().iterator(); @@ -717,7 +717,7 @@ public void testGetHeaderMap() throws Exception { } @Test - public void testGetHeaderNames() throws IOException { + void testGetHeaderNames() throws IOException { try (final CSVParser parser = CSVParser.parse("a,b,c\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader("A", "B", "C"))) { final Map nameIndexMap = parser.getHeaderMap(); final List headerNames = parser.getHeaderNames(); @@ -731,7 +731,7 @@ public void testGetHeaderNames() throws IOException { } @Test - public void testGetHeaderNamesReadOnly() throws IOException { + void testGetHeaderNamesReadOnly() throws IOException { try (final CSVParser parser = CSVParser.parse("a,b,c\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader("A", "B", "C"))) { final List headerNames = parser.getHeaderNames(); assertNotNull(headerNames); @@ -740,7 +740,7 @@ public void testGetHeaderNamesReadOnly() throws IOException { } @Test - public void testGetLine() throws IOException { + void testGetLine() throws IOException { try (final CSVParser parser = CSVParser.parse(CSV_INPUT, CSVFormat.DEFAULT.withIgnoreSurroundingSpaces())) { for (final String[] re : RESULT) { assertArrayEquals(re, parser.nextRecord().values()); @@ -751,22 +751,22 @@ public void testGetLine() throws IOException { } @Test - public void testGetLineNumberWithCR() throws Exception { + void testGetLineNumberWithCR() throws Exception { this.validateLineNumbers(String.valueOf(CR)); } @Test - public void testGetLineNumberWithCRLF() throws Exception { + void testGetLineNumberWithCRLF() throws Exception { this.validateLineNumbers(CRLF); } @Test - public void testGetLineNumberWithLF() throws Exception { + void testGetLineNumberWithLF() throws Exception { this.validateLineNumbers(String.valueOf(LF)); } @Test - public void testGetOneLine() throws IOException { + void testGetOneLine() throws IOException { try (final CSVParser parser = CSVParser.parse(CSV_INPUT_1, CSVFormat.DEFAULT)) { final CSVRecord record = parser.getRecords().get(0); assertArrayEquals(RESULT[0], record.values()); @@ -779,7 +779,7 @@ public void testGetOneLine() throws IOException { * @throws IOException when an I/O error occurs. */ @Test - public void testGetOneLineOneParser() throws IOException { + void testGetOneLineOneParser() throws IOException { final CSVFormat format = CSVFormat.DEFAULT; try (final PipedWriter writer = new PipedWriter(); final CSVParser parser = new CSVParser(new PipedReader(writer), format)) { writer.append(CSV_INPUT_1); @@ -794,32 +794,32 @@ public void testGetOneLineOneParser() throws IOException { } @Test - public void testGetRecordNumberWithCR() throws Exception { + void testGetRecordNumberWithCR() throws Exception { this.validateRecordNumbers(String.valueOf(CR)); } @Test - public void testGetRecordNumberWithCRLF() throws Exception { + void testGetRecordNumberWithCRLF() throws Exception { this.validateRecordNumbers(CRLF); } @Test - public void testGetRecordNumberWithLF() throws Exception { + void testGetRecordNumberWithLF() throws Exception { this.validateRecordNumbers(String.valueOf(LF)); } @Test - public void testGetRecordPositionWithCRLF() throws Exception { + void testGetRecordPositionWithCRLF() throws Exception { this.validateRecordPosition(CRLF); } @Test - public void testGetRecordPositionWithLF() throws Exception { + void testGetRecordPositionWithLF() throws Exception { this.validateRecordPosition(String.valueOf(LF)); } @Test - public void testGetRecords() throws IOException { + void testGetRecords() throws IOException { try (final CSVParser parser = CSVParser.parse(CSV_INPUT, CSVFormat.DEFAULT.withIgnoreSurroundingSpaces())) { final List records = parser.getRecords(); assertEquals(RESULT.length, records.size()); @@ -831,7 +831,7 @@ public void testGetRecords() throws IOException { } @Test - public void testGetRecordsFromBrokenInputStream() throws IOException { + void testGetRecordsFromBrokenInputStream() throws IOException { @SuppressWarnings("resource") // We also get an exception on close, which is OK but can't assert in a try. final CSVParser parser = CSVParser.parse(new BrokenInputStream(), UTF_8, CSVFormat.DEFAULT); assertThrows(UncheckedIOException.class, parser::getRecords); @@ -839,7 +839,7 @@ public void testGetRecordsFromBrokenInputStream() throws IOException { } @Test - public void testGetRecordWithMultiLineValues() throws Exception { + void testGetRecordWithMultiLineValues() throws Exception { try (final CSVParser parser = CSVParser.parse("\"a\r\n1\",\"a\r\n2\"" + CRLF + "\"b\r\n1\",\"b\r\n2\"" + CRLF + "\"c\r\n1\",\"c\r\n2\"", CSVFormat.DEFAULT.withRecordSeparator(CRLF))) { CSVRecord record; @@ -864,7 +864,7 @@ public void testGetRecordWithMultiLineValues() throws Exception { } @Test - public void testGetTrailerComment_HeaderComment1() throws IOException { + void testGetTrailerComment_HeaderComment1() throws IOException { try (CSVParser parser = CSVParser.parse(CSV_INPUT_HEADER_COMMENT, FORMAT_AUTO_HEADER)) { parser.getRecords(); assertFalse(parser.hasTrailerComment()); @@ -873,7 +873,7 @@ public void testGetTrailerComment_HeaderComment1() throws IOException { } @Test - public void testGetTrailerComment_HeaderComment2() throws IOException { + void testGetTrailerComment_HeaderComment2() throws IOException { try (CSVParser parser = CSVParser.parse(CSV_INPUT_HEADER_COMMENT, FORMAT_EXPLICIT_HEADER)) { parser.getRecords(); assertFalse(parser.hasTrailerComment()); @@ -882,7 +882,7 @@ public void testGetTrailerComment_HeaderComment2() throws IOException { } @Test - public void testGetTrailerComment_HeaderComment3() throws IOException { + void testGetTrailerComment_HeaderComment3() throws IOException { try (CSVParser parser = CSVParser.parse(CSV_INPUT_HEADER_COMMENT, FORMAT_EXPLICIT_HEADER_NOSKIP)) { parser.getRecords(); assertFalse(parser.hasTrailerComment()); @@ -891,7 +891,7 @@ public void testGetTrailerComment_HeaderComment3() throws IOException { } @Test - public void testGetTrailerComment_HeaderTrailerComment1() throws IOException { + void testGetTrailerComment_HeaderTrailerComment1() throws IOException { try (CSVParser parser = CSVParser.parse(CSV_INPUT_HEADER_TRAILER_COMMENT, FORMAT_AUTO_HEADER)) { parser.getRecords(); assertTrue(parser.hasTrailerComment()); @@ -900,7 +900,7 @@ public void testGetTrailerComment_HeaderTrailerComment1() throws IOException { } @Test - public void testGetTrailerComment_HeaderTrailerComment2() throws IOException { + void testGetTrailerComment_HeaderTrailerComment2() throws IOException { try (CSVParser parser = CSVParser.parse(CSV_INPUT_HEADER_TRAILER_COMMENT, FORMAT_EXPLICIT_HEADER)) { parser.getRecords(); assertTrue(parser.hasTrailerComment()); @@ -909,7 +909,7 @@ public void testGetTrailerComment_HeaderTrailerComment2() throws IOException { } @Test - public void testGetTrailerComment_HeaderTrailerComment3() throws IOException { + void testGetTrailerComment_HeaderTrailerComment3() throws IOException { try (CSVParser parser = CSVParser.parse(CSV_INPUT_HEADER_TRAILER_COMMENT, FORMAT_EXPLICIT_HEADER_NOSKIP)) { parser.getRecords(); assertTrue(parser.hasTrailerComment()); @@ -918,7 +918,7 @@ public void testGetTrailerComment_HeaderTrailerComment3() throws IOException { } @Test - public void testGetTrailerComment_MultilineComment() throws IOException { + void testGetTrailerComment_MultilineComment() throws IOException { try (CSVParser parser = CSVParser.parse(CSV_INPUT_MULTILINE_HEADER_TRAILER_COMMENT, FORMAT_AUTO_HEADER)) { parser.getRecords(); assertTrue(parser.hasTrailerComment()); @@ -927,7 +927,7 @@ public void testGetTrailerComment_MultilineComment() throws IOException { } @Test - public void testHeader() throws Exception { + void testHeader() throws Exception { final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z"); try (final CSVParser parser = CSVFormat.DEFAULT.withHeader().parse(in)) { @@ -946,7 +946,7 @@ public void testHeader() throws Exception { } @Test - public void testHeaderComment() throws Exception { + void testHeaderComment() throws Exception { final Reader in = new StringReader("# comment\na,b,c\n1,2,3\nx,y,z"); try (final CSVParser parser = CSVFormat.DEFAULT.withCommentMarker('#').withHeader().parse(in)) { @@ -965,7 +965,7 @@ public void testHeaderComment() throws Exception { } @Test - public void testHeaderMissing() throws Exception { + void testHeaderMissing() throws Exception { final Reader in = new StringReader("a,,c\n1,2,3\nx,y,z"); try (final CSVParser parser = CSVFormat.DEFAULT.withHeader().withAllowMissingColumnNames().parse(in)) { @@ -983,7 +983,7 @@ public void testHeaderMissing() throws Exception { } @Test - public void testHeaderMissingWithNull() throws Exception { + void testHeaderMissingWithNull() throws Exception { final Reader in = new StringReader("a,,c,,e\n1,2,3,4,5\nv,w,x,y,z"); try (final CSVParser parser = CSVFormat.DEFAULT.withHeader().withNullString("").withAllowMissingColumnNames().parse(in)) { parser.iterator(); @@ -991,7 +991,7 @@ public void testHeaderMissingWithNull() throws Exception { } @Test - public void testHeadersMissing() throws Exception { + void testHeadersMissing() throws Exception { try (final Reader in = new StringReader("a,,c,,e\n1,2,3,4,5\nv,w,x,y,z"); final CSVParser parser = CSVFormat.DEFAULT.withHeader().withAllowMissingColumnNames().parse(in)) { parser.iterator(); @@ -999,19 +999,19 @@ public void testHeadersMissing() throws Exception { } @Test - public void testHeadersMissingException() { + void testHeadersMissingException() { final Reader in = new StringReader("a,,c,,e\n1,2,3,4,5\nv,w,x,y,z"); assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withHeader().parse(in).iterator()); } @Test - public void testHeadersMissingOneColumnException() { + void testHeadersMissingOneColumnException() { final Reader in = new StringReader("a,,c,d,e\n1,2,3,4,5\nv,w,x,y,z"); assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withHeader().parse(in).iterator()); } @Test - public void testHeadersWithNullColumnName() throws IOException { + void testHeadersWithNullColumnName() throws IOException { final Reader in = new StringReader("header1,null,header3\n1,2,3\n4,5,6"); try (final CSVParser parser = CSVFormat.DEFAULT.withHeader().withNullString("null").withAllowMissingColumnNames().parse(in)) { final Iterator records = parser.iterator(); @@ -1025,7 +1025,7 @@ public void testHeadersWithNullColumnName() throws IOException { } @Test - public void testIgnoreCaseHeaderMapping() throws Exception { + void testIgnoreCaseHeaderMapping() throws Exception { final Reader reader = new StringReader("1,2,3"); try (final CSVParser parser = CSVFormat.DEFAULT.withHeader("One", "TWO", "three").withIgnoreHeaderCase().parse(reader)) { final Iterator records = parser.iterator(); @@ -1036,7 +1036,7 @@ public void testIgnoreCaseHeaderMapping() throws Exception { }} @Test - public void testIgnoreEmptyLines() throws IOException { + void testIgnoreEmptyLines() throws IOException { final String code = "\nfoo,baar\n\r\n,\n\n,world\r\n\n"; // String code = "world\r\n\n"; // String code = "foo;baar\r\n\r\nhello;\r\n\r\nworld;\r\n"; @@ -1047,12 +1047,12 @@ public void testIgnoreEmptyLines() throws IOException { } @Test - public void testInvalidFormat() { + void testInvalidFormat() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withDelimiter(CR)); } @Test - public void testIterator() throws Exception { + void testIterator() throws Exception { final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z"); try (final CSVParser parser = CSVFormat.DEFAULT.parse(in)) { @@ -1072,7 +1072,7 @@ public void testIterator() throws Exception { }} @Test - public void testIteratorSequenceBreaking() throws IOException { + void testIteratorSequenceBreaking() throws IOException { final String fiveRows = "1\n2\n3\n4\n5\n"; // Iterator hasNext() shouldn't break sequence @@ -1131,7 +1131,7 @@ public void testIteratorSequenceBreaking() throws IOException { } @Test - public void testLineFeedEndings() throws IOException { + void testLineFeedEndings() throws IOException { final String code = "foo\nbaar,\nhello,world\n,kanu"; try (final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT)) { final List records = parser.getRecords(); @@ -1140,7 +1140,7 @@ public void testLineFeedEndings() throws IOException { } @Test - public void testMappedButNotSetAsOutlook2007ContactExport() throws Exception { + void testMappedButNotSetAsOutlook2007ContactExport() throws Exception { final Reader in = new StringReader("a,b,c\n1,2\nx,y,z"); try (final CSVParser parser = CSVFormat.DEFAULT.withHeader("A", "B", "C").withSkipHeaderRecord().parse(in)) { final Iterator records = parser.iterator(); @@ -1177,7 +1177,7 @@ record = records.next(); @Test @Disabled - public void testMongoDbCsv() throws Exception { + void testMongoDbCsv() throws Exception { try (final CSVParser parser = CSVParser.parse("\"a a\",b,c" + LF + "d,e,f", CSVFormat.MONGODB_CSV)) { final Iterator itr1 = parser.iterator(); final Iterator itr2 = parser.iterator(); @@ -1196,7 +1196,7 @@ public void testMongoDbCsv() throws Exception { @Test // TODO this may lead to strange behavior, throw an exception if iterator() has already been called? - public void testMultipleIterators() throws Exception { + void testMultipleIterators() throws Exception { try (final CSVParser parser = CSVParser.parse("a,b,c" + CRLF + "d,e,f", CSVFormat.DEFAULT)) { final Iterator itr1 = parser.iterator(); @@ -1213,24 +1213,24 @@ public void testMultipleIterators() throws Exception { } @Test - public void testNewCSVParserNullReaderFormat() { + void testNewCSVParserNullReaderFormat() { assertThrows(NullPointerException.class, () -> new CSVParser(null, CSVFormat.DEFAULT)); } @Test - public void testNewCSVParserReaderNullFormat() { + void testNewCSVParserReaderNullFormat() { assertThrows(NullPointerException.class, () -> new CSVParser(new StringReader(""), null)); } @Test - public void testNoHeaderMap() throws Exception { + void testNoHeaderMap() throws Exception { try (final CSVParser parser = CSVParser.parse("a,b,c\n1,2,3\nx,y,z", CSVFormat.DEFAULT)) { assertNull(parser.getHeaderMap()); } } @Test - public void testNotValueCSV() throws IOException { + void testNotValueCSV() throws IOException { final String source = "#"; final CSVFormat csvFormat = CSVFormat.DEFAULT.withCommentMarker('#'); try (final CSVParser csvParser = csvFormat.parse(new StringReader(source))) { @@ -1240,7 +1240,7 @@ public void testNotValueCSV() throws IOException { } @Test - public void testParse() throws Exception { + void testParse() throws Exception { final ClassLoader loader = ClassLoader.getSystemClassLoader(); final URL url = loader.getResource("org/apache/commons/csv/CSVFileParser/test.csv"); final CSVFormat format = CSVFormat.DEFAULT.withHeader("A", "B", "C", "D"); @@ -1275,47 +1275,47 @@ public void testParse() throws Exception { } @Test - public void testParseFileNullFormat() { + void testParseFileNullFormat() { assertThrows(NullPointerException.class, () -> CSVParser.parse(new File("CSVFileParser/test.csv"), Charset.defaultCharset(), null)); } @Test - public void testParseNullFileFormat() { + void testParseNullFileFormat() { assertThrows(NullPointerException.class, () -> CSVParser.parse((File) null, Charset.defaultCharset(), CSVFormat.DEFAULT)); } @Test - public void testParseNullPathFormat() { + void testParseNullPathFormat() { assertThrows(NullPointerException.class, () -> CSVParser.parse((Path) null, Charset.defaultCharset(), CSVFormat.DEFAULT)); } @Test - public void testParseNullStringFormat() { + void testParseNullStringFormat() { assertThrows(NullPointerException.class, () -> CSVParser.parse((String) null, CSVFormat.DEFAULT)); } @Test - public void testParseNullUrlCharsetFormat() { + void testParseNullUrlCharsetFormat() { assertThrows(NullPointerException.class, () -> CSVParser.parse((URL) null, Charset.defaultCharset(), CSVFormat.DEFAULT)); } @Test - public void testParserUrlNullCharsetFormat() { + void testParserUrlNullCharsetFormat() { assertThrows(NullPointerException.class, () -> CSVParser.parse(new URL("https://commons.apache.org"), null, CSVFormat.DEFAULT)); } @Test - public void testParseStringNullFormat() { + void testParseStringNullFormat() { assertThrows(NullPointerException.class, () -> CSVParser.parse("csv data", (CSVFormat) null)); } @Test - public void testParseUrlCharsetNullFormat() { + void testParseUrlCharsetNullFormat() { assertThrows(NullPointerException.class, () -> CSVParser.parse(new URL("https://commons.apache.org"), Charset.defaultCharset(), null)); } @Test - public void testParseWithDelimiterStringWithEscape() throws IOException { + void testParseWithDelimiterStringWithEscape() throws IOException { final String source = "a![!|!]b![|]c[|]xyz\r\nabc[abc][|]xyz"; final CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setDelimiter("[|]").setEscape('!').build(); try (CSVParser csvParser = csvFormat.parse(new StringReader(source))) { @@ -1328,7 +1328,7 @@ public void testParseWithDelimiterStringWithEscape() throws IOException { } } @Test - public void testParseWithDelimiterStringWithQuote() throws IOException { + void testParseWithDelimiterStringWithQuote() throws IOException { final String source = "'a[|]b[|]c'[|]xyz\r\nabc[abc][|]xyz"; final CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setDelimiter("[|]").setQuote('\'').build(); try (CSVParser csvParser = csvFormat.parse(new StringReader(source))) { @@ -1341,7 +1341,7 @@ public void testParseWithDelimiterStringWithQuote() throws IOException { } } @Test - public void testParseWithDelimiterWithEscape() throws IOException { + void testParseWithDelimiterWithEscape() throws IOException { final String source = "a!,b!,c,xyz"; final CSVFormat csvFormat = CSVFormat.DEFAULT.withEscape('!'); try (CSVParser csvParser = csvFormat.parse(new StringReader(source))) { @@ -1351,7 +1351,7 @@ public void testParseWithDelimiterWithEscape() throws IOException { } } @Test - public void testParseWithDelimiterWithQuote() throws IOException { + void testParseWithDelimiterWithQuote() throws IOException { final String source = "'a,b,c',xyz"; final CSVFormat csvFormat = CSVFormat.DEFAULT.withQuote('\''); try (CSVParser csvParser = csvFormat.parse(new StringReader(source))) { @@ -1361,7 +1361,7 @@ public void testParseWithDelimiterWithQuote() throws IOException { } } @Test - public void testParseWithQuoteThrowsException() throws IOException { + void testParseWithQuoteThrowsException() throws IOException { final CSVFormat csvFormat = CSVFormat.DEFAULT.withQuote('\''); final String source1 = "'a,b,c','"; final String source2 = "'a,b,c'abc,xyz"; @@ -1378,7 +1378,7 @@ public void testParseWithQuoteThrowsException() throws IOException { } } @Test - public void testParseWithQuoteWithEscape() throws IOException { + void testParseWithQuoteWithEscape() throws IOException { final String source = "'a?,b?,c?d',xyz"; final CSVFormat csvFormat = CSVFormat.DEFAULT.withQuote('\'').withEscape('?'); try (CSVParser csvParser = csvFormat.parse(new StringReader(source))) { @@ -1388,7 +1388,7 @@ public void testParseWithQuoteWithEscape() throws IOException { } } @Test - public void testProvidedHeader() throws Exception { + void testProvidedHeader() throws Exception { final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z"); try (final CSVParser parser = CSVFormat.DEFAULT.withHeader("A", "B", "C").parse(in)) { @@ -1411,7 +1411,7 @@ public void testProvidedHeader() throws Exception { } @Test - public void testProvidedHeaderAuto() throws Exception { + void testProvidedHeaderAuto() throws Exception { final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z"); try (final CSVParser parser = CSVFormat.DEFAULT.withHeader().parse(in)) { @@ -1434,7 +1434,7 @@ public void testProvidedHeaderAuto() throws Exception { } @Test - public void testRepeatedHeadersAreReturnedInCSVRecordHeaderNames() throws IOException { + void testRepeatedHeadersAreReturnedInCSVRecordHeaderNames() throws IOException { final Reader in = new StringReader("header1,header2,header1\n1,2,3\n4,5,6"); try (final CSVParser parser = CSVFormat.DEFAULT.withFirstRecordAsHeader().withTrim().parse(in)) { final Iterator records = parser.iterator(); @@ -1445,7 +1445,7 @@ public void testRepeatedHeadersAreReturnedInCSVRecordHeaderNames() throws IOExce }} @Test - public void testRoundtrip() throws Exception { + void testRoundtrip() throws Exception { final StringWriter out = new StringWriter(); final String data = "a,b,c\r\n1,2,3\r\nx,y,z\r\n"; try (final CSVPrinter printer = new CSVPrinter(out, CSVFormat.DEFAULT); @@ -1458,7 +1458,7 @@ public void testRoundtrip() throws Exception { } @Test - public void testSkipAutoHeader() throws Exception { + void testSkipAutoHeader() throws Exception { final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z"); try (final CSVParser parser = CSVFormat.DEFAULT.withHeader().parse(in)) { final Iterator records = parser.iterator(); @@ -1470,7 +1470,7 @@ public void testSkipAutoHeader() throws Exception { } @Test - public void testSkipHeaderOverrideDuplicateHeaders() throws Exception { + void testSkipHeaderOverrideDuplicateHeaders() throws Exception { final Reader in = new StringReader("a,a,a\n1,2,3\nx,y,z"); try (final CSVParser parser = CSVFormat.DEFAULT.withHeader("X", "Y", "Z").withSkipHeaderRecord().parse(in)) { final Iterator records = parser.iterator(); @@ -1481,7 +1481,7 @@ public void testSkipHeaderOverrideDuplicateHeaders() throws Exception { }} @Test - public void testSkipSetAltHeaders() throws Exception { + void testSkipSetAltHeaders() throws Exception { final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z"); try (final CSVParser parser = CSVFormat.DEFAULT.withHeader("X", "Y", "Z").withSkipHeaderRecord().parse(in)) { final Iterator records = parser.iterator(); @@ -1493,7 +1493,7 @@ public void testSkipSetAltHeaders() throws Exception { } @Test - public void testSkipSetHeader() throws Exception { + void testSkipSetHeader() throws Exception { final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z"); try (final CSVParser parser = CSVFormat.DEFAULT.withHeader("a", "b", "c").withSkipHeaderRecord().parse(in)) { final Iterator records = parser.iterator(); @@ -1506,7 +1506,7 @@ public void testSkipSetHeader() throws Exception { @Test @Disabled - public void testStartWithEmptyLinesThenHeaders() throws Exception { + void testStartWithEmptyLinesThenHeaders() throws Exception { final String[] codes = {"\r\n\r\n\r\nhello,\r\n\r\n\r\n", "hello,\n\n\n", "hello,\"\"\r\n\r\n\r\n", "hello,\"\"\n\n\n"}; final String[][] res = {{"hello", ""}, {""}, // Excel format does not ignore empty lines {""}}; @@ -1523,7 +1523,7 @@ public void testStartWithEmptyLinesThenHeaders() throws Exception { } @Test - public void testStream() throws Exception { + void testStream() throws Exception { final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z"); try (final CSVParser parser = CSVFormat.DEFAULT.parse(in)) { final List list = parser.stream().collect(Collectors.toList()); @@ -1534,7 +1534,7 @@ public void testStream() throws Exception { }} @Test - public void testThrowExceptionWithLineAndPosition() throws IOException { + void testThrowExceptionWithLineAndPosition() throws IOException { final String csvContent = "col1,col2,col3,col4,col5,col6,col7,col8,col9,col10\nrec1,rec2,rec3,rec4,rec5,rec6,rec7,rec8,\"\"rec9\"\",rec10"; final StringReader stringReader = new StringReader(csvContent); // @formatter:off @@ -1551,7 +1551,7 @@ public void testThrowExceptionWithLineAndPosition() throws IOException { } @Test - public void testTrailingDelimiter() throws Exception { + void testTrailingDelimiter() throws Exception { final Reader in = new StringReader("a,a,a,\n\"1\",\"2\",\"3\",\nx,y,z,"); try (final CSVParser parser = CSVFormat.DEFAULT.withHeader("X", "Y", "Z").withSkipHeaderRecord().withTrailingDelimiter().parse(in)) { final Iterator records = parser.iterator(); @@ -1564,7 +1564,7 @@ public void testTrailingDelimiter() throws Exception { } @Test - public void testTrim() throws Exception { + void testTrim() throws Exception { final Reader in = new StringReader("a,a,a\n\" 1 \",\" 2 \",\" 3 \"\nx,y,z"); try (final CSVParser parser = CSVFormat.DEFAULT.withHeader("X", "Y", "Z").withSkipHeaderRecord().withTrim().parse(in)) { final Iterator records = parser.iterator(); diff --git a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java index a044ee59a6..c6851cf7aa 100644 --- a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java +++ b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java @@ -71,7 +71,7 @@ /** * Tests {@link CSVPrinter}. */ -public class CSVPrinterTest { + class CSVPrinterTest { private static final char DQUOTE_CHAR = '"'; private static final char EURO_CH = '\u20AC'; @@ -250,7 +250,7 @@ private void setUpTable(final Connection connection) throws SQLException { } @Test - public void testCloseBackwardCompatibility() throws IOException { + void testCloseBackwardCompatibility() throws IOException { try (final Writer writer = mock(Writer.class)) { final CSVFormat csvFormat = CSVFormat.DEFAULT; try (CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat)) { @@ -261,7 +261,7 @@ public void testCloseBackwardCompatibility() throws IOException { }} @Test - public void testCloseWithCsvFormatAutoFlushOff() throws IOException { + void testCloseWithCsvFormatAutoFlushOff() throws IOException { try (final Writer writer = mock(Writer.class)) { final CSVFormat csvFormat = CSVFormat.DEFAULT.withAutoFlush(false); try (CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat)) { @@ -273,7 +273,7 @@ public void testCloseWithCsvFormatAutoFlushOff() throws IOException { } @Test - public void testCloseWithCsvFormatAutoFlushOn() throws IOException { + void testCloseWithCsvFormatAutoFlushOn() throws IOException { // System.out.println("start method"); try (final Writer writer = mock(Writer.class)) { final CSVFormat csvFormat = CSVFormat.DEFAULT.withAutoFlush(true); @@ -285,7 +285,7 @@ public void testCloseWithCsvFormatAutoFlushOn() throws IOException { }} @Test - public void testCloseWithFlushOff() throws IOException { + void testCloseWithFlushOff() throws IOException { try (final Writer writer = mock(Writer.class)) { final CSVFormat csvFormat = CSVFormat.DEFAULT; @SuppressWarnings("resource") @@ -297,7 +297,7 @@ public void testCloseWithFlushOff() throws IOException { } @Test - public void testCloseWithFlushOn() throws IOException { + void testCloseWithFlushOn() throws IOException { try (final Writer writer = mock(Writer.class)) { @SuppressWarnings("resource") final CSVPrinter csvPrinter = new CSVPrinter(writer, CSVFormat.DEFAULT); @@ -307,7 +307,7 @@ public void testCloseWithFlushOn() throws IOException { } @Test - public void testCRComment() throws IOException { + void testCRComment() throws IOException { final StringWriter sw = new StringWriter(); final Object value = "abc"; try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withCommentMarker('#'))) { @@ -319,7 +319,7 @@ public void testCRComment() throws IOException { } @Test - public void testCSV135() throws IOException { + void testCSV135() throws IOException { final List list = new LinkedList<>(); list.add("\"\""); // "" list.add("\\\\"); // \\ @@ -342,7 +342,7 @@ public void testCSV135() throws IOException { } @Test - public void testCSV259() throws IOException { + void testCSV259() throws IOException { final StringWriter sw = new StringWriter(); try (final Reader reader = new FileReader("src/test/resources/org/apache/commons/csv/CSV-259/sample.txt"); final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape('!').withQuote(null))) { @@ -352,7 +352,7 @@ public void testCSV259() throws IOException { } @Test - public void testDelimeterQuoted() throws IOException { + void testDelimeterQuoted() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote('\''))) { printer.print("a,b,c"); @@ -362,7 +362,7 @@ public void testDelimeterQuoted() throws IOException { } @Test - public void testDelimeterQuoteNone() throws IOException { + void testDelimeterQuoteNone() throws IOException { final StringWriter sw = new StringWriter(); final CSVFormat format = CSVFormat.DEFAULT.withEscape('!').withQuoteMode(QuoteMode.NONE); try (final CSVPrinter printer = new CSVPrinter(sw, format)) { @@ -373,7 +373,7 @@ public void testDelimeterQuoteNone() throws IOException { } @Test - public void testDelimeterStringQuoted() throws IOException { + void testDelimeterStringQuoted() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.builder().setDelimiter("[|]").setQuote('\'').build())) { printer.print("a[|]b[|]c"); @@ -383,7 +383,7 @@ public void testDelimeterStringQuoted() throws IOException { } @Test - public void testDelimeterStringQuoteNone() throws IOException { + void testDelimeterStringQuoteNone() throws IOException { final StringWriter sw = new StringWriter(); final CSVFormat format = CSVFormat.DEFAULT.builder().setDelimiter("[|]").setEscape('!').setQuoteMode(QuoteMode.NONE).build(); try (final CSVPrinter printer = new CSVPrinter(sw, format)) { @@ -395,7 +395,7 @@ public void testDelimeterStringQuoteNone() throws IOException { } @Test - public void testDelimiterEscaped() throws IOException { + void testDelimiterEscaped() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape('!').withQuote(null))) { printer.print("a,b,c"); @@ -405,7 +405,7 @@ public void testDelimiterEscaped() throws IOException { } @Test - public void testDelimiterPlain() throws IOException { + void testDelimiterPlain() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(null))) { printer.print("a,b,c"); @@ -415,7 +415,7 @@ public void testDelimiterPlain() throws IOException { } @Test - public void testDelimiterStringEscaped() throws IOException { + void testDelimiterStringEscaped() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.builder().setDelimiter("|||").setEscape('!').setQuote(null).build())) { printer.print("a|||b|||c"); @@ -425,7 +425,7 @@ public void testDelimiterStringEscaped() throws IOException { } @Test - public void testDisabledComment() throws IOException { + void testDisabledComment() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT)) { printer.printComment("This is a comment"); @@ -434,7 +434,7 @@ public void testDisabledComment() throws IOException { } @Test - public void testDontQuoteEuroFirstChar() throws IOException { + void testDontQuoteEuroFirstChar() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.RFC4180)) { printer.printRecord(EURO_CH, "Deux"); @@ -443,7 +443,7 @@ public void testDontQuoteEuroFirstChar() throws IOException { } @Test - public void testEolEscaped() throws IOException { + void testEolEscaped() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(null).withEscape('!'))) { printer.print("a\rb\nc"); @@ -453,7 +453,7 @@ public void testEolEscaped() throws IOException { } @Test - public void testEolPlain() throws IOException { + void testEolPlain() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(null))) { printer.print("a\rb\nc"); @@ -463,7 +463,7 @@ public void testEolPlain() throws IOException { } @Test - public void testEolQuoted() throws IOException { + void testEolQuoted() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote('\''))) { printer.print("a\rb\nc"); @@ -473,7 +473,7 @@ public void testEolQuoted() throws IOException { } @Test - public void testEscapeBackslash1() throws IOException { + void testEscapeBackslash1() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) { printer.print("\\"); @@ -482,7 +482,7 @@ public void testEscapeBackslash1() throws IOException { } @Test - public void testEscapeBackslash2() throws IOException { + void testEscapeBackslash2() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) { printer.print("\\\r"); @@ -491,7 +491,7 @@ public void testEscapeBackslash2() throws IOException { } @Test - public void testEscapeBackslash3() throws IOException { + void testEscapeBackslash3() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) { printer.print("X\\\r"); @@ -500,7 +500,7 @@ public void testEscapeBackslash3() throws IOException { } @Test - public void testEscapeBackslash4() throws IOException { + void testEscapeBackslash4() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) { printer.print("\\\\"); @@ -509,7 +509,7 @@ public void testEscapeBackslash4() throws IOException { } @Test - public void testEscapeBackslash5() throws IOException { + void testEscapeBackslash5() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) { printer.print("\\\\"); @@ -518,7 +518,7 @@ public void testEscapeBackslash5() throws IOException { } @Test - public void testEscapeNull1() throws IOException { + void testEscapeNull1() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape(null))) { printer.print("\\"); @@ -527,7 +527,7 @@ public void testEscapeNull1() throws IOException { } @Test - public void testEscapeNull2() throws IOException { + void testEscapeNull2() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape(null))) { printer.print("\\\r"); @@ -536,7 +536,7 @@ public void testEscapeNull2() throws IOException { } @Test - public void testEscapeNull3() throws IOException { + void testEscapeNull3() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape(null))) { printer.print("X\\\r"); @@ -545,7 +545,7 @@ public void testEscapeNull3() throws IOException { } @Test - public void testEscapeNull4() throws IOException { + void testEscapeNull4() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape(null))) { printer.print("\\\\"); @@ -554,7 +554,7 @@ public void testEscapeNull4() throws IOException { } @Test - public void testEscapeNull5() throws IOException { + void testEscapeNull5() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape(null))) { printer.print("\\\\"); @@ -563,7 +563,7 @@ public void testEscapeNull5() throws IOException { } @Test - public void testExcelPrintAllArrayOfArrays() throws IOException { + void testExcelPrintAllArrayOfArrays() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.EXCEL)) { printer.printRecords((Object[]) new String[][] { { "r1c1", "r1c2" }, { "r2c1", "r2c2" } }); @@ -572,7 +572,7 @@ public void testExcelPrintAllArrayOfArrays() throws IOException { } @Test - public void testExcelPrintAllArrayOfLists() throws IOException { + void testExcelPrintAllArrayOfLists() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.EXCEL)) { printer.printRecords( @@ -582,7 +582,7 @@ public void testExcelPrintAllArrayOfLists() throws IOException { } @Test - public void testExcelPrintAllIterableOfArrays() throws IOException { + void testExcelPrintAllIterableOfArrays() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.EXCEL)) { printer.printRecords(Arrays.asList(new String[][] { { "r1c1", "r1c2" }, { "r2c1", "r2c2" } })); @@ -591,7 +591,7 @@ public void testExcelPrintAllIterableOfArrays() throws IOException { } @Test - public void testExcelPrintAllIterableOfLists() throws IOException { + void testExcelPrintAllIterableOfLists() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.EXCEL)) { printer.printRecords( @@ -601,7 +601,7 @@ public void testExcelPrintAllIterableOfLists() throws IOException { } @Test - public void testExcelPrintAllStreamOfArrays() throws IOException { + void testExcelPrintAllStreamOfArrays() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.EXCEL)) { printer.printRecords(Stream.of(new String[][] { { "r1c1", "r1c2" }, { "r2c1", "r2c2" } })); @@ -610,7 +610,7 @@ public void testExcelPrintAllStreamOfArrays() throws IOException { } @Test - public void testExcelPrinter1() throws IOException { + void testExcelPrinter1() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.EXCEL)) { printer.printRecord("a", "b"); @@ -619,7 +619,7 @@ public void testExcelPrinter1() throws IOException { } @Test - public void testExcelPrinter2() throws IOException { + void testExcelPrinter2() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.EXCEL)) { printer.printRecord("a,b", "b"); @@ -628,7 +628,7 @@ public void testExcelPrinter2() throws IOException { } @Test - public void testHeader() throws IOException { + void testHeader() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(null).withHeader("C1", "C2", "C3"))) { @@ -639,7 +639,7 @@ public void testHeader() throws IOException { } @Test - public void testHeaderCommentExcel() throws IOException { + void testHeaderCommentExcel() throws IOException { final StringWriter sw = new StringWriter(); final Date now = new Date(); final CSVFormat format = CSVFormat.EXCEL; @@ -650,7 +650,7 @@ public void testHeaderCommentExcel() throws IOException { } @Test - public void testHeaderCommentTdf() throws IOException { + void testHeaderCommentTdf() throws IOException { final StringWriter sw = new StringWriter(); final Date now = new Date(); final CSVFormat format = CSVFormat.TDF; @@ -661,7 +661,7 @@ public void testHeaderCommentTdf() throws IOException { } @Test - public void testHeaderNotSet() throws IOException { + void testHeaderNotSet() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(null))) { printer.printRecord("a", "b", "c"); @@ -671,12 +671,12 @@ public void testHeaderNotSet() throws IOException { } @Test - public void testInvalidFormat() { + void testInvalidFormat() { assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.withDelimiter(CR)); } @Test - public void testJdbcPrinter() throws IOException, ClassNotFoundException, SQLException { + void testJdbcPrinter() throws IOException, ClassNotFoundException, SQLException { final StringWriter sw = new StringWriter(); try (final Connection connection = getH2Connection()) { setUpTable(connection); @@ -690,7 +690,7 @@ public void testJdbcPrinter() throws IOException, ClassNotFoundException, SQLExc } @Test - public void testJdbcPrinterWithResultSet() throws IOException, ClassNotFoundException, SQLException { + void testJdbcPrinterWithResultSet() throws IOException, ClassNotFoundException, SQLException { final StringWriter sw = new StringWriter(); Class.forName("org.h2.Driver"); try (final Connection connection = getH2Connection()) { @@ -706,7 +706,7 @@ public void testJdbcPrinterWithResultSet() throws IOException, ClassNotFoundExce } @Test - public void testJdbcPrinterWithResultSetHeader() throws IOException, ClassNotFoundException, SQLException { + void testJdbcPrinterWithResultSetHeader() throws IOException, ClassNotFoundException, SQLException { final StringWriter sw = new StringWriter(); try (final Connection connection = getH2Connection()) { setUpTable(connection); @@ -727,7 +727,7 @@ public void testJdbcPrinterWithResultSetHeader() throws IOException, ClassNotFou } @Test - public void testJdbcPrinterWithResultSetMetaData() throws IOException, ClassNotFoundException, SQLException { + void testJdbcPrinterWithResultSetMetaData() throws IOException, ClassNotFoundException, SQLException { final StringWriter sw = new StringWriter(); Class.forName("org.h2.Driver"); try (final Connection connection = getH2Connection()) { @@ -743,7 +743,7 @@ public void testJdbcPrinterWithResultSetMetaData() throws IOException, ClassNotF } @Test - public void testJira135_part1() throws IOException { + void testJira135_part1() throws IOException { final CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote(DQUOTE_CHAR).withEscape(BACKSLASH); final StringWriter sw = new StringWriter(); final List list = new LinkedList<>(); @@ -759,7 +759,7 @@ public void testJira135_part1() throws IOException { @Test @Disabled - public void testJira135_part2() throws IOException { + void testJira135_part2() throws IOException { final CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote(DQUOTE_CHAR).withEscape(BACKSLASH); final StringWriter sw = new StringWriter(); final List list = new LinkedList<>(); @@ -774,7 +774,7 @@ public void testJira135_part2() throws IOException { } @Test - public void testJira135_part3() throws IOException { + void testJira135_part3() throws IOException { final CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote(DQUOTE_CHAR).withEscape(BACKSLASH); final StringWriter sw = new StringWriter(); final List list = new LinkedList<>(); @@ -790,7 +790,7 @@ public void testJira135_part3() throws IOException { @Test @Disabled - public void testJira135All() throws IOException { + void testJira135All() throws IOException { final CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote(DQUOTE_CHAR).withEscape(BACKSLASH); final StringWriter sw = new StringWriter(); final List list = new LinkedList<>(); @@ -807,7 +807,7 @@ public void testJira135All() throws IOException { } @Test - public void testMongoDbCsvBasic() throws IOException { + void testMongoDbCsvBasic() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.MONGODB_CSV)) { printer.printRecord("a", "b"); @@ -816,7 +816,7 @@ public void testMongoDbCsvBasic() throws IOException { } @Test - public void testMongoDbCsvCommaInValue() throws IOException { + void testMongoDbCsvCommaInValue() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.MONGODB_CSV)) { printer.printRecord("a,b", "c"); @@ -825,7 +825,7 @@ public void testMongoDbCsvCommaInValue() throws IOException { } @Test - public void testMongoDbCsvDoubleQuoteInValue() throws IOException { + void testMongoDbCsvDoubleQuoteInValue() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.MONGODB_CSV)) { printer.printRecord("a \"c\" b", "d"); @@ -834,7 +834,7 @@ public void testMongoDbCsvDoubleQuoteInValue() throws IOException { } @Test - public void testMongoDbCsvTabInValue() throws IOException { + void testMongoDbCsvTabInValue() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.MONGODB_CSV)) { printer.printRecord("a\tb", "c"); @@ -843,7 +843,7 @@ public void testMongoDbCsvTabInValue() throws IOException { } @Test - public void testMongoDbTsvBasic() throws IOException { + void testMongoDbTsvBasic() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.MONGODB_TSV)) { printer.printRecord("a", "b"); @@ -852,7 +852,7 @@ public void testMongoDbTsvBasic() throws IOException { } @Test - public void testMongoDbTsvCommaInValue() throws IOException { + void testMongoDbTsvCommaInValue() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.MONGODB_TSV)) { printer.printRecord("a,b", "c"); @@ -861,7 +861,7 @@ public void testMongoDbTsvCommaInValue() throws IOException { } @Test - public void testMongoDbTsvTabInValue() throws IOException { + void testMongoDbTsvTabInValue() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.MONGODB_TSV)) { printer.printRecord("a\tb", "c"); @@ -870,7 +870,7 @@ public void testMongoDbTsvTabInValue() throws IOException { } @Test - public void testMultiLineComment() throws IOException { + void testMultiLineComment() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withCommentMarker('#'))) { printer.printComment("This is a comment\non multiple lines"); @@ -881,7 +881,7 @@ public void testMultiLineComment() throws IOException { } @Test - public void testMySqlNullOutput() throws IOException { + void testMySqlNullOutput() throws IOException { Object[] s = new String[] { "NULL", null }; CSVFormat format = CSVFormat.MYSQL.withQuote(DQUOTE_CHAR).withNullString("NULL") .withQuoteMode(QuoteMode.NON_NUMERIC); @@ -984,22 +984,22 @@ public void testMySqlNullOutput() throws IOException { } @Test - public void testMySqlNullStringDefault() { + void testMySqlNullStringDefault() { assertEquals("\\N", CSVFormat.MYSQL.getNullString()); } @Test - public void testNewCsvPrinterAppendableNullFormat() { + void testNewCsvPrinterAppendableNullFormat() { assertThrows(NullPointerException.class, () -> new CSVPrinter(new StringWriter(), null)); } @Test - public void testNewCsvPrinterNullAppendableFormat() { + void testNewCsvPrinterNullAppendableFormat() { assertThrows(NullPointerException.class, () -> new CSVPrinter(null, CSVFormat.DEFAULT)); } @Test - public void testNotFlushable() throws IOException { + void testNotFlushable() throws IOException { final Appendable out = new StringBuilder(); try (final CSVPrinter printer = new CSVPrinter(out, CSVFormat.DEFAULT)) { printer.printRecord("a", "b", "c"); @@ -1009,7 +1009,7 @@ public void testNotFlushable() throws IOException { } @Test - public void testParseCustomNullValues() throws IOException { + void testParseCustomNullValues() throws IOException { final StringWriter sw = new StringWriter(); final CSVFormat format = CSVFormat.DEFAULT.withNullString("NULL"); try (final CSVPrinter printer = new CSVPrinter(sw, format)) { @@ -1028,7 +1028,7 @@ public void testParseCustomNullValues() throws IOException { } @Test - public void testPlainEscaped() throws IOException { + void testPlainEscaped() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(null).withEscape('!'))) { printer.print("abc"); @@ -1038,7 +1038,7 @@ public void testPlainEscaped() throws IOException { } @Test - public void testPlainPlain() throws IOException { + void testPlainPlain() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(null))) { printer.print("abc"); @@ -1048,7 +1048,7 @@ public void testPlainPlain() throws IOException { } @Test - public void testPlainQuoted() throws IOException { + void testPlainQuoted() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote('\''))) { printer.print("abc"); @@ -1058,7 +1058,7 @@ public void testPlainQuoted() throws IOException { @Test @Disabled - public void testPostgreSqlCsvNullOutput() throws IOException { + void testPostgreSqlCsvNullOutput() throws IOException { Object[] s = new String[] { "NULL", null }; CSVFormat format = CSVFormat.POSTGRESQL_CSV.withQuote(DQUOTE_CHAR).withNullString("NULL").withQuoteMode(QuoteMode.ALL_NON_NULL); StringWriter writer = new StringWriter(); @@ -1161,7 +1161,7 @@ public void testPostgreSqlCsvNullOutput() throws IOException { @Test @Disabled - public void testPostgreSqlCsvTextOutput() throws IOException { + void testPostgreSqlCsvTextOutput() throws IOException { Object[] s = new String[] { "NULL", null }; CSVFormat format = CSVFormat.POSTGRESQL_TEXT.withQuote(DQUOTE_CHAR).withNullString("NULL").withQuoteMode(QuoteMode.ALL_NON_NULL); StringWriter writer = new StringWriter(); @@ -1263,17 +1263,17 @@ public void testPostgreSqlCsvTextOutput() throws IOException { } @Test - public void testPostgreSqlNullStringDefaultCsv() { + void testPostgreSqlNullStringDefaultCsv() { assertEquals("", CSVFormat.POSTGRESQL_CSV.getNullString()); } @Test - public void testPostgreSqlNullStringDefaultText() { + void testPostgreSqlNullStringDefaultText() { assertEquals("\\N", CSVFormat.POSTGRESQL_TEXT.getNullString()); } @Test - public void testPrint() throws IOException { + void testPrint() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = CSVFormat.DEFAULT.print(sw)) { printer.printRecord("a", "b\\c"); @@ -1282,7 +1282,7 @@ public void testPrint() throws IOException { } @Test - public void testPrintCSVParser() throws IOException { + void testPrintCSVParser() throws IOException { final String code = "a1,b1\n" // 1) + "a2,b2\n" // 2) + "a3,b3\n" // 3) @@ -1302,7 +1302,7 @@ public void testPrintCSVParser() throws IOException { } @Test - public void testPrintCSVRecord() throws IOException { + void testPrintCSVRecord() throws IOException { final String code = "a1,b1\n" // 1) + "a2,b2\n" // 2) + "a3,b3\n" // 3) @@ -1324,7 +1324,7 @@ public void testPrintCSVRecord() throws IOException { } @Test - public void testPrintCSVRecords() throws IOException { + void testPrintCSVRecords() throws IOException { final String code = "a1,b1\n" // 1) + "a2,b2\n" // 2) + "a3,b3\n" // 3) @@ -1344,7 +1344,7 @@ public void testPrintCSVRecords() throws IOException { } @Test - public void testPrintCustomNullValues() throws IOException { + void testPrintCustomNullValues() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withNullString("NULL"))) { printer.printRecord("a", null, "b"); @@ -1353,7 +1353,7 @@ public void testPrintCustomNullValues() throws IOException { } @Test - public void testPrinter1() throws IOException { + void testPrinter1() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT)) { printer.printRecord("a", "b"); @@ -1362,7 +1362,7 @@ public void testPrinter1() throws IOException { } @Test - public void testPrinter2() throws IOException { + void testPrinter2() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT)) { printer.printRecord("a,b", "b"); @@ -1371,7 +1371,7 @@ public void testPrinter2() throws IOException { } @Test - public void testPrinter3() throws IOException { + void testPrinter3() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT)) { printer.printRecord("a, b", "b "); @@ -1380,7 +1380,7 @@ public void testPrinter3() throws IOException { } @Test - public void testPrinter4() throws IOException { + void testPrinter4() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT)) { printer.printRecord("a", "b\"c"); @@ -1389,7 +1389,7 @@ public void testPrinter4() throws IOException { } @Test - public void testPrinter5() throws IOException { + void testPrinter5() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT)) { printer.printRecord("a", "b\nc"); @@ -1398,7 +1398,7 @@ public void testPrinter5() throws IOException { } @Test - public void testPrinter6() throws IOException { + void testPrinter6() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT)) { printer.printRecord("a", "b\r\nc"); @@ -1407,7 +1407,7 @@ public void testPrinter6() throws IOException { } @Test - public void testPrinter7() throws IOException { + void testPrinter7() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT)) { printer.printRecord("a", "b\\c"); @@ -1416,7 +1416,7 @@ public void testPrinter7() throws IOException { } @Test - public void testPrintNullValues() throws IOException { + void testPrintNullValues() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT)) { printer.printRecord("a", null, "b"); @@ -1425,7 +1425,7 @@ public void testPrintNullValues() throws IOException { } @Test - public void testPrintOnePositiveInteger() throws IOException { + void testPrintOnePositiveInteger() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuoteMode(QuoteMode.MINIMAL))) { printer.print(Integer.MAX_VALUE); @@ -1444,7 +1444,7 @@ public void testPrintOnePositiveInteger() throws IOException { * @throws IOException Not expected to happen */ @Test - public void testPrintReaderWithoutQuoteToAppendable() throws IOException { + void testPrintReaderWithoutQuoteToAppendable() throws IOException { final StringBuilder sb = new StringBuilder(); final String content = "testValue"; try (final CSVPrinter printer = new CSVPrinter(sb, CSVFormat.DEFAULT.withQuote(null))) { @@ -1465,7 +1465,7 @@ public void testPrintReaderWithoutQuoteToAppendable() throws IOException { * @throws IOException Not expected to happen */ @Test - public void testPrintReaderWithoutQuoteToWriter() throws IOException { + void testPrintReaderWithoutQuoteToWriter() throws IOException { final StringWriter sw = new StringWriter(); final String content = "testValue"; try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(null))) { @@ -1476,7 +1476,7 @@ public void testPrintReaderWithoutQuoteToWriter() throws IOException { } @Test - public void testPrintRecordStream() throws IOException { + void testPrintRecordStream() throws IOException { final String code = "a1,b1\n" // 1) + "a2,b2\n" // 2) + "a3,b3\n" // 3) @@ -1498,7 +1498,7 @@ public void testPrintRecordStream() throws IOException { } @Test - public void testPrintRecordsWithCSVRecord() throws IOException { + void testPrintRecordsWithCSVRecord() throws IOException { final String[] values = {"A", "B", "C"}; final String rowData = StringUtils.join(values, ','); final CharArrayWriter charArrayWriter = new CharArrayWriter(0); @@ -1513,7 +1513,7 @@ public void testPrintRecordsWithCSVRecord() throws IOException { } @Test - public void testPrintRecordsWithEmptyVector() throws IOException { + void testPrintRecordsWithEmptyVector() throws IOException { final PrintStream out = System.out; try { System.setOut(new PrintStream(NullOutputStream.INSTANCE)); @@ -1530,7 +1530,7 @@ public void testPrintRecordsWithEmptyVector() throws IOException { } @Test - public void testPrintRecordsWithObjectArray() throws IOException { + void testPrintRecordsWithObjectArray() throws IOException { final CharArrayWriter charArrayWriter = new CharArrayWriter(0); try (CSVPrinter csvPrinter = CSVFormat.INFORMIX_UNLOAD.print(charArrayWriter)) { final HashSet hashSet = new HashSet<>(); @@ -1543,7 +1543,7 @@ public void testPrintRecordsWithObjectArray() throws IOException { } @Test - public void testPrintRecordsWithResultSetOneRow() throws IOException, SQLException { + void testPrintRecordsWithResultSetOneRow() throws IOException, SQLException { try (CSVPrinter csvPrinter = CSVFormat.MYSQL.printer()) { try (ResultSet resultSet = new SimpleResultSet()) { csvPrinter.printRecords(resultSet); @@ -1553,7 +1553,7 @@ public void testPrintRecordsWithResultSetOneRow() throws IOException, SQLExcepti } @Test - public void testPrintToFileWithCharsetUtf16Be() throws IOException { + void testPrintToFileWithCharsetUtf16Be() throws IOException { final File file = createTempFile(); try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file, StandardCharsets.UTF_16BE)) { printer.printRecord("a", "b\\c"); @@ -1562,7 +1562,7 @@ public void testPrintToFileWithCharsetUtf16Be() throws IOException { } @Test - public void testPrintToFileWithDefaultCharset() throws IOException { + void testPrintToFileWithDefaultCharset() throws IOException { final File file = createTempFile(); try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file, Charset.defaultCharset())) { printer.printRecord("a", "b\\c"); @@ -1571,7 +1571,7 @@ public void testPrintToFileWithDefaultCharset() throws IOException { } @Test - public void testPrintToPathWithDefaultCharset() throws IOException { + void testPrintToPathWithDefaultCharset() throws IOException { final Path file = createTempPath(); try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file, Charset.defaultCharset())) { printer.printRecord("a", "b\\c"); @@ -1580,7 +1580,7 @@ public void testPrintToPathWithDefaultCharset() throws IOException { } @Test - public void testQuoteAll() throws IOException { + void testQuoteAll() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuoteMode(QuoteMode.ALL))) { printer.printRecord("a", "b\nc", "d"); @@ -1589,7 +1589,7 @@ public void testQuoteAll() throws IOException { } @Test - public void testQuoteCommaFirstChar() throws IOException { + void testQuoteCommaFirstChar() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.RFC4180)) { printer.printRecord(","); @@ -1598,7 +1598,7 @@ public void testQuoteCommaFirstChar() throws IOException { } @Test - public void testQuoteNonNumeric() throws IOException { + void testQuoteNonNumeric() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuoteMode(QuoteMode.NON_NUMERIC))) { printer.printRecord("a", "b\nc", Integer.valueOf(1)); @@ -1607,56 +1607,56 @@ public void testQuoteNonNumeric() throws IOException { } @Test - public void testRandomDefault() throws Exception { + void testRandomDefault() throws Exception { doRandom(CSVFormat.DEFAULT, ITERATIONS_FOR_RANDOM_TEST); } @Test - public void testRandomExcel() throws Exception { + void testRandomExcel() throws Exception { doRandom(CSVFormat.EXCEL, ITERATIONS_FOR_RANDOM_TEST); } @Test @Disabled - public void testRandomMongoDbCsv() throws Exception { + void testRandomMongoDbCsv() throws Exception { doRandom(CSVFormat.MONGODB_CSV, ITERATIONS_FOR_RANDOM_TEST); } @Test - public void testRandomMySql() throws Exception { + void testRandomMySql() throws Exception { doRandom(CSVFormat.MYSQL, ITERATIONS_FOR_RANDOM_TEST); } @Test @Disabled - public void testRandomOracle() throws Exception { + void testRandomOracle() throws Exception { doRandom(CSVFormat.ORACLE, ITERATIONS_FOR_RANDOM_TEST); } @Test @Disabled - public void testRandomPostgreSqlCsv() throws Exception { + void testRandomPostgreSqlCsv() throws Exception { doRandom(CSVFormat.POSTGRESQL_CSV, ITERATIONS_FOR_RANDOM_TEST); } @Test - public void testRandomPostgreSqlText() throws Exception { + void testRandomPostgreSqlText() throws Exception { doRandom(CSVFormat.POSTGRESQL_TEXT, ITERATIONS_FOR_RANDOM_TEST); } @Test - public void testRandomRfc4180() throws Exception { + void testRandomRfc4180() throws Exception { doRandom(CSVFormat.RFC4180, ITERATIONS_FOR_RANDOM_TEST); } @Test - public void testRandomTdf() throws Exception { + void testRandomTdf() throws Exception { doRandom(CSVFormat.TDF, ITERATIONS_FOR_RANDOM_TEST); } @Test - public void testSingleLineComment() throws IOException { + void testSingleLineComment() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withCommentMarker('#'))) { printer.printComment("This is a comment"); @@ -1665,7 +1665,7 @@ public void testSingleLineComment() throws IOException { } @Test - public void testSingleQuoteQuoted() throws IOException { + void testSingleQuoteQuoted() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote('\''))) { printer.print("a'b'c"); @@ -1675,7 +1675,7 @@ public void testSingleQuoteQuoted() throws IOException { } @Test - public void testSkipHeaderRecordFalse() throws IOException { + void testSkipHeaderRecordFalse() throws IOException { // functionally identical to testHeader, used to test CSV-153 final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, @@ -1687,7 +1687,7 @@ public void testSkipHeaderRecordFalse() throws IOException { } @Test - public void testSkipHeaderRecordTrue() throws IOException { + void testSkipHeaderRecordTrue() throws IOException { // functionally identical to testHeaderNotSet, used to test CSV-153 final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, @@ -1699,7 +1699,7 @@ public void testSkipHeaderRecordTrue() throws IOException { } @Test - public void testTrailingDelimiterOnTwoColumns() throws IOException { + void testTrailingDelimiterOnTwoColumns() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withTrailingDelimiter())) { printer.printRecord("A", "B"); @@ -1708,7 +1708,7 @@ public void testTrailingDelimiterOnTwoColumns() throws IOException { } @Test - public void testTrimOffOneColumn() throws IOException { + void testTrimOffOneColumn() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withTrim(false))) { printer.print(" A "); @@ -1717,7 +1717,7 @@ public void testTrimOffOneColumn() throws IOException { } @Test - public void testTrimOnOneColumn() throws IOException { + void testTrimOnOneColumn() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withTrim())) { printer.print(" A "); @@ -1726,7 +1726,7 @@ public void testTrimOnOneColumn() throws IOException { } @Test - public void testTrimOnTwoColumns() throws IOException { + void testTrimOnTwoColumns() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withTrim())) { printer.print(" A "); diff --git a/src/test/java/org/apache/commons/csv/CSVRecordTest.java b/src/test/java/org/apache/commons/csv/CSVRecordTest.java index 9be416cf7b..e684b5575b 100644 --- a/src/test/java/org/apache/commons/csv/CSVRecordTest.java +++ b/src/test/java/org/apache/commons/csv/CSVRecordTest.java @@ -42,7 +42,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class CSVRecordTest { +class CSVRecordTest { private enum EnumFixture { UNKNOWN_COLUMN @@ -69,7 +69,7 @@ public String toString() { private String[] values; @BeforeEach - public void setUp() throws Exception { + void setUp() throws Exception { values = new String[] { "A", "B", "C" }; final String rowData = StringUtils.join(values, ','); try (final CSVParser parser = CSVFormat.DEFAULT.parse(new StringReader(rowData))) { @@ -82,7 +82,7 @@ record = parser.iterator().next(); } @Test - public void testCSVRecordNULLValues() throws IOException { + void testCSVRecordNULLValues() throws IOException { final CSVParser parser = CSVParser.parse("A,B\r\nONE,TWO", CSVFormat.DEFAULT.withHeader()); final CSVRecord csvRecord = new CSVRecord(parser, null, null, 0L, 0L); assertEquals(0, csvRecord.size()); @@ -90,7 +90,7 @@ public void testCSVRecordNULLValues() throws IOException { } @Test - public void testDuplicateHeaderGet() throws IOException { + void testDuplicateHeaderGet() throws IOException { final String csv = "A,A,B,B\n1,2,5,6\n"; final CSVFormat format = CSVFormat.DEFAULT.builder().setHeader().build(); @@ -105,7 +105,7 @@ public void testDuplicateHeaderGet() throws IOException { } @Test - public void testDuplicateHeaderToMap() throws IOException { + void testDuplicateHeaderToMap() throws IOException { final String csv = "A,A,B,B\n1,2,5,6\n"; final CSVFormat format = CSVFormat.DEFAULT.builder().setHeader().build(); @@ -121,64 +121,64 @@ public void testDuplicateHeaderToMap() throws IOException { } @Test - public void testGetInt() { + void testGetInt() { assertEquals(values[0], record.get(0)); assertEquals(values[1], record.get(1)); assertEquals(values[2], record.get(2)); } @Test - public void testGetNullEnum() { + void testGetNullEnum() { assertThrows(IllegalArgumentException.class, () -> recordWithHeader.get((Enum) null)); } @Test - public void testGetString() { + void testGetString() { assertEquals(values[0], recordWithHeader.get(EnumHeader.FIRST.name())); assertEquals(values[1], recordWithHeader.get(EnumHeader.SECOND.name())); assertEquals(values[2], recordWithHeader.get(EnumHeader.THIRD.name())); } @Test - public void testGetStringInconsistentRecord() { + void testGetStringInconsistentRecord() { headerMap.put("fourth", Integer.valueOf(4)); assertThrows(IllegalArgumentException.class, () -> recordWithHeader.get("fourth")); } @Test - public void testGetStringNoHeader() { + void testGetStringNoHeader() { assertThrows(IllegalStateException.class, () -> record.get("first")); } @Test - public void testGetUnmappedEnum() { + void testGetUnmappedEnum() { assertThrows(IllegalArgumentException.class, () -> recordWithHeader.get(EnumFixture.UNKNOWN_COLUMN)); } @Test - public void testGetUnmappedName() { + void testGetUnmappedName() { assertThrows(IllegalArgumentException.class, () -> assertNull(recordWithHeader.get("fourth"))); } @Test - public void testGetUnmappedNegativeInt() { + void testGetUnmappedNegativeInt() { assertThrows(ArrayIndexOutOfBoundsException.class, () -> recordWithHeader.get(Integer.MIN_VALUE)); } @Test - public void testGetUnmappedPositiveInt() { + void testGetUnmappedPositiveInt() { assertThrows(ArrayIndexOutOfBoundsException.class, () -> recordWithHeader.get(Integer.MAX_VALUE)); } @Test - public void testGetWithEnum() { + void testGetWithEnum() { assertEquals(recordWithHeader.get("FIRST"), recordWithHeader.get(EnumHeader.FIRST)); assertEquals(recordWithHeader.get("SECOND"), recordWithHeader.get(EnumHeader.SECOND)); assertThrows(IllegalArgumentException.class, () -> recordWithHeader.get(EnumFixture.UNKNOWN_COLUMN)); } @Test - public void testIsConsistent() { + void testIsConsistent() { assertTrue(record.isConsistent()); assertTrue(recordWithHeader.isConsistent()); final Map map = recordWithHeader.getParser().getHeaderMap(); @@ -188,7 +188,7 @@ public void testIsConsistent() { } @Test - public void testIsInconsistent() throws IOException { + void testIsInconsistent() throws IOException { final String[] headers = { "first", "second", "third" }; final String rowData = StringUtils.join(values, ','); try (final CSVParser parser = CSVFormat.DEFAULT.withHeader(headers).parse(new StringReader(rowData))) { @@ -200,14 +200,14 @@ public void testIsInconsistent() throws IOException { } @Test - public void testIsMapped() { + void testIsMapped() { assertFalse(record.isMapped("first")); assertTrue(recordWithHeader.isMapped(EnumHeader.FIRST.name())); assertFalse(recordWithHeader.isMapped("fourth")); } @Test - public void testIsSetInt() { + void testIsSetInt() { assertFalse(record.isSet(-1)); assertTrue(record.isSet(0)); assertTrue(record.isSet(2)); @@ -217,14 +217,14 @@ public void testIsSetInt() { } @Test - public void testIsSetString() { + void testIsSetString() { assertFalse(record.isSet("first")); assertTrue(recordWithHeader.isSet(EnumHeader.FIRST.name())); assertFalse(recordWithHeader.isSet("DOES NOT EXIST")); } @Test - public void testIterator() { + void testIterator() { int i = 0; for (final String value : record) { assertEquals(values[i], value); @@ -233,7 +233,7 @@ public void testIterator() { } @Test - public void testPutInMap() { + void testPutInMap() { final Map map = new ConcurrentHashMap<>(); this.recordWithHeader.putIn(map); this.validateMap(map, false); @@ -243,7 +243,7 @@ public void testPutInMap() { } @Test - public void testRemoveAndAddColumns() throws IOException { + void testRemoveAndAddColumns() throws IOException { // do: try (final CSVPrinter printer = new CSVPrinter(new StringBuilder(), CSVFormat.DEFAULT)) { final Map map = recordWithHeader.toMap(); @@ -258,7 +258,7 @@ public void testRemoveAndAddColumns() throws IOException { } @Test - public void testSerialization() throws IOException, ClassNotFoundException { + void testSerialization() throws IOException, ClassNotFoundException { final CSVRecord shortRec; try (final CSVParser parser = CSVParser.parse("A,B\n#my comment\nOne,Two", CSVFormat.DEFAULT.withHeader().withCommentMarker('#'))) { shortRec = parser.iterator().next(); @@ -291,7 +291,7 @@ public void testSerialization() throws IOException, ClassNotFoundException { } @Test - public void testStream() { + void testStream() { final AtomicInteger i = new AtomicInteger(); record.stream().forEach(value -> { assertEquals(values[i.get()], value); @@ -300,7 +300,7 @@ public void testStream() { } @Test - public void testToListAdd() { + void testToListAdd() { final String[] expected = values.clone(); final List list = record.toList(); list.add("Last"); @@ -310,7 +310,7 @@ public void testToListAdd() { } @Test - public void testToListFor() { + void testToListFor() { int i = 0; for (final String value : record.toList()) { assertEquals(values[i], value); @@ -319,7 +319,7 @@ public void testToListFor() { } @Test - public void testToListForEach() { + void testToListForEach() { final AtomicInteger i = new AtomicInteger(); record.toList().forEach(e -> { assertEquals(values[i.getAndIncrement()], e); @@ -327,7 +327,7 @@ public void testToListForEach() { } @Test - public void testToListSet() { + void testToListSet() { final String[] expected = values.clone(); final List list = record.toList(); list.set(list.size() - 1, "Last"); @@ -337,13 +337,13 @@ public void testToListSet() { } @Test - public void testToMap() { + void testToMap() { final Map map = this.recordWithHeader.toMap(); this.validateMap(map, true); } @Test - public void testToMapWithNoHeader() throws Exception { + void testToMapWithNoHeader() throws Exception { try (final CSVParser parser = CSVParser.parse("a,b", CSVFormat.newFormat(','))) { final CSVRecord shortRec = parser.iterator().next(); final Map map = shortRec.toMap(); @@ -353,7 +353,7 @@ public void testToMapWithNoHeader() throws Exception { } @Test - public void testToMapWithShortRecord() throws Exception { + void testToMapWithShortRecord() throws Exception { try (final CSVParser parser = CSVParser.parse("a,b", CSVFormat.DEFAULT.withHeader("A", "B", "C"))) { final CSVRecord shortRec = parser.iterator().next(); shortRec.toMap(); @@ -361,7 +361,7 @@ public void testToMapWithShortRecord() throws Exception { } @Test - public void testToString() { + void testToString() { assertNotNull(recordWithHeader.toString()); assertTrue(recordWithHeader.toString().contains("comment=")); assertTrue(recordWithHeader.toString().contains("recordNumber=")); diff --git a/src/test/java/org/apache/commons/csv/ExtendedBufferedReaderTest.java b/src/test/java/org/apache/commons/csv/ExtendedBufferedReaderTest.java index a6396ee518..8aa72d0168 100644 --- a/src/test/java/org/apache/commons/csv/ExtendedBufferedReaderTest.java +++ b/src/test/java/org/apache/commons/csv/ExtendedBufferedReaderTest.java @@ -30,14 +30,14 @@ /** * Test {@link ExtendedBufferedReader}. */ -public class ExtendedBufferedReaderTest { +class ExtendedBufferedReaderTest { private ExtendedBufferedReader createBufferedReader(final String s) { return new ExtendedBufferedReader(new StringReader(s)); } @Test - public void testEmptyInput() throws Exception { + void testEmptyInput() throws Exception { try (final ExtendedBufferedReader br = createBufferedReader("")) { assertEquals(END_OF_STREAM, br.read()); assertEquals(END_OF_STREAM, br.lookAhead()); @@ -52,7 +52,7 @@ public void testEmptyInput() throws Exception { * */ @Test - public void testReadChar() throws Exception { + void testReadChar() throws Exception { final String LF = "\n"; final String CR = "\r"; final String CRLF = CR + LF; @@ -86,7 +86,7 @@ public void testReadChar() throws Exception { } @Test - public void testReadingInDifferentBuffer() throws Exception { + void testReadingInDifferentBuffer() throws Exception { final char[] tmp1 = new char[2], tmp2 = new char[4]; try (ExtendedBufferedReader reader = createBufferedReader("1\r\n2\r\n")) { reader.read(tmp1, 0, 2); @@ -96,7 +96,7 @@ public void testReadingInDifferentBuffer() throws Exception { } @Test - public void testReadLine() throws Exception { + void testReadLine() throws Exception { try (final ExtendedBufferedReader br = createBufferedReader("")) { assertNull(br.readLine()); } @@ -139,7 +139,7 @@ public void testReadLine() throws Exception { } @Test - public void testReadLookahead1() throws Exception { + void testReadLookahead1() throws Exception { try (final ExtendedBufferedReader br = createBufferedReader("1\n2\r3\n")) { assertEquals(0, br.getCurrentLineNumber()); assertEquals('1', br.lookAhead()); @@ -198,7 +198,7 @@ public void testReadLookahead1() throws Exception { } @Test - public void testReadLookahead2() throws Exception { + void testReadLookahead2() throws Exception { final char[] ref = new char[5]; final char[] res = new char[5]; diff --git a/src/test/java/org/apache/commons/csv/LexerTest.java b/src/test/java/org/apache/commons/csv/LexerTest.java index f36eaa4533..d6f7c393d5 100644 --- a/src/test/java/org/apache/commons/csv/LexerTest.java +++ b/src/test/java/org/apache/commons/csv/LexerTest.java @@ -42,7 +42,7 @@ /** */ -public class LexerTest { +class LexerTest { private CSVFormat formatWithEscaping; @@ -52,13 +52,13 @@ private Lexer createLexer(final String input, final CSVFormat format) { } @BeforeEach - public void setUp() { + void setUp() { formatWithEscaping = CSVFormat.DEFAULT.withEscape('\\'); } // simple token with escaping enabled @Test - public void testBackslashWithEscaping() throws IOException { + void testBackslashWithEscaping() throws IOException { /* * file: a,\,,b \,, */ @@ -78,7 +78,7 @@ public void testBackslashWithEscaping() throws IOException { // simple token with escaping not enabled @Test - public void testBackslashWithoutEscaping() throws IOException { + void testBackslashWithoutEscaping() throws IOException { /* * file: a,\,,b \,, */ @@ -99,14 +99,14 @@ public void testBackslashWithoutEscaping() throws IOException { } @Test - public void testBackspace() throws Exception { + void testBackspace() throws Exception { try (final Lexer lexer = createLexer("character" + BACKSPACE + "NotEscaped", formatWithEscaping)) { assertThat(lexer.nextToken(new Token()), hasContent("character" + BACKSPACE + "NotEscaped")); } } @Test - public void testComments() throws IOException { + void testComments() throws IOException { final String code = "first,line,\n" + "second,line,tokenWith#no-comment\n" + "# comment line \n" + "third,line,#no-comment\n" + "# penultimate comment\n" + "# Final comment\n"; final CSVFormat format = CSVFormat.DEFAULT.withCommentMarker('#'); @@ -129,7 +129,7 @@ public void testComments() throws IOException { } @Test - public void testCommentsAndEmptyLines() throws IOException { + void testCommentsAndEmptyLines() throws IOException { final String code = "1,2,3,\n" + // 1 "\n" + // 1b "\n" + // 1c @@ -175,7 +175,7 @@ public void testCommentsAndEmptyLines() throws IOException { } @Test - public void testCR() throws Exception { + void testCR() throws Exception { try (final Lexer lexer = createLexer("character" + CR + "NotEscaped", formatWithEscaping)) { assertThat(lexer.nextToken(new Token()), hasContent("character")); assertThat(lexer.nextToken(new Token()), hasContent("NotEscaped")); @@ -184,7 +184,7 @@ public void testCR() throws Exception { // From CSV-1 @Test - public void testDelimiterIsWhitespace() throws IOException { + void testDelimiterIsWhitespace() throws IOException { final String code = "one\ttwo\t\tfour \t five\t six"; try (final Lexer parser = createLexer(code, CSVFormat.TDF)) { assertThat(parser.nextToken(new Token()), matches(TOKEN, "one")); @@ -197,21 +197,21 @@ public void testDelimiterIsWhitespace() throws IOException { } @Test // TODO is this correct? Do we expect BACKSPACE to be unescaped? - public void testEscapedBackspace() throws Exception { + void testEscapedBackspace() throws Exception { try (final Lexer lexer = createLexer("character\\" + BACKSPACE + "Escaped", formatWithEscaping)) { assertThat(lexer.nextToken(new Token()), hasContent("character" + BACKSPACE + "Escaped")); } } @Test - public void testEscapedCharacter() throws Exception { + void testEscapedCharacter() throws Exception { try (final Lexer lexer = createLexer("character\\aEscaped", formatWithEscaping)) { assertThat(lexer.nextToken(new Token()), hasContent("character\\aEscaped")); } } @Test - public void testEscapedControlCharacter() throws Exception { + void testEscapedControlCharacter() throws Exception { // we are explicitly using an escape different from \ here try (final Lexer lexer = createLexer("character!rEscaped", CSVFormat.DEFAULT.withEscape('!'))) { assertThat(lexer.nextToken(new Token()), hasContent("character" + CR + "Escaped")); @@ -219,35 +219,35 @@ public void testEscapedControlCharacter() throws Exception { } @Test - public void testEscapedControlCharacter2() throws Exception { + void testEscapedControlCharacter2() throws Exception { try (final Lexer lexer = createLexer("character\\rEscaped", CSVFormat.DEFAULT.withEscape('\\'))) { assertThat(lexer.nextToken(new Token()), hasContent("character" + CR + "Escaped")); } } @Test - public void testEscapedCR() throws Exception { + void testEscapedCR() throws Exception { try (final Lexer lexer = createLexer("character\\" + CR + "Escaped", formatWithEscaping)) { assertThat(lexer.nextToken(new Token()), hasContent("character" + CR + "Escaped")); } } @Test // TODO is this correct? Do we expect FF to be unescaped? - public void testEscapedFF() throws Exception { + void testEscapedFF() throws Exception { try (final Lexer lexer = createLexer("character\\" + FF + "Escaped", formatWithEscaping)) { assertThat(lexer.nextToken(new Token()), hasContent("character" + FF + "Escaped")); } } @Test - public void testEscapedLF() throws Exception { + void testEscapedLF() throws Exception { try (final Lexer lexer = createLexer("character\\" + LF + "Escaped", formatWithEscaping)) { assertThat(lexer.nextToken(new Token()), hasContent("character" + LF + "Escaped")); } } @Test - public void testEscapedMySqlNullValue() throws Exception { + void testEscapedMySqlNullValue() throws Exception { // MySQL uses \N to symbolize null values. We have to restore this try (final Lexer lexer = createLexer("character\\NEscaped", formatWithEscaping)) { assertThat(lexer.nextToken(new Token()), hasContent("character\\NEscaped")); @@ -255,7 +255,7 @@ public void testEscapedMySqlNullValue() throws Exception { } @Test // TODO is this correct? Do we expect TAB to be unescaped? - public void testEscapedTab() throws Exception { + void testEscapedTab() throws Exception { try (final Lexer lexer = createLexer("character\\" + TAB + "Escaped", formatWithEscaping)) { assertThat(lexer.nextToken(new Token()), hasContent("character" + TAB + "Escaped")); } @@ -263,7 +263,7 @@ public void testEscapedTab() throws Exception { } @Test - public void testEscapingAtEOF() throws Exception { + void testEscapingAtEOF() throws Exception { final String code = "escaping at EOF is evil\\"; try (final Lexer lexer = createLexer(code, formatWithEscaping)) { assertThrows(IOException.class, () -> lexer.nextToken(new Token())); @@ -271,14 +271,14 @@ public void testEscapingAtEOF() throws Exception { } @Test - public void testFF() throws Exception { + void testFF() throws Exception { try (final Lexer lexer = createLexer("character" + FF + "NotEscaped", formatWithEscaping)) { assertThat(lexer.nextToken(new Token()), hasContent("character" + FF + "NotEscaped")); } } @Test - public void testIgnoreEmptyLines() throws IOException { + void testIgnoreEmptyLines() throws IOException { final String code = "first,line,\n" + "\n" + "\n" + "second,line\n" + "\n" + "\n" + "third line \n" + "\n" + "\n" + "last, line \n" + "\n" + "\n" + "\n"; final CSVFormat format = CSVFormat.DEFAULT.withIgnoreEmptyLines(); @@ -297,7 +297,7 @@ public void testIgnoreEmptyLines() throws IOException { } @Test - public void testIsMetaCharCommentStart() throws IOException { + void testIsMetaCharCommentStart() throws IOException { try (final Lexer lexer = createLexer("#", CSVFormat.DEFAULT.withCommentMarker('#'))) { final int ch = lexer.readEscape(); assertEquals('#', ch); @@ -305,7 +305,7 @@ public void testIsMetaCharCommentStart() throws IOException { } @Test - public void testLF() throws Exception { + void testLF() throws Exception { try (final Lexer lexer = createLexer("character" + LF + "NotEscaped", formatWithEscaping)) { assertThat(lexer.nextToken(new Token()), hasContent("character")); assertThat(lexer.nextToken(new Token()), hasContent("NotEscaped")); @@ -314,7 +314,7 @@ public void testLF() throws Exception { // encapsulator tokenizer (single line) @Test - public void testNextToken4() throws IOException { + void testNextToken4() throws IOException { /* * file: a,"foo",b a, " foo",b a,"foo " ,b // whitespace after closing encapsulator a, " foo " ,b */ @@ -338,7 +338,7 @@ public void testNextToken4() throws IOException { // encapsulator tokenizer (multi line, delimiter in string) @Test - public void testNextToken5() throws IOException { + void testNextToken5() throws IOException { final String code = "a,\"foo\n\",b\n\"foo\n baar ,,,\"\n\"\n\t \n\""; try (final Lexer parser = createLexer(code, CSVFormat.DEFAULT)) { assertThat(parser.nextToken(new Token()), matches(TOKEN, "a")); @@ -351,7 +351,7 @@ public void testNextToken5() throws IOException { // change delimiters, comment, encapsulater @Test - public void testNextToken6() throws IOException { + void testNextToken6() throws IOException { /* * file: a;'b and \' more ' !comment;;;; ;; */ @@ -364,7 +364,7 @@ public void testNextToken6() throws IOException { } @Test - public void testReadEscapeBackspace() throws IOException { + void testReadEscapeBackspace() throws IOException { try (final Lexer lexer = createLexer("b", CSVFormat.DEFAULT.withEscape('\b'))) { final int ch = lexer.readEscape(); assertEquals(BACKSPACE, ch); @@ -372,7 +372,7 @@ public void testReadEscapeBackspace() throws IOException { } @Test - public void testReadEscapeFF() throws IOException { + void testReadEscapeFF() throws IOException { try (final Lexer lexer = createLexer("f", CSVFormat.DEFAULT.withEscape('\f'))) { final int ch = lexer.readEscape(); assertEquals(FF, ch); @@ -380,7 +380,7 @@ public void testReadEscapeFF() throws IOException { } @Test - public void testReadEscapeTab() throws IOException { + void testReadEscapeTab() throws IOException { try (final Lexer lexer = createLexer("t", CSVFormat.DEFAULT.withEscape('\t'))) { final int ch = lexer.readEscape(); assertThat(lexer.nextToken(new Token()), matches(EOF, "")); @@ -389,7 +389,7 @@ public void testReadEscapeTab() throws IOException { } @Test - public void testSurroundingSpacesAreDeleted() throws IOException { + void testSurroundingSpacesAreDeleted() throws IOException { final String code = "noSpaces, leadingSpaces,trailingSpaces , surroundingSpaces , ,,"; try (final Lexer parser = createLexer(code, CSVFormat.DEFAULT.withIgnoreSurroundingSpaces())) { assertThat(parser.nextToken(new Token()), matches(TOKEN, "noSpaces")); @@ -403,7 +403,7 @@ public void testSurroundingSpacesAreDeleted() throws IOException { } @Test - public void testSurroundingTabsAreDeleted() throws IOException { + void testSurroundingTabsAreDeleted() throws IOException { final String code = "noTabs,\tleadingTab,trailingTab\t,\tsurroundingTabs\t,\t\t,,"; try (final Lexer parser = createLexer(code, CSVFormat.DEFAULT.withIgnoreSurroundingSpaces())) { assertThat(parser.nextToken(new Token()), matches(TOKEN, "noTabs")); @@ -417,14 +417,14 @@ public void testSurroundingTabsAreDeleted() throws IOException { } @Test - public void testTab() throws Exception { + void testTab() throws Exception { try (final Lexer lexer = createLexer("character" + TAB + "NotEscaped", formatWithEscaping)) { assertThat(lexer.nextToken(new Token()), hasContent("character" + TAB + "NotEscaped")); } } @Test - public void testTrimTrailingSpacesZeroLength() throws Exception { + void testTrimTrailingSpacesZeroLength() throws Exception { final StringBuilder buffer = new StringBuilder(""); final Lexer lexer = createLexer(buffer.toString(), CSVFormat.DEFAULT); lexer.trimTrailingSpaces(buffer); From 75ca861253e211b4a80a28420d08e1d135fa73ee Mon Sep 17 00:00:00 2001 From: Ivan Capobianco Date: Mon, 27 Nov 2023 11:03:56 +0100 Subject: [PATCH 18/18] fix: sonarcloud code smell public test method --- .../apache/commons/csv/TokenMatchersTest.java | 14 +++++----- .../commons/csv/issues/JiraCsv148Test.java | 6 ++--- .../commons/csv/issues/JiraCsv149Test.java | 6 ++--- .../commons/csv/issues/JiraCsv154Test.java | 6 ++--- .../commons/csv/issues/JiraCsv167Test.java | 4 +-- .../commons/csv/issues/JiraCsv198Test.java | 4 +-- .../commons/csv/issues/JiraCsv203Test.java | 16 ++++++------ .../commons/csv/issues/JiraCsv206Test.java | 4 +-- .../commons/csv/issues/JiraCsv211Test.java | 4 +-- .../commons/csv/issues/JiraCsv213Test.java | 4 +-- .../commons/csv/issues/JiraCsv247Test.java | 6 ++--- .../commons/csv/issues/JiraCsv248Test.java | 4 +-- .../commons/csv/issues/JiraCsv249Test.java | 4 +-- .../commons/csv/issues/JiraCsv253Test.java | 4 +-- .../commons/csv/issues/JiraCsv263Test.java | 4 +-- .../commons/csv/issues/JiraCsv264Test.java | 8 +++--- .../commons/csv/issues/JiraCsv265Test.java | 6 ++--- .../commons/csv/issues/JiraCsv271Test.java | 6 ++--- .../commons/csv/issues/JiraCsv288Test.java | 26 +++++++++---------- .../commons/csv/issues/JiraCsv290Test.java | 8 +++--- .../commons/csv/issues/JiraCsv93Test.java | 8 +++--- 21 files changed, 76 insertions(+), 76 deletions(-) diff --git a/src/test/java/org/apache/commons/csv/TokenMatchersTest.java b/src/test/java/org/apache/commons/csv/TokenMatchersTest.java index 47c213d7bd..5322f2269f 100644 --- a/src/test/java/org/apache/commons/csv/TokenMatchersTest.java +++ b/src/test/java/org/apache/commons/csv/TokenMatchersTest.java @@ -27,12 +27,12 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class TokenMatchersTest { + class TokenMatchersTest { private Token token; @BeforeEach - public void setUp() { + void setUp() { token = new Token(); token.type = Token.Type.TOKEN; token.isReady = true; @@ -40,13 +40,13 @@ public void setUp() { } @Test - public void testHasContent() { + void testHasContent() { assertFalse(hasContent("This is not the token's content").matches(token)); assertTrue(hasContent("content").matches(token)); } @Test - public void testHasType() { + void testHasType() { assertFalse(hasType(Token.Type.COMMENT).matches(token)); assertFalse(hasType(Token.Type.EOF).matches(token)); assertFalse(hasType(Token.Type.EORECORD).matches(token)); @@ -54,14 +54,14 @@ public void testHasType() { } @Test - public void testIsReady() { + void testIsReady() { assertTrue(isReady().matches(token)); token.isReady = false; assertFalse(isReady().matches(token)); } @Test - public void testMatches() { + void testMatches() { assertTrue(matches(Token.Type.TOKEN, "content").matches(token)); assertFalse(matches(Token.Type.EOF, "content").matches(token)); assertFalse(matches(Token.Type.TOKEN, "not the content").matches(token)); @@ -69,7 +69,7 @@ public void testMatches() { } @Test - public void testToString() { + void testToString() { assertTrue(matches(Token.Type.TOKEN, "content").matches(token)); assertEquals("TOKEN", token.type.name()); assertEquals("TOKEN [content]", token.toString()); diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv148Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv148Test.java index 315d2bf738..4b719dced5 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv148Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv148Test.java @@ -22,10 +22,10 @@ import org.apache.commons.csv.QuoteMode; import org.junit.jupiter.api.Test; -public class JiraCsv148Test { + class JiraCsv148Test { @Test - public void testWithIgnoreSurroundingSpacesEmpty() { + void testWithIgnoreSurroundingSpacesEmpty() { // @formatter:off final CSVFormat format = CSVFormat.DEFAULT.builder() .setQuoteMode(QuoteMode.ALL) @@ -47,7 +47,7 @@ public void testWithIgnoreSurroundingSpacesEmpty() { * you can remove the leading and trailing spaces, tabs and other symbols. */ @Test - public void testWithTrimEmpty() { + void testWithTrimEmpty() { // @formatter:off final CSVFormat format = CSVFormat.DEFAULT.builder() .setQuoteMode(QuoteMode.ALL) diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv149Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv149Test.java index 70f8c5ead4..d67277c50a 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv149Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv149Test.java @@ -27,12 +27,12 @@ import org.apache.commons.csv.CSVRecord; import org.junit.jupiter.api.Test; -public class JiraCsv149Test { + class JiraCsv149Test { private static final String CR_LF = "\r\n"; @Test - public void testJiraCsv149EndWithEOL() throws IOException { + void testJiraCsv149EndWithEOL() throws IOException { testJiraCsv149EndWithEolAtEof(true); } @@ -59,7 +59,7 @@ private void testJiraCsv149EndWithEolAtEof(final boolean eolAtEof) throws IOExce } @Test - public void testJiraCsv149EndWithoutEOL() throws IOException { + void testJiraCsv149EndWithoutEOL() throws IOException { testJiraCsv149EndWithEolAtEof(false); } } diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv154Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv154Test.java index 1f7d93e26b..9cdc4802fb 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv154Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv154Test.java @@ -24,10 +24,10 @@ import org.apache.commons.csv.CSVPrinter; import org.junit.jupiter.api.Test; -public class JiraCsv154Test { + class JiraCsv154Test { @Test - public void testJiraCsv154_withCommentMarker() throws IOException { + void testJiraCsv154_withCommentMarker() throws IOException { final String comment = "This is a header comment"; // @formatter:off final CSVFormat format = CSVFormat.EXCEL.builder() @@ -46,7 +46,7 @@ public void testJiraCsv154_withCommentMarker() throws IOException { } @Test - public void testJiraCsv154_withHeaderComments() throws IOException { + void testJiraCsv154_withHeaderComments() throws IOException { final String comment = "This is a header comment"; // @formatter:off final CSVFormat format = CSVFormat.EXCEL.builder() diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv167Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv167Test.java index 57d63298ef..a02e228fbd 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv167Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv167Test.java @@ -29,7 +29,7 @@ import org.apache.commons.csv.QuoteMode; import org.junit.jupiter.api.Test; -public class JiraCsv167Test { + class JiraCsv167Test { private Reader getTestReader() { return new InputStreamReader( @@ -37,7 +37,7 @@ private Reader getTestReader() { } @Test - public void testParse() throws IOException { + void testParse() throws IOException { int totcomment = 0; int totrecs = 0; try (final Reader reader = getTestReader(); final BufferedReader br = new BufferedReader(reader)) { diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv198Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv198Test.java index 996e2eb3b7..9af475d87d 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv198Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv198Test.java @@ -28,7 +28,7 @@ import org.apache.commons.csv.CSVParser; import org.junit.jupiter.api.Test; -public class JiraCsv198Test { + class JiraCsv198Test { // @formatter:off private static final CSVFormat CSV_FORMAT = CSVFormat.EXCEL.builder() @@ -39,7 +39,7 @@ public class JiraCsv198Test { // @formatter:on @Test - public void test() throws UnsupportedEncodingException, IOException { + void test() throws UnsupportedEncodingException, IOException { final InputStream pointsOfReference = getClass().getResourceAsStream("/org/apache/commons/csv/CSV-198/optd_por_public.csv"); assertNotNull(pointsOfReference); try (@SuppressWarnings("resource") diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv203Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv203Test.java index 17c62351e2..1777f24a0e 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv203Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv203Test.java @@ -27,10 +27,10 @@ * JIRA: withNullString value is printed without quotes when * QuoteMode.ALL is specified */ -public class JiraCsv203Test { + class JiraCsv203Test { @Test - public void testQuoteModeAll() throws Exception { + void testQuoteModeAll() throws Exception { // @formatter:off final CSVFormat format = CSVFormat.EXCEL.builder() .setNullString("N/A") @@ -46,7 +46,7 @@ public void testQuoteModeAll() throws Exception { } @Test - public void testQuoteModeAllNonNull() throws Exception { + void testQuoteModeAllNonNull() throws Exception { // @formatter:off final CSVFormat format = CSVFormat.EXCEL.builder() .setNullString("N/A") @@ -62,7 +62,7 @@ public void testQuoteModeAllNonNull() throws Exception { } @Test - public void testQuoteModeMinimal() throws Exception { + void testQuoteModeMinimal() throws Exception { // @formatter:off final CSVFormat format = CSVFormat.EXCEL.builder() .setNullString("N/A") @@ -78,7 +78,7 @@ public void testQuoteModeMinimal() throws Exception { } @Test - public void testQuoteModeNonNumeric() throws Exception { + void testQuoteModeNonNumeric() throws Exception { // @formatter:off final CSVFormat format = CSVFormat.EXCEL.builder() .setNullString("N/A") @@ -94,7 +94,7 @@ public void testQuoteModeNonNumeric() throws Exception { } @Test - public void testWithEmptyValues() throws Exception { + void testWithEmptyValues() throws Exception { // @formatter:off final CSVFormat format = CSVFormat.EXCEL.builder() .setNullString("N/A") @@ -111,7 +111,7 @@ public void testWithEmptyValues() throws Exception { } @Test - public void testWithoutNullString() throws Exception { + void testWithoutNullString() throws Exception { // @formatter:off final CSVFormat format = CSVFormat.EXCEL.builder() //.setNullString("N/A") @@ -127,7 +127,7 @@ public void testWithoutNullString() throws Exception { } @Test - public void testWithoutQuoteMode() throws Exception { + void testWithoutQuoteMode() throws Exception { // @formatter:off final CSVFormat format = CSVFormat.EXCEL.builder() .setNullString("N/A") diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv206Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv206Test.java index 3d0a4fb4c7..07d5a1b313 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv206Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv206Test.java @@ -28,10 +28,10 @@ import org.apache.commons.csv.CSVRecord; import org.junit.jupiter.api.Test; -public class JiraCsv206Test { + class JiraCsv206Test { @Test - public void testJiraCsv206MultipleCharacterDelimiter() throws IOException { + void testJiraCsv206MultipleCharacterDelimiter() throws IOException { // Read with multiple character delimiter final String source = "FirstName[|]LastName[|]Address\r\nJohn[|]Smith[|]123 Main St."; final StringReader reader = new StringReader(source); diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv211Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv211Test.java index 126e85e504..f3e9960229 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv211Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv211Test.java @@ -25,10 +25,10 @@ import org.apache.commons.csv.CSVParser; import org.junit.jupiter.api.Test; -public class JiraCsv211Test { + class JiraCsv211Test { @Test - public void testJiraCsv211Format() throws IOException { + void testJiraCsv211Format() throws IOException { // @formatter:off final CSVFormat printFormat = CSVFormat.DEFAULT.builder() .setDelimiter('\t') diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv213Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv213Test.java index e175ff0e9e..bb37996058 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv213Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv213Test.java @@ -36,7 +36,7 @@ * you want, you need to open a new CSVParser. *

*/ -public class JiraCsv213Test { + class JiraCsv213Test { private void createEndChannel(final File csvFile) { // @formatter:off @@ -62,7 +62,7 @@ private void createEndChannel(final File csvFile) { } @Test - public void test() { + void test() { createEndChannel(new File("src/test/resources/org/apache/commons/csv/CSV-213/999751170.patch.csv")); } } diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv247Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv247Test.java index 4dc18a001e..9757646b67 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv247Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv247Test.java @@ -32,10 +32,10 @@ import org.apache.commons.csv.CSVRecord; import org.junit.jupiter.api.Test; -public class JiraCsv247Test { + class JiraCsv247Test { @Test - public void testHeadersMissingOneColumnWhenAllowingMissingColumnNames() throws Exception { + void testHeadersMissingOneColumnWhenAllowingMissingColumnNames() throws Exception { final CSVFormat format = CSVFormat.DEFAULT.builder().setHeader().setAllowMissingColumnNames(true).build(); assertTrue(format.getAllowMissingColumnNames(), "We should allow missing column names"); @@ -61,7 +61,7 @@ record = iterator.next(); } @Test - public void testHeadersMissingThrowsWhenNotAllowingMissingColumnNames() { + void testHeadersMissingThrowsWhenNotAllowingMissingColumnNames() { final CSVFormat format = CSVFormat.DEFAULT.builder().setHeader().build(); assertFalse(format.getAllowMissingColumnNames(), "By default we should not allow missing column names"); diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv248Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv248Test.java index d0a10300bb..8c6931c02d 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv248Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv248Test.java @@ -30,7 +30,7 @@ import org.apache.commons.csv.CSVRecord; import org.junit.jupiter.api.Test; -public class JiraCsv248Test { + class JiraCsv248Test { private static InputStream getTestInput() { return ClassLoader.getSystemClassLoader().getResourceAsStream("org/apache/commons/csv/CSV-248/csvRecord.bin"); } @@ -46,7 +46,7 @@ private static InputStream getTestInput() { * @throws ClassNotFoundException If the CSVRecord cannot be deserialized */ @Test - public void testJiraCsv248() throws IOException, ClassNotFoundException { + void testJiraCsv248() throws IOException, ClassNotFoundException { // Record was originally created using CSV version 1.6 with the following code: // try (final CSVParser parser = CSVParser.parse("A,B\n#my comment\nOne,Two", // CSVFormat.DEFAULT.builder().setHeader().setCommentMarker('#'))) { diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv249Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv249Test.java index 7989a4646f..6be1fc5c3b 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv249Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv249Test.java @@ -30,10 +30,10 @@ import org.apache.commons.csv.CSVRecord; import org.junit.jupiter.api.Test; -public class JiraCsv249Test { + class JiraCsv249Test { @Test - public void testJiraCsv249() throws IOException { + void testJiraCsv249() throws IOException { final CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setEscape('\\').build(); final StringWriter stringWriter = new StringWriter(); try (CSVPrinter printer = new CSVPrinter(stringWriter, csvFormat)) { diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv253Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv253Test.java index 90507313eb..0f86324aef 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv253Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv253Test.java @@ -31,7 +31,7 @@ /** * Setting QuoteMode:ALL_NON_NULL or NON_NUMERIC can distinguish between empty string columns and absent value columns. */ -public class JiraCsv253Test { + class JiraCsv253Test { private void assertArrayEqual(final String[] expected, final CSVRecord actual) { for (int i = 0; i < expected.length; i++) { @@ -40,7 +40,7 @@ private void assertArrayEqual(final String[] expected, final CSVRecord actual) { } @Test - public void testHandleAbsentValues() throws IOException { + void testHandleAbsentValues() throws IOException { final String source = "\"John\",,\"Doe\"\n" + ",\"AA\",123\n" + "\"John\",90,\n" + "\"\",,90"; final CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setQuoteMode(QuoteMode.NON_NUMERIC).build(); try (final CSVParser parser = csvFormat.parse(new StringReader(source))) { diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv263Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv263Test.java index 062ed7caf6..e3cbcb808a 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv263Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv263Test.java @@ -30,10 +30,10 @@ /** * Tests [CSV-263] Print from Reader with embedded quotes generates incorrect output. */ -public class JiraCsv263Test { + class JiraCsv263Test { @Test - public void testPrintFromReaderWithQuotes() throws IOException { + void testPrintFromReaderWithQuotes() throws IOException { // @formatter:off final CSVFormat format = CSVFormat.RFC4180.builder() .setDelimiter(',') diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv264Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv264Test.java index 0e18ae55bd..ad923e77e6 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv264Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv264Test.java @@ -33,7 +33,7 @@ * * @see Jira Ticker */ -public class JiraCsv264Test { + class JiraCsv264Test { private static final String CSV_STRING = "\"\",\"B\",\"\"\n" + "\"1\",\"2\",\"3\"\n" + @@ -47,7 +47,7 @@ public class JiraCsv264Test { "\"6\",\"7\",\"\",\"\",\"10\""; @Test - public void testJiraCsv264() { + void testJiraCsv264() { final CSVFormat csvFormat = CSVFormat.DEFAULT .builder() .setHeader() @@ -61,7 +61,7 @@ public void testJiraCsv264() { } @Test - public void testJiraCsv264WithGapAllowEmpty() throws IOException { + void testJiraCsv264WithGapAllowEmpty() throws IOException { final CSVFormat csvFormat = CSVFormat.DEFAULT .builder() .setHeader() @@ -75,7 +75,7 @@ public void testJiraCsv264WithGapAllowEmpty() throws IOException { } @Test - public void testJiraCsv264WithGapDisallow() { + void testJiraCsv264WithGapDisallow() { final CSVFormat csvFormat = CSVFormat.DEFAULT .builder() .setHeader() diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv265Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv265Test.java index f62b866585..eda5f76246 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv265Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv265Test.java @@ -31,10 +31,10 @@ /** * Tests [CSV-265] {@link CSVRecord#getCharacterPosition()} returns the correct position after encountering a comment. */ -public class JiraCsv265Test { + class JiraCsv265Test { @Test - public void testCharacterPositionWithComments() throws IOException { + void testCharacterPositionWithComments() throws IOException { // @formatter:off final String csv = "# Comment1\n" + "Header1,Header2\n" @@ -59,7 +59,7 @@ public void testCharacterPositionWithComments() throws IOException { } @Test - public void testCharacterPositionWithCommentsSpanningMultipleLines() throws IOException { + void testCharacterPositionWithCommentsSpanningMultipleLines() throws IOException { // @formatter:off final String csv = "# Comment1\n" + "# Comment2\n" diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv271Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv271Test.java index 6150a76680..034bc09e9c 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv271Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv271Test.java @@ -27,10 +27,10 @@ import org.apache.commons.csv.CSVPrinter; import org.junit.jupiter.api.Test; -public class JiraCsv271Test { + class JiraCsv271Test { @Test - public void testJiraCsv271_withArray() throws IOException { + void testJiraCsv271_withArray() throws IOException { final CSVFormat csvFormat = CSVFormat.DEFAULT; final StringWriter stringWriter = new StringWriter(); try (CSVPrinter printer = new CSVPrinter(stringWriter, csvFormat)) { @@ -41,7 +41,7 @@ public void testJiraCsv271_withArray() throws IOException { } @Test - public void testJiraCsv271_withList() throws IOException { + void testJiraCsv271_withList() throws IOException { final CSVFormat csvFormat = CSVFormat.DEFAULT; final StringWriter stringWriter = new StringWriter(); try (CSVPrinter printer = new CSVPrinter(stringWriter, csvFormat)) { diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv288Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv288Test.java index 37209e7aff..bf15116e52 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv288Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv288Test.java @@ -29,7 +29,7 @@ import org.apache.commons.csv.CSVRecord; import org.junit.jupiter.api.Test; -public class JiraCsv288Test { + class JiraCsv288Test { private void print(final CSVRecord csvRecord, final CSVPrinter csvPrinter) throws IOException { for (final String value : csvRecord) { @@ -40,7 +40,7 @@ private void print(final CSVRecord csvRecord, final CSVPrinter csvPrinter) throw @Test // Before fix: // expected: but was: - public void testParseWithABADelimiter() throws Exception { + void testParseWithABADelimiter() throws Exception { final Reader in = new StringReader("a|~|b|~|c|~|d|~||~|f"); final StringBuilder stringBuilder = new StringBuilder(); try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL); @@ -55,7 +55,7 @@ public void testParseWithABADelimiter() throws Exception { @Test // Before fix: // expected: but was: - public void testParseWithDoublePipeDelimiter() throws Exception { + void testParseWithDoublePipeDelimiter() throws Exception { final Reader in = new StringReader("a||b||c||d||||f"); final StringBuilder stringBuilder = new StringBuilder(); try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL); @@ -70,7 +70,7 @@ public void testParseWithDoublePipeDelimiter() throws Exception { @Test // Regression, already passed before fix - public void testParseWithDoublePipeDelimiterDoubleCharValue() throws Exception { + void testParseWithDoublePipeDelimiterDoubleCharValue() throws Exception { final Reader in = new StringReader("a||bb||cc||dd||f"); final StringBuilder stringBuilder = new StringBuilder(); try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL); @@ -85,7 +85,7 @@ public void testParseWithDoublePipeDelimiterDoubleCharValue() throws Exception { @Test // Before fix: // expected: but was: - public void testParseWithDoublePipeDelimiterEndsWithDelimiter() throws Exception { + void testParseWithDoublePipeDelimiterEndsWithDelimiter() throws Exception { final Reader in = new StringReader("a||b||c||d||||f||"); final StringBuilder stringBuilder = new StringBuilder(); try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL); @@ -100,7 +100,7 @@ public void testParseWithDoublePipeDelimiterEndsWithDelimiter() throws Exception @Test // Before fix: // expected: but was: - public void testParseWithDoublePipeDelimiterQuoted() throws Exception { + void testParseWithDoublePipeDelimiterQuoted() throws Exception { final Reader in = new StringReader("a||\"b||c\"||d||||f"); final StringBuilder stringBuilder = new StringBuilder(); try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL); @@ -114,7 +114,7 @@ public void testParseWithDoublePipeDelimiterQuoted() throws Exception { @Test // Regression, already passed before fix - public void testParseWithSinglePipeDelimiterEndsWithDelimiter() throws Exception { + void testParseWithSinglePipeDelimiterEndsWithDelimiter() throws Exception { final Reader in = new StringReader("a|b|c|d||f|"); final StringBuilder stringBuilder = new StringBuilder(); try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL); @@ -129,7 +129,7 @@ public void testParseWithSinglePipeDelimiterEndsWithDelimiter() throws Exception @Test // Before fix: // expected: but was: - public void testParseWithTriplePipeDelimiter() throws Exception { + void testParseWithTriplePipeDelimiter() throws Exception { final Reader in = new StringReader("a|||b|||c|||d||||||f"); final StringBuilder stringBuilder = new StringBuilder(); try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL); @@ -143,7 +143,7 @@ public void testParseWithTriplePipeDelimiter() throws Exception { @Test // Regression, already passed before fix - public void testParseWithTwoCharDelimiter1() throws Exception { + void testParseWithTwoCharDelimiter1() throws Exception { final Reader in = new StringReader("a~|b~|c~|d~|~|f"); final StringBuilder stringBuilder = new StringBuilder(); try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL); @@ -157,7 +157,7 @@ public void testParseWithTwoCharDelimiter1() throws Exception { @Test // Regression, already passed before fix - public void testParseWithTwoCharDelimiter2() throws Exception { + void testParseWithTwoCharDelimiter2() throws Exception { final Reader in = new StringReader("a~|b~|c~|d~|~|f~"); final StringBuilder stringBuilder = new StringBuilder(); try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL); @@ -171,7 +171,7 @@ public void testParseWithTwoCharDelimiter2() throws Exception { @Test // Regression, already passed before fix - public void testParseWithTwoCharDelimiter3() throws Exception { + void testParseWithTwoCharDelimiter3() throws Exception { final Reader in = new StringReader("a~|b~|c~|d~|~|f|"); final StringBuilder stringBuilder = new StringBuilder(); try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL); @@ -185,7 +185,7 @@ public void testParseWithTwoCharDelimiter3() throws Exception { @Test // Regression, already passed before fix - public void testParseWithTwoCharDelimiter4() throws Exception { + void testParseWithTwoCharDelimiter4() throws Exception { final Reader in = new StringReader("a~|b~|c~|d~|~|f~~||g"); final StringBuilder stringBuilder = new StringBuilder(); try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL); @@ -200,7 +200,7 @@ public void testParseWithTwoCharDelimiter4() throws Exception { @Test // Before fix: // expected: but was: - public void testParseWithTwoCharDelimiterEndsWithDelimiter() throws Exception { + void testParseWithTwoCharDelimiterEndsWithDelimiter() throws Exception { final Reader in = new StringReader("a~|b~|c~|d~|~|f~|"); final StringBuilder stringBuilder = new StringBuilder(); try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL); diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv290Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv290Test.java index 69aee2c796..c4bfae5375 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv290Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv290Test.java @@ -55,7 +55,7 @@ // 2 xyz \\b:\b \\t:\t \\n:\n \\r:\r a b // 3 a b,c,d "quoted" e // -public class JiraCsv290Test { + class JiraCsv290Test { private void testHelper(final String fileName, final CSVFormat format) throws Exception { List> content = new ArrayList<>(); @@ -81,17 +81,17 @@ private void testHelper(final String fileName, final CSVFormat format) throws Ex } @Test - public void testPostgresqlCsv() throws Exception { + void testPostgresqlCsv() throws Exception { testHelper("psql.csv", CSVFormat.POSTGRESQL_CSV); } @Test - public void testPostgresqlText() throws Exception { + void testPostgresqlText() throws Exception { testHelper("psql.tsv", CSVFormat.POSTGRESQL_TEXT); } @Test - public void testWriteThenRead() throws Exception { + void testWriteThenRead() throws Exception { final StringWriter sw = new StringWriter(); try (CSVPrinter printer = new CSVPrinter(sw, CSVFormat.POSTGRESQL_CSV.builder().setHeader().setSkipHeaderRecord(true).build())) { diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv93Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv93Test.java index 5b62d9af42..4f91d74f29 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv93Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv93Test.java @@ -41,7 +41,7 @@ * Jira CSV-253 to a certain extent. *

*/ -public class JiraCsv93Test { + class JiraCsv93Test { private static Object[] objects1 = {"abc", "", null, "a,b,c", 123}; private static Object[] objects2 = {"abc", "NULL", null, "a,b,c", 123}; @@ -59,7 +59,7 @@ private void every(final CSVFormat csvFormat, final Object[] objects, final Stri } @Test - public void testWithNotSetNullString() throws IOException { + void testWithNotSetNullString() throws IOException { // @formatter:off every(CSVFormat.DEFAULT, objects1, @@ -89,7 +89,7 @@ public void testWithNotSetNullString() throws IOException { } @Test - public void testWithSetNullStringEmptyString() throws IOException { + void testWithSetNullStringEmptyString() throws IOException { // @formatter:off every(CSVFormat.DEFAULT.builder().setNullString("").build(), objects1, @@ -119,7 +119,7 @@ public void testWithSetNullStringEmptyString() throws IOException { } @Test - public void testWithSetNullStringNULL() throws IOException { + void testWithSetNullStringNULL() throws IOException { // @formatter:off every(CSVFormat.DEFAULT.builder().setNullString("NULL").build(), objects2,