Skip to content

Commit df9da10

Browse files
committed
Prepare for 1.8-RC2.
- Remove package private code with Java 8 equivalent java.util.Objects.requirteNonNull(). - Checkstyle fixes. - Use final. - Remove unused import.
1 parent 70092bb commit df9da10

7 files changed

Lines changed: 36 additions & 26 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
<commons.release.version>1.8</commons.release.version>
141141
<commons.release.desc>(Java 8)</commons.release.desc>
142142
<!-- The RC version used in the staging repository URL. -->
143-
<commons.rc.version>RC1</commons.rc.version>
143+
<commons.rc.version>RC2</commons.rc.version>
144144
<commons.bc.version>1.7</commons.bc.version>
145145
<commons.componentid>csv</commons.componentid>
146146
<commons.module.name>org.apache.commons.csv</commons.module.name>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class CSVFileParserTest {
4242

4343
private static final File BASE = new File("src/test/resources/CSVFileParser");
4444

45-
private String readTestData(BufferedReader reader) throws IOException {
45+
private String readTestData(final BufferedReader reader) throws IOException {
4646
String line;
4747
do {
4848
line = reader.readLine();
@@ -61,7 +61,7 @@ public static Stream<File> generateData() {
6161

6262
@ParameterizedTest
6363
@MethodSource("generateData")
64-
public void testCSVFile(File testFile) throws Exception {
64+
public void testCSVFile(final File testFile) throws Exception {
6565
try (FileReader fr = new FileReader(testFile); BufferedReader testData = new BufferedReader(fr)) {
6666
String line = readTestData(testData);
6767
assertNotNull("file must contain config line", line);
@@ -108,7 +108,7 @@ public void testCSVFile(File testFile) throws Exception {
108108

109109
@ParameterizedTest
110110
@MethodSource("generateData")
111-
public void testCSVUrl(File testFile) throws Exception {
111+
public void testCSVUrl(final File testFile) throws Exception {
112112
try (FileReader fr = new FileReader(testFile); BufferedReader testData = new BufferedReader(fr)) {
113113
String line = readTestData(testData);
114114
assertNotNull("file must contain config line", line);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private static CSVFormat copy(final CSVFormat format) {
6464
return format.withDelimiter(format.getDelimiter());
6565
}
6666

67-
private void assertNotEquals(String name, String type, Object left, Object right) {
67+
private void assertNotEquals(final String name, final String type, final Object left, final Object right) {
6868
if (left.equals(right) || right.equals(left)) {
6969
fail("Objects must not compare equal for " + name + "(" + type + ")");
7070
}
@@ -153,12 +153,12 @@ public void testEqualsEscape() {
153153

154154
@Test
155155
public void testEqualsHash() throws Exception {
156-
Method[] methods = CSVFormat.class.getDeclaredMethods();
157-
for (Method method : methods) {
156+
final Method[] methods = CSVFormat.class.getDeclaredMethods();
157+
for (final Method method : methods) {
158158
if (Modifier.isPublic(method.getModifiers())) {
159159
final String name = method.getName();
160160
if (name.startsWith("with")) {
161-
for (Class<?> cls : method.getParameterTypes()) {
161+
for (final Class<?> cls : method.getParameterTypes()) {
162162
final String type = cls.getCanonicalName();
163163
if ("boolean".equals(type)) {
164164
final Object defTrue = method.invoke(CSVFormat.DEFAULT, new Object[] {Boolean.TRUE});
@@ -550,7 +550,7 @@ public void testFormatThrowsNullPointerException() {
550550

551551
final CSVFormat csvFormat = CSVFormat.MYSQL;
552552

553-
NullPointerException e = assertThrows(NullPointerException.class, () -> csvFormat.format((Object[]) null));
553+
final NullPointerException e = assertThrows(NullPointerException.class, () -> csvFormat.format((Object[]) null));
554554
assertEquals(CSVFormat.class.getName(), e.getStackTrace()[0].getClassName());
555555
}
556556

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

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,25 @@ public void testCloseWithFlushOn() throws IOException {
289289

290290
@Test
291291
public void testCSV135() throws IOException {
292-
List<String> l = new LinkedList<String>();
293-
l.add("\"\""); // ""
294-
l.add("\\\\"); // \\
295-
l.add("\\\"\\"); // \"\
296-
tryFormat(l, null, null, "\"\",\\\\,\\\"\\"); // "",\\,\"\ (unchanged)
297-
tryFormat(l, '"', null, "\"\"\"\"\"\",\\\\,\"\\\"\"\\\""); // """""",\\,"\""\" (quoted, and embedded DQ doubled)
298-
tryFormat(l, null, '\\', "\"\",\\\\\\\\,\\\\\"\\\\"); // "",\\\\,\\"\\ (escapes escaped, not quoted)
299-
tryFormat(l, '"', '\\', "\"\\\"\\\"\",\"\\\\\\\\\",\"\\\\\\\"\\\\\""); // "\"\"","\\\\","\\\"\\" (quoted, and embedded DQ & escape escaped)
300-
tryFormat(l, '"', '"', "\"\"\"\"\"\",\\\\,\"\\\"\"\\\""); // """""",\\,"\""\" (quoted, embedded DQ escaped)
292+
final List<String> list = new LinkedList<>();
293+
list.add("\"\""); // ""
294+
list.add("\\\\"); // \\
295+
list.add("\\\"\\"); // \"\
296+
//
297+
// "",\\,\"\ (unchanged)
298+
tryFormat(list, null, null, "\"\",\\\\,\\\"\\");
299+
//
300+
// """""",\\,"\""\" (quoted, and embedded DQ doubled)
301+
tryFormat(list, '"', null, "\"\"\"\"\"\",\\\\,\"\\\"\"\\\"");
302+
//
303+
// "",\\\\,\\"\\ (escapes escaped, not quoted)
304+
tryFormat(list, null, '\\', "\"\",\\\\\\\\,\\\\\"\\\\");
305+
//
306+
// "\"\"","\\\\","\\\"\\" (quoted, and embedded DQ & escape escaped)
307+
tryFormat(list, '"', '\\', "\"\\\"\\\"\",\"\\\\\\\\\",\"\\\\\\\"\\\\\"");
308+
//
309+
// """""",\\,"\""\" (quoted, embedded DQ escaped)
310+
tryFormat(list, '"', '"', "\"\"\"\"\"\",\\\\,\"\\\"\"\\\"");
301311
}
302312

303313
@Test
@@ -772,7 +782,8 @@ public void testMultiLineComment() throws IOException {
772782
@Test
773783
public void testMySqlNullOutput() throws IOException {
774784
Object[] s = new String[] { "NULL", null };
775-
CSVFormat format = CSVFormat.MYSQL.withQuote(DQUOTE_CHAR).withNullString("NULL").withQuoteMode(QuoteMode.NON_NUMERIC);
785+
CSVFormat format = CSVFormat.MYSQL.withQuote(DQUOTE_CHAR).withNullString("NULL")
786+
.withQuoteMode(QuoteMode.NON_NUMERIC);
776787
StringWriter writer = new StringWriter();
777788
try (final CSVPrinter printer = new CSVPrinter(writer, format)) {
778789
printer.printRecord(s);
@@ -1519,10 +1530,10 @@ private String[] toFirstRecordValues(final String expected, final CSVFormat form
15191530
return CSVParser.parse(expected, format).getRecords().get(0).values();
15201531
}
15211532

1522-
private void tryFormat(List<String> l, Character quote, Character escape, String expected) throws IOException {
1523-
CSVFormat format = CSVFormat.DEFAULT.withQuote(quote).withEscape(escape).withRecordSeparator(null);
1524-
Appendable out = new StringBuilder();
1525-
CSVPrinter printer = new CSVPrinter(out, format);
1533+
private void tryFormat(final List<String> l, final Character quote, final Character escape, final String expected) throws IOException {
1534+
final CSVFormat format = CSVFormat.DEFAULT.withQuote(quote).withEscape(escape).withRecordSeparator(null);
1535+
final Appendable out = new StringBuilder();
1536+
final CSVPrinter printer = new CSVPrinter(out, format);
15261537
printer.printRecord(l);
15271538
printer.close();
15281539
assertEquals(expected, out.toString());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public void testSerialization() throws IOException, ClassNotFoundException {
226226
try {
227227
rec.get("A");
228228
org.junit.jupiter.api.Assertions.fail("Access by name is not expected after deserialisation");
229-
} catch (IllegalStateException expected) {
229+
} catch (final IllegalStateException expected) {
230230
// OK
231231
}
232232
}

src/test/java/org/apache/commons/csv/issues/JiraCsv213Test.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import org.apache.commons.csv.CSVFormat;
2626
import org.apache.commons.csv.CSVParser;
27-
import org.apache.commons.csv.CSVRecord;
2827
import org.apache.commons.csv.QuoteMode;
2928
import org.junit.jupiter.api.Disabled;
3029
import org.junit.jupiter.api.Test;

src/test/java/org/apache/commons/csv/issues/JiraCsv248Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void testJiraCsv248() throws IOException, ClassNotFoundException {
6868
try {
6969
rec.get("A");
7070
org.junit.jupiter.api.Assertions.fail("Access by name is not expected after deserialisation");
71-
} catch (IllegalStateException expected) {
71+
} catch (final IllegalStateException expected) {
7272
// OK
7373
}
7474
}

0 commit comments

Comments
 (0)