Prepare for 1.8-RC2.

- Remove package private code with Java 8 equivalent
java.util.Objects.requirteNonNull().
- Checkstyle fixes.
- Use final.
- Remove unused import.
This commit is contained in:
Gary Gregory 2020-02-01 20:01:01 -05:00
parent 70092bb303
commit df9da1056b
7 changed files with 36 additions and 26 deletions

View File

@ -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>

View File

@ -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);

View File

@ -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());
}

View File

@ -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());

View File

@ -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
}
}

View File

@ -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;

View File

@ -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
}
}