You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/02/02 01:03:52 UTC

[commons-csv] 01/03: Prepare for 1.8-RC2.

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-csv.git

commit df9da1056b47ad450902c1caf97124a2e4d2a9b8
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 1 20:01:01 2020 -0500

    Prepare for 1.8-RC2.
    
    - Remove package private code with Java 8 equivalent
    java.util.Objects.requirteNonNull().
    - Checkstyle fixes.
    - Use final.
    - Remove unused import.
---
 pom.xml                                            |  2 +-
 .../org/apache/commons/csv/CSVFileParserTest.java  |  6 ++--
 .../java/org/apache/commons/csv/CSVFormatTest.java | 10 +++---
 .../org/apache/commons/csv/CSVPrinterTest.java     | 39 ++++++++++++++--------
 .../java/org/apache/commons/csv/CSVRecordTest.java |  2 +-
 .../apache/commons/csv/issues/JiraCsv213Test.java  |  1 -
 .../apache/commons/csv/issues/JiraCsv248Test.java  |  2 +-
 7 files changed, 36 insertions(+), 26 deletions(-)

diff --git a/pom.xml b/pom.xml
index 466961b..042cb0f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -140,7 +140,7 @@
     <commons.release.version>1.8</commons.release.version>
     <commons.release.desc>(Java 8)</commons.release.desc>
     <!-- The RC version used in the staging repository URL. -->
-    <commons.rc.version>RC1</commons.rc.version>
+    <commons.rc.version>RC2</commons.rc.version>
     <commons.bc.version>1.7</commons.bc.version>
     <commons.componentid>csv</commons.componentid>
     <commons.module.name>org.apache.commons.csv</commons.module.name>
diff --git a/src/test/java/org/apache/commons/csv/CSVFileParserTest.java b/src/test/java/org/apache/commons/csv/CSVFileParserTest.java
index 52813a3..8e274f9 100644
--- a/src/test/java/org/apache/commons/csv/CSVFileParserTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVFileParserTest.java
@@ -42,7 +42,7 @@ public class CSVFileParserTest {
 
     private static final File BASE = new File("src/test/resources/CSVFileParser");
 
-    private String readTestData(BufferedReader reader) throws IOException {
+    private String readTestData(final BufferedReader reader) throws IOException {
         String line;
         do {
             line = reader.readLine();
@@ -61,7 +61,7 @@ public class CSVFileParserTest {
 
     @ParameterizedTest
     @MethodSource("generateData")
-    public void testCSVFile(File testFile) throws Exception {
+    public 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);
@@ -108,7 +108,7 @@ public class CSVFileParserTest {
 
     @ParameterizedTest
     @MethodSource("generateData")
-    public void testCSVUrl(File testFile) throws Exception {
+    public 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/CSVFormatTest.java b/src/test/java/org/apache/commons/csv/CSVFormatTest.java
index c7f9885..d7173a7 100644
--- a/src/test/java/org/apache/commons/csv/CSVFormatTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVFormatTest.java
@@ -64,7 +64,7 @@ public class CSVFormatTest {
         return format.withDelimiter(format.getDelimiter());
     }
 
-    private void assertNotEquals(String name, String type, Object left, Object right) {
+    private void assertNotEquals(final String name, final String type, final Object left, final Object right) {
         if (left.equals(right) || right.equals(left)) {
             fail("Objects must not compare equal for " + name + "(" + type + ")");
         }
@@ -153,12 +153,12 @@ public class CSVFormatTest {
 
     @Test
     public void testEqualsHash() throws Exception {
-        Method[] methods = CSVFormat.class.getDeclaredMethods();
-        for (Method method : methods) {
+        final Method[] methods = CSVFormat.class.getDeclaredMethods();
+        for (final Method method : methods) {
             if (Modifier.isPublic(method.getModifiers())) {
                final String name = method.getName();
                if (name.startsWith("with")) {
-                   for (Class<?> cls : method.getParameterTypes()) {
+                   for (final Class<?> cls : method.getParameterTypes()) {
                        final String type = cls.getCanonicalName();
                        if ("boolean".equals(type)) {
                            final Object defTrue = method.invoke(CSVFormat.DEFAULT, new Object[] {Boolean.TRUE});
@@ -550,7 +550,7 @@ public class CSVFormatTest {
 
         final CSVFormat csvFormat = CSVFormat.MYSQL;
 
-        NullPointerException e = assertThrows(NullPointerException.class, () -> csvFormat.format((Object[]) null));
+        final NullPointerException e = assertThrows(NullPointerException.class, () -> csvFormat.format((Object[]) null));
         assertEquals(CSVFormat.class.getName(), e.getStackTrace()[0].getClassName());
     }
 
diff --git a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
index b3bc910..cb26848 100644
--- a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
@@ -289,15 +289,25 @@ public class CSVPrinterTest {
 
     @Test
     public void testCSV135() throws IOException {
-        List<String> l = new LinkedList<String>();
-        l.add("\"\"");   // ""
-        l.add("\\\\");   // \\
-        l.add("\\\"\\"); // \"\
-        tryFormat(l, null, null, "\"\",\\\\,\\\"\\"); // "",\\,\"\ (unchanged)
-        tryFormat(l, '"',  null, "\"\"\"\"\"\",\\\\,\"\\\"\"\\\"");              // """""",\\,"\""\" (quoted, and embedded DQ doubled)
-        tryFormat(l, null, '\\', "\"\",\\\\\\\\,\\\\\"\\\\");                    // "",\\\\,\\"\\ (escapes escaped, not quoted)
-        tryFormat(l, '"',  '\\', "\"\\\"\\\"\",\"\\\\\\\\\",\"\\\\\\\"\\\\\"");  // "\"\"","\\\\","\\\"\\" (quoted, and embedded DQ & escape escaped)
-        tryFormat(l, '"',  '"',  "\"\"\"\"\"\",\\\\,\"\\\"\"\\\"");              // """""",\\,"\""\" (quoted, embedded DQ escaped)
+        final List<String> list = new LinkedList<>();
+        list.add("\"\"");   // ""
+        list.add("\\\\");   // \\
+        list.add("\\\"\\"); // \"\
+        //
+        // "",\\,\"\ (unchanged)
+        tryFormat(list, null, null, "\"\",\\\\,\\\"\\");
+        //
+        // """""",\\,"\""\" (quoted, and embedded DQ doubled)
+        tryFormat(list, '"',  null, "\"\"\"\"\"\",\\\\,\"\\\"\"\\\"");
+        //
+        // "",\\\\,\\"\\ (escapes escaped, not quoted)
+        tryFormat(list, null, '\\', "\"\",\\\\\\\\,\\\\\"\\\\");
+        //
+        // "\"\"","\\\\","\\\"\\" (quoted, and embedded DQ & escape escaped)
+        tryFormat(list, '"',  '\\', "\"\\\"\\\"\",\"\\\\\\\\\",\"\\\\\\\"\\\\\"");
+        //
+        // """""",\\,"\""\" (quoted, embedded DQ escaped)
+        tryFormat(list, '"',  '"',  "\"\"\"\"\"\",\\\\,\"\\\"\"\\\"");
     }
 
     @Test
@@ -772,7 +782,8 @@ public class CSVPrinterTest {
     @Test
     public void testMySqlNullOutput() throws IOException {
         Object[] s = new String[] { "NULL", null };
-        CSVFormat format = CSVFormat.MYSQL.withQuote(DQUOTE_CHAR).withNullString("NULL").withQuoteMode(QuoteMode.NON_NUMERIC);
+        CSVFormat format = CSVFormat.MYSQL.withQuote(DQUOTE_CHAR).withNullString("NULL")
+            .withQuoteMode(QuoteMode.NON_NUMERIC);
         StringWriter writer = new StringWriter();
         try (final CSVPrinter printer = new CSVPrinter(writer, format)) {
             printer.printRecord(s);
@@ -1519,10 +1530,10 @@ public class CSVPrinterTest {
         return CSVParser.parse(expected, format).getRecords().get(0).values();
     }
 
-    private void tryFormat(List<String> l, Character quote, Character escape, String expected) throws IOException {
-        CSVFormat format = CSVFormat.DEFAULT.withQuote(quote).withEscape(escape).withRecordSeparator(null);
-        Appendable out = new StringBuilder();
-        CSVPrinter printer = new CSVPrinter(out, format);
+    private void tryFormat(final List<String> l, final Character quote, final Character escape, final String expected) throws IOException {
+        final CSVFormat format = CSVFormat.DEFAULT.withQuote(quote).withEscape(escape).withRecordSeparator(null);
+        final Appendable out = new StringBuilder();
+        final CSVPrinter printer = new CSVPrinter(out, format);
         printer.printRecord(l);
         printer.close();
         assertEquals(expected, out.toString());
diff --git a/src/test/java/org/apache/commons/csv/CSVRecordTest.java b/src/test/java/org/apache/commons/csv/CSVRecordTest.java
index 8ed51c3..d66acfa 100644
--- a/src/test/java/org/apache/commons/csv/CSVRecordTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVRecordTest.java
@@ -226,7 +226,7 @@ public class CSVRecordTest {
             try {
                 rec.get("A");
                 org.junit.jupiter.api.Assertions.fail("Access by name is not expected after deserialisation");
-            } catch (IllegalStateException expected) {
+            } catch (final IllegalStateException expected) {
                 // OK
             }
         }
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 88dc70b..b612b62 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv213Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv213Test.java
@@ -24,7 +24,6 @@ import java.nio.charset.StandardCharsets;
 
 import org.apache.commons.csv.CSVFormat;
 import org.apache.commons.csv.CSVParser;
-import org.apache.commons.csv.CSVRecord;
 import org.apache.commons.csv.QuoteMode;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
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 efbe09f..bf640b6 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv248Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv248Test.java
@@ -68,7 +68,7 @@ public class JiraCsv248Test {
             try {
                 rec.get("A");
                 org.junit.jupiter.api.Assertions.fail("Access by name is not expected after deserialisation");
-            } catch (IllegalStateException expected) {
+            } catch (final IllegalStateException expected) {
                 // OK
             }
         }