Use final.

This commit is contained in:
Gary Gregory 2017-10-09 13:43:02 -06:00
parent b4a084ed48
commit 0c216e783c
9 changed files with 83 additions and 83 deletions

View File

@ -630,7 +630,7 @@ public final class CSVFormat implements Serializable {
final boolean ignoreEmptyLines, final String recordSeparator, final String nullString, final boolean ignoreEmptyLines, final String recordSeparator, final String nullString,
final Object[] headerComments, final String[] header, final boolean skipHeaderRecord, final Object[] headerComments, final String[] header, final boolean skipHeaderRecord,
final boolean allowMissingColumnNames, final boolean ignoreHeaderCase, final boolean trim, final boolean allowMissingColumnNames, final boolean ignoreHeaderCase, final boolean trim,
final boolean trailingDelimiter, boolean autoFlush) { final boolean trailingDelimiter, final boolean autoFlush) {
this.delimiter = delimiter; this.delimiter = delimiter;
this.quoteCharacter = quoteChar; this.quoteCharacter = quoteChar;
this.quoteMode = quoteMode; this.quoteMode = quoteMode;
@ -1026,7 +1026,7 @@ public final class CSVFormat implements Serializable {
* @since 1.5 * @since 1.5
*/ */
@SuppressWarnings("resource") @SuppressWarnings("resource")
public CSVPrinter print(final File out, Charset charset) throws IOException { public CSVPrinter print(final File out, final Charset charset) throws IOException {
// The writer will be closed when close() is called. // The writer will be closed when close() is called.
return new CSVPrinter(new OutputStreamWriter(new FileOutputStream(out), charset), this); return new CSVPrinter(new OutputStreamWriter(new FileOutputStream(out), charset), this);
} }
@ -1047,7 +1047,7 @@ public final class CSVFormat implements Serializable {
* thrown if the optional header cannot be printed. * thrown if the optional header cannot be printed.
* @since 1.5 * @since 1.5
*/ */
public CSVPrinter print(final Path out, Charset charset) throws IOException { public CSVPrinter print(final Path out, final Charset charset) throws IOException {
return print(Files.newBufferedWriter(out, charset)); return print(Files.newBufferedWriter(out, charset));
} }

View File

@ -225,7 +225,7 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
* If there is a problem reading the header or skipping the first record * If there is a problem reading the header or skipping the first record
* @since 1.5 * @since 1.5
*/ */
public static CSVParser parse(Reader reader, final CSVFormat format) throws IOException { public static CSVParser parse(final Reader reader, final CSVFormat format) throws IOException {
return new CSVParser(reader, format); return new CSVParser(reader, format);
} }

View File

@ -92,7 +92,7 @@ public final class CSVPrinter implements Flushable, Closeable {
* If an I/O error occurs * If an I/O error occurs
* @since 1.6 * @since 1.6
*/ */
public void close(boolean flush) throws IOException { public void close(final boolean flush) throws IOException {
if (flush || format.getAutoFlush()) { if (flush || format.getAutoFlush()) {
if (out instanceof Flushable) { if (out instanceof Flushable) {
((Flushable) out).flush(); ((Flushable) out).flush();

View File

@ -462,8 +462,8 @@ public class CSVFormatTest {
@Test @Test
public void testToStringAndWithCommentMarkerTakingCharacter() { public void testToStringAndWithCommentMarkerTakingCharacter() {
CSVFormat.Predefined cSVFormat_Predefined = CSVFormat.Predefined.Default; final CSVFormat.Predefined cSVFormat_Predefined = CSVFormat.Predefined.Default;
CSVFormat cSVFormat = cSVFormat_Predefined.getFormat(); final CSVFormat cSVFormat = cSVFormat_Predefined.getFormat();
assertNull(cSVFormat.getEscapeCharacter()); assertNull(cSVFormat.getEscapeCharacter());
assertTrue(cSVFormat.isQuoteCharacterSet()); assertTrue(cSVFormat.isQuoteCharacterSet());
@ -492,9 +492,9 @@ public class CSVFormatTest {
assertTrue(cSVFormat.getIgnoreEmptyLines()); assertTrue(cSVFormat.getIgnoreEmptyLines());
assertEquals('\"', (char)cSVFormat.getQuoteCharacter()); assertEquals('\"', (char)cSVFormat.getQuoteCharacter());
Character character = Character.valueOf('n'); final Character character = Character.valueOf('n');
CSVFormat cSVFormatTwo = cSVFormat.withCommentMarker(character); final CSVFormat cSVFormatTwo = cSVFormat.withCommentMarker(character);
assertNull(cSVFormat.getEscapeCharacter()); assertNull(cSVFormat.getEscapeCharacter());
assertTrue(cSVFormat.isQuoteCharacterSet()); assertTrue(cSVFormat.isQuoteCharacterSet());
@ -625,7 +625,7 @@ public class CSVFormatTest {
@Test @Test
public void testNewFormat() { public void testNewFormat() {
CSVFormat cSVFormat = CSVFormat.newFormat('X'); final CSVFormat cSVFormat = CSVFormat.newFormat('X');
assertFalse(cSVFormat.getSkipHeaderRecord()); assertFalse(cSVFormat.getSkipHeaderRecord());
assertFalse(cSVFormat.isEscapeCharacterSet()); assertFalse(cSVFormat.isEscapeCharacterSet());
@ -687,7 +687,7 @@ public class CSVFormatTest {
@Test @Test
public void testWithHeaderComments() { public void testWithHeaderComments() {
CSVFormat cSVFormat = CSVFormat.DEFAULT; final CSVFormat cSVFormat = CSVFormat.DEFAULT;
assertEquals('\"', (char)cSVFormat.getQuoteCharacter()); assertEquals('\"', (char)cSVFormat.getQuoteCharacter());
assertFalse(cSVFormat.isCommentMarkerSet()); assertFalse(cSVFormat.isCommentMarkerSet());
@ -716,8 +716,8 @@ public class CSVFormatTest {
assertFalse(cSVFormat.getIgnoreSurroundingSpaces()); assertFalse(cSVFormat.getIgnoreSurroundingSpaces());
assertNull(cSVFormat.getEscapeCharacter()); assertNull(cSVFormat.getEscapeCharacter());
Object[] objectArray = new Object[8]; final Object[] objectArray = new Object[8];
CSVFormat cSVFormatTwo = cSVFormat.withHeaderComments(objectArray); final CSVFormat cSVFormatTwo = cSVFormat.withHeaderComments(objectArray);
assertEquals('\"', (char)cSVFormat.getQuoteCharacter()); assertEquals('\"', (char)cSVFormat.getQuoteCharacter());
assertFalse(cSVFormat.isCommentMarkerSet()); assertFalse(cSVFormat.isCommentMarkerSet());
@ -778,7 +778,7 @@ public class CSVFormatTest {
assertTrue(cSVFormatTwo.equals(cSVFormat)); assertTrue(cSVFormatTwo.equals(cSVFormat));
String string = cSVFormatTwo.format(objectArray); final String string = cSVFormatTwo.format(objectArray);
assertEquals('\"', (char)cSVFormat.getQuoteCharacter()); assertEquals('\"', (char)cSVFormat.getQuoteCharacter());
assertFalse(cSVFormat.isCommentMarkerSet()); assertFalse(cSVFormat.isCommentMarkerSet());
@ -849,12 +849,12 @@ public class CSVFormatTest {
@Test //I assume this to be a defect. @Test //I assume this to be a defect.
public void testFormatThrowsNullPointerException() { public void testFormatThrowsNullPointerException() {
CSVFormat cSVFormat = CSVFormat.MYSQL; final CSVFormat cSVFormat = CSVFormat.MYSQL;
try { try {
cSVFormat.format(null); cSVFormat.format(null);
fail("Expecting exception: NullPointerException"); fail("Expecting exception: NullPointerException");
} catch(NullPointerException e) { } catch(final NullPointerException e) {
assertEquals(CSVFormat.class.getName(), e.getStackTrace()[0].getClassName()); assertEquals(CSVFormat.class.getName(), e.getStackTrace()[0].getClassName());
} }
@ -864,8 +864,8 @@ public class CSVFormatTest {
@Test @Test
public void testEqualsOne() { public void testEqualsOne() {
CSVFormat cSVFormatOne = CSVFormat.INFORMIX_UNLOAD; final CSVFormat cSVFormatOne = CSVFormat.INFORMIX_UNLOAD;
CSVFormat cSVFormatTwo = CSVFormat.MYSQL; final CSVFormat cSVFormatTwo = CSVFormat.MYSQL;
assertEquals('\\', (char)cSVFormatOne.getEscapeCharacter()); assertEquals('\\', (char)cSVFormatOne.getEscapeCharacter());
@ -994,7 +994,7 @@ public class CSVFormatTest {
@Test @Test
public void testEqualsWithNull() { public void testEqualsWithNull() {
CSVFormat cSVFormat = CSVFormat.POSTGRESQL_TEXT; final CSVFormat cSVFormat = CSVFormat.POSTGRESQL_TEXT;
assertEquals('\"', (char)cSVFormat.getEscapeCharacter()); assertEquals('\"', (char)cSVFormat.getEscapeCharacter());
assertFalse(cSVFormat.getIgnoreSurroundingSpaces()); assertFalse(cSVFormat.getIgnoreSurroundingSpaces());
@ -1058,8 +1058,8 @@ public class CSVFormatTest {
@Test @Test
public void testToString() { public void testToString() {
CSVFormat cSVFormat = CSVFormat.POSTGRESQL_TEXT; final CSVFormat cSVFormat = CSVFormat.POSTGRESQL_TEXT;
String string = cSVFormat.INFORMIX_UNLOAD.toString(); final String string = cSVFormat.INFORMIX_UNLOAD.toString();
assertEquals("Delimiter=<|> Escape=<\\> QuoteChar=<\"> RecordSeparator=<\n> EmptyLines:ignored SkipHeaderRecord:false", string); assertEquals("Delimiter=<|> Escape=<\\> QuoteChar=<\"> RecordSeparator=<\n> EmptyLines:ignored SkipHeaderRecord:false", string);
@ -1069,8 +1069,8 @@ public class CSVFormatTest {
@Test @Test
public void testHashCodeAndWithIgnoreHeaderCase() { public void testHashCodeAndWithIgnoreHeaderCase() {
CSVFormat cSVFormat = CSVFormat.INFORMIX_UNLOAD_CSV; final CSVFormat cSVFormat = CSVFormat.INFORMIX_UNLOAD_CSV;
CSVFormat cSVFormatTwo = cSVFormat.withIgnoreHeaderCase(); final CSVFormat cSVFormatTwo = cSVFormat.withIgnoreHeaderCase();
cSVFormatTwo.hashCode(); cSVFormatTwo.hashCode();
assertTrue(cSVFormatTwo.getIgnoreHeaderCase()); assertTrue(cSVFormatTwo.getIgnoreHeaderCase());

View File

@ -74,7 +74,7 @@ public class CSVParserTest {
private static final String[][] RESULT = { { "a", "b", "c", "d" }, { "a", "b", "1 2" }, { "foo baar", "b", "" }, private static final String[][] RESULT = { { "a", "b", "c", "d" }, { "a", "b", "1 2" }, { "foo baar", "b", "" },
{ "foo\n,,\n\",,\n\"", "d", "e" } }; { "foo\n,,\n\",,\n\"", "d", "e" } };
private BOMInputStream createBOMInputStream(String resource) throws IOException { private BOMInputStream createBOMInputStream(final String resource) throws IOException {
final URL url = ClassLoader.getSystemClassLoader().getResource(resource); final URL url = ClassLoader.getSystemClassLoader().getResource(resource);
return new BOMInputStream(url.openStream()); return new BOMInputStream(url.openStream());
} }

View File

@ -304,7 +304,7 @@ public class CSVPrinterTest {
@Test @Test
public void testEscapeBackslash1() throws IOException { public void testEscapeBackslash1() throws IOException {
StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) { try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) {
printer.print("\\"); printer.print("\\");
} }
@ -313,7 +313,7 @@ public class CSVPrinterTest {
@Test @Test
public void testEscapeBackslash2() throws IOException { public void testEscapeBackslash2() throws IOException {
StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) { try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) {
printer.print("\\\r"); printer.print("\\\r");
} }
@ -322,7 +322,7 @@ public class CSVPrinterTest {
@Test @Test
public void testEscapeBackslash3() throws IOException { public void testEscapeBackslash3() throws IOException {
StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) { try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) {
printer.print("X\\\r"); printer.print("X\\\r");
} }
@ -331,7 +331,7 @@ public class CSVPrinterTest {
@Test @Test
public void testEscapeBackslash4() throws IOException { public void testEscapeBackslash4() throws IOException {
StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) { try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) {
printer.print("\\\\"); printer.print("\\\\");
} }
@ -340,7 +340,7 @@ public class CSVPrinterTest {
@Test @Test
public void testEscapeBackslash5() throws IOException { public void testEscapeBackslash5() throws IOException {
StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) { try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) {
printer.print("\\\\"); printer.print("\\\\");
} }
@ -349,7 +349,7 @@ public class CSVPrinterTest {
@Test @Test
public void testEscapeNull1() throws IOException { public void testEscapeNull1() throws IOException {
StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape(null))) { try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape(null))) {
printer.print("\\"); printer.print("\\");
} }
@ -358,7 +358,7 @@ public class CSVPrinterTest {
@Test @Test
public void testEscapeNull2() throws IOException { public void testEscapeNull2() throws IOException {
StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape(null))) { try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape(null))) {
printer.print("\\\r"); printer.print("\\\r");
} }
@ -367,7 +367,7 @@ public class CSVPrinterTest {
@Test @Test
public void testEscapeNull3() throws IOException { public void testEscapeNull3() throws IOException {
StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape(null))) { try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape(null))) {
printer.print("X\\\r"); printer.print("X\\\r");
} }
@ -376,7 +376,7 @@ public class CSVPrinterTest {
@Test @Test
public void testEscapeNull4() throws IOException { public void testEscapeNull4() throws IOException {
StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape(null))) { try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape(null))) {
printer.print("\\\\"); printer.print("\\\\");
} }
@ -385,7 +385,7 @@ public class CSVPrinterTest {
@Test @Test
public void testEscapeNull5() throws IOException { public void testEscapeNull5() throws IOException {
StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape(null))) { try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape(null))) {
printer.print("\\\\"); printer.print("\\\\");
} }
@ -1115,7 +1115,7 @@ public class CSVPrinterTest {
@Test @Test
public void testPrintToFileWithCharsetUtf16Be() throws IOException { public void testPrintToFileWithCharsetUtf16Be() throws IOException {
File file = File.createTempFile(getClass().getName(), ".csv"); final File file = File.createTempFile(getClass().getName(), ".csv");
try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file, StandardCharsets.UTF_16BE)) { try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file, StandardCharsets.UTF_16BE)) {
printer.printRecord("a", "b\\c"); printer.printRecord("a", "b\\c");
} }
@ -1124,7 +1124,7 @@ public class CSVPrinterTest {
@Test @Test
public void testPrintToFileWithDefaultCharset() throws IOException { public void testPrintToFileWithDefaultCharset() throws IOException {
File file = File.createTempFile(getClass().getName(), ".csv"); final File file = File.createTempFile(getClass().getName(), ".csv");
try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file, Charset.defaultCharset())) { try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file, Charset.defaultCharset())) {
printer.printRecord("a", "b\\c"); printer.printRecord("a", "b\\c");
} }
@ -1133,7 +1133,7 @@ public class CSVPrinterTest {
@Test @Test
public void testPrintToPathWithDefaultCharset() throws IOException { public void testPrintToPathWithDefaultCharset() throws IOException {
File file = File.createTempFile(getClass().getName(), ".csv"); final File file = File.createTempFile(getClass().getName(), ".csv");
try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file.toPath(), Charset.defaultCharset())) { try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file.toPath(), Charset.defaultCharset())) {
printer.printRecord("a", "b\\c"); printer.printRecord("a", "b\\c");
} }
@ -1282,8 +1282,8 @@ public class CSVPrinterTest {
@Test @Test
public void testPrintRecordsWithResultSetOneRow() throws IOException, SQLException { public void testPrintRecordsWithResultSetOneRow() throws IOException, SQLException {
try (CSVPrinter csvPrinter = CSVFormat.MYSQL.printer()) { try (CSVPrinter csvPrinter = CSVFormat.MYSQL.printer()) {
Value[] valueArray = new Value[0]; final Value[] valueArray = new Value[0];
ValueArray valueArrayTwo = ValueArray.get(valueArray); final ValueArray valueArrayTwo = ValueArray.get(valueArray);
try (ResultSet resultSet = valueArrayTwo.getResultSet()) { try (ResultSet resultSet = valueArrayTwo.getResultSet()) {
csvPrinter.printRecords(resultSet); csvPrinter.printRecords(resultSet);
assertEquals(0, resultSet.getRow()); assertEquals(0, resultSet.getRow());
@ -1293,10 +1293,10 @@ public class CSVPrinterTest {
@Test @Test
public void testPrintRecordsWithObjectArray() throws IOException { public void testPrintRecordsWithObjectArray() throws IOException {
CharArrayWriter charArrayWriter = new CharArrayWriter(0); final CharArrayWriter charArrayWriter = new CharArrayWriter(0);
try (CSVPrinter csvPrinter = CSVFormat.INFORMIX_UNLOAD.print(charArrayWriter)) { try (CSVPrinter csvPrinter = CSVFormat.INFORMIX_UNLOAD.print(charArrayWriter)) {
HashSet<BatchUpdateException> hashSet = new HashSet<>(); final HashSet<BatchUpdateException> hashSet = new HashSet<>();
Object[] objectArray = new Object[6]; final Object[] objectArray = new Object[6];
objectArray[3] = hashSet; objectArray[3] = hashSet;
csvPrinter.printRecords(objectArray); csvPrinter.printRecords(objectArray);
} }
@ -1308,8 +1308,8 @@ public class CSVPrinterTest {
@Test @Test
public void testPrintRecordsWithEmptyVector() throws IOException { public void testPrintRecordsWithEmptyVector() throws IOException {
try (CSVPrinter csvPrinter = CSVFormat.POSTGRESQL_TEXT.printer()) { try (CSVPrinter csvPrinter = CSVFormat.POSTGRESQL_TEXT.printer()) {
Vector<CSVFormatTest.EmptyEnum> vector = new Vector<>(); final Vector<CSVFormatTest.EmptyEnum> vector = new Vector<>();
int expectedCapacity = 23; final int expectedCapacity = 23;
vector.setSize(expectedCapacity); vector.setSize(expectedCapacity);
csvPrinter.printRecords(vector); csvPrinter.printRecords(vector);
assertEquals(expectedCapacity, vector.capacity()); assertEquals(expectedCapacity, vector.capacity());
@ -1318,18 +1318,18 @@ public class CSVPrinterTest {
@Test @Test
public void testCloseWithFlushOn() throws IOException { public void testCloseWithFlushOn() throws IOException {
Writer writer = mock(Writer.class); final Writer writer = mock(Writer.class);
CSVFormat csvFormat = CSVFormat.DEFAULT; final CSVFormat csvFormat = CSVFormat.DEFAULT;
CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat); final CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat);
csvPrinter.close(true); csvPrinter.close(true);
verify(writer, times(1)).flush(); verify(writer, times(1)).flush();
} }
@Test @Test
public void testCloseWithFlushOff() throws IOException { public void testCloseWithFlushOff() throws IOException {
Writer writer = mock(Writer.class); final Writer writer = mock(Writer.class);
CSVFormat csvFormat = CSVFormat.DEFAULT; final CSVFormat csvFormat = CSVFormat.DEFAULT;
CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat); final CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat);
csvPrinter.close(false); csvPrinter.close(false);
verify(writer, never()).flush(); verify(writer, never()).flush();
verify(writer, times(1)).close(); verify(writer, times(1)).close();
@ -1337,8 +1337,8 @@ public class CSVPrinterTest {
@Test @Test
public void testCloseBackwardCompatibility() throws IOException { public void testCloseBackwardCompatibility() throws IOException {
Writer writer = mock(Writer.class); final Writer writer = mock(Writer.class);
CSVFormat csvFormat = CSVFormat.DEFAULT; final CSVFormat csvFormat = CSVFormat.DEFAULT;
try (CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat)) { try (CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat)) {
} }
verify(writer, never()).flush(); verify(writer, never()).flush();
@ -1348,8 +1348,8 @@ public class CSVPrinterTest {
@Test @Test
public void testCloseWithCsvFormatAutoFlushOn() throws IOException { public void testCloseWithCsvFormatAutoFlushOn() throws IOException {
// System.out.println("start method"); // System.out.println("start method");
Writer writer = mock(Writer.class); final Writer writer = mock(Writer.class);
CSVFormat csvFormat = CSVFormat.DEFAULT.withAutoFlush(true); final CSVFormat csvFormat = CSVFormat.DEFAULT.withAutoFlush(true);
try (CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat)) { try (CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat)) {
} }
verify(writer, times(1)).flush(); verify(writer, times(1)).flush();
@ -1358,8 +1358,8 @@ public class CSVPrinterTest {
@Test @Test
public void testCloseWithCsvFormatAutoFlushOff() throws IOException { public void testCloseWithCsvFormatAutoFlushOff() throws IOException {
Writer writer = mock(Writer.class); final Writer writer = mock(Writer.class);
CSVFormat csvFormat = CSVFormat.DEFAULT.withAutoFlush(false); final CSVFormat csvFormat = CSVFormat.DEFAULT.withAutoFlush(false);
try (CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat)) { try (CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat)) {
} }
verify(writer, never()).flush(); verify(writer, never()).flush();

View File

@ -33,12 +33,12 @@ public class JiraCsv198Test {
@Test @Test
public void test() throws UnsupportedEncodingException, IOException { public void test() throws UnsupportedEncodingException, IOException {
InputStream pointsOfReference = getClass().getResourceAsStream("/CSV-198/optd_por_public.csv"); final InputStream pointsOfReference = getClass().getResourceAsStream("/CSV-198/optd_por_public.csv");
Assert.assertNotNull(pointsOfReference); Assert.assertNotNull(pointsOfReference);
try (@SuppressWarnings("resource") try (@SuppressWarnings("resource")
CSVParser parser = CSV_FORMAT.parse(new InputStreamReader(pointsOfReference, "UTF-8"))) { CSVParser parser = CSV_FORMAT.parse(new InputStreamReader(pointsOfReference, "UTF-8"))) {
for (CSVRecord record : parser) { for (final CSVRecord record : parser) {
String locationType = record.get("location_type"); final String locationType = record.get("location_type");
Assert.assertNotNull(locationType); Assert.assertNotNull(locationType);
} }
} }

View File

@ -29,13 +29,13 @@ public class JiraCsv203Test {
@Test @Test
public void testQuoteModeAll() throws Exception { public void testQuoteModeAll() throws Exception {
CSVFormat format = CSVFormat.EXCEL final CSVFormat format = CSVFormat.EXCEL
.withNullString("N/A") .withNullString("N/A")
.withIgnoreSurroundingSpaces(true) .withIgnoreSurroundingSpaces(true)
.withQuoteMode(QuoteMode.ALL); .withQuoteMode(QuoteMode.ALL);
StringBuffer buffer = new StringBuffer(); final StringBuffer buffer = new StringBuffer();
CSVPrinter printer = new CSVPrinter(buffer, format); final CSVPrinter printer = new CSVPrinter(buffer, format);
printer.printRecord(new Object[] { null, "Hello", null, "World" }); printer.printRecord(new Object[] { null, "Hello", null, "World" });
Assert.assertEquals("\"N/A\",\"Hello\",\"N/A\",\"World\"\r\n", buffer.toString()); Assert.assertEquals("\"N/A\",\"Hello\",\"N/A\",\"World\"\r\n", buffer.toString());
@ -43,13 +43,13 @@ public class JiraCsv203Test {
@Test @Test
public void testQuoteModeAllNonNull() throws Exception { public void testQuoteModeAllNonNull() throws Exception {
CSVFormat format = CSVFormat.EXCEL final CSVFormat format = CSVFormat.EXCEL
.withNullString("N/A") .withNullString("N/A")
.withIgnoreSurroundingSpaces(true) .withIgnoreSurroundingSpaces(true)
.withQuoteMode(QuoteMode.ALL_NON_NULL); .withQuoteMode(QuoteMode.ALL_NON_NULL);
StringBuffer buffer = new StringBuffer(); final StringBuffer buffer = new StringBuffer();
CSVPrinter printer = new CSVPrinter(buffer, format); final CSVPrinter printer = new CSVPrinter(buffer, format);
printer.printRecord(new Object[] { null, "Hello", null, "World" }); printer.printRecord(new Object[] { null, "Hello", null, "World" });
Assert.assertEquals("N/A,\"Hello\",N/A,\"World\"\r\n", buffer.toString()); Assert.assertEquals("N/A,\"Hello\",N/A,\"World\"\r\n", buffer.toString());
@ -57,12 +57,12 @@ public class JiraCsv203Test {
@Test @Test
public void testWithoutQuoteMode() throws Exception { public void testWithoutQuoteMode() throws Exception {
CSVFormat format = CSVFormat.EXCEL final CSVFormat format = CSVFormat.EXCEL
.withNullString("N/A") .withNullString("N/A")
.withIgnoreSurroundingSpaces(true); .withIgnoreSurroundingSpaces(true);
StringBuffer buffer = new StringBuffer(); final StringBuffer buffer = new StringBuffer();
CSVPrinter printer = new CSVPrinter(buffer, format); final CSVPrinter printer = new CSVPrinter(buffer, format);
printer.printRecord(new Object[] { null, "Hello", null, "World" }); printer.printRecord(new Object[] { null, "Hello", null, "World" });
Assert.assertEquals("N/A,Hello,N/A,World\r\n", buffer.toString()); Assert.assertEquals("N/A,Hello,N/A,World\r\n", buffer.toString());
@ -70,13 +70,13 @@ public class JiraCsv203Test {
@Test @Test
public void testQuoteModeMinimal() throws Exception { public void testQuoteModeMinimal() throws Exception {
CSVFormat format = CSVFormat.EXCEL final CSVFormat format = CSVFormat.EXCEL
.withNullString("N/A") .withNullString("N/A")
.withIgnoreSurroundingSpaces(true) .withIgnoreSurroundingSpaces(true)
.withQuoteMode(QuoteMode.MINIMAL); .withQuoteMode(QuoteMode.MINIMAL);
StringBuffer buffer = new StringBuffer(); final StringBuffer buffer = new StringBuffer();
CSVPrinter printer = new CSVPrinter(buffer, format); final CSVPrinter printer = new CSVPrinter(buffer, format);
printer.printRecord(new Object[] { null, "Hello", null, "World" }); printer.printRecord(new Object[] { null, "Hello", null, "World" });
Assert.assertEquals("N/A,Hello,N/A,World\r\n", buffer.toString()); Assert.assertEquals("N/A,Hello,N/A,World\r\n", buffer.toString());
@ -84,13 +84,13 @@ public class JiraCsv203Test {
@Test @Test
public void testQuoteModeNonNumeric() throws Exception { public void testQuoteModeNonNumeric() throws Exception {
CSVFormat format = CSVFormat.EXCEL final CSVFormat format = CSVFormat.EXCEL
.withNullString("N/A") .withNullString("N/A")
.withIgnoreSurroundingSpaces(true) .withIgnoreSurroundingSpaces(true)
.withQuoteMode(QuoteMode.NON_NUMERIC); .withQuoteMode(QuoteMode.NON_NUMERIC);
StringBuffer buffer = new StringBuffer(); final StringBuffer buffer = new StringBuffer();
CSVPrinter printer = new CSVPrinter(buffer, format); final CSVPrinter printer = new CSVPrinter(buffer, format);
printer.printRecord(new Object[] { null, "Hello", null, "World" }); printer.printRecord(new Object[] { null, "Hello", null, "World" });
Assert.assertEquals("N/A,\"Hello\",N/A,\"World\"\r\n", buffer.toString()); Assert.assertEquals("N/A,\"Hello\",N/A,\"World\"\r\n", buffer.toString());
@ -98,13 +98,13 @@ public class JiraCsv203Test {
@Test @Test
public void testWithoutNullString() throws Exception { public void testWithoutNullString() throws Exception {
CSVFormat format = CSVFormat.EXCEL final CSVFormat format = CSVFormat.EXCEL
//.withNullString("N/A") //.withNullString("N/A")
.withIgnoreSurroundingSpaces(true) .withIgnoreSurroundingSpaces(true)
.withQuoteMode(QuoteMode.ALL); .withQuoteMode(QuoteMode.ALL);
StringBuffer buffer = new StringBuffer(); final StringBuffer buffer = new StringBuffer();
CSVPrinter printer = new CSVPrinter(buffer, format); final CSVPrinter printer = new CSVPrinter(buffer, format);
printer.printRecord(new Object[] { null, "Hello", null, "World" }); printer.printRecord(new Object[] { null, "Hello", null, "World" });
Assert.assertEquals(",\"Hello\",,\"World\"\r\n", buffer.toString()); Assert.assertEquals(",\"Hello\",,\"World\"\r\n", buffer.toString());
@ -112,13 +112,13 @@ public class JiraCsv203Test {
@Test @Test
public void testWithEmptyValues() throws Exception { public void testWithEmptyValues() throws Exception {
CSVFormat format = CSVFormat.EXCEL final CSVFormat format = CSVFormat.EXCEL
.withNullString("N/A") .withNullString("N/A")
.withIgnoreSurroundingSpaces(true) .withIgnoreSurroundingSpaces(true)
.withQuoteMode(QuoteMode.ALL); .withQuoteMode(QuoteMode.ALL);
StringBuffer buffer = new StringBuffer(); final StringBuffer buffer = new StringBuffer();
CSVPrinter printer = new CSVPrinter(buffer, format); final CSVPrinter printer = new CSVPrinter(buffer, format);
printer.printRecord(new Object[] { "", "Hello", "", "World" }); printer.printRecord(new Object[] { "", "Hello", "", "World" });
//printer.printRecord(new Object[] { null, "Hello", null, "World" }); //printer.printRecord(new Object[] { null, "Hello", null, "World" });

View File

@ -41,7 +41,7 @@ import org.junit.Test;
@Ignore @Ignore
public class JiraCsv213Test { public class JiraCsv213Test {
private void createEndChannel(File csvFile) { private void createEndChannel(final File csvFile) {
// @formatter:off // @formatter:off
final CSVFormat csvFormat = final CSVFormat csvFormat =
CSVFormat.DEFAULT CSVFormat.DEFAULT
@ -56,11 +56,11 @@ public class JiraCsv213Test {
System.out.println(parser.getCurrentLineNumber()); System.out.println(parser.getCurrentLineNumber());
System.out.println(parser.getRecordNumber()); System.out.println(parser.getRecordNumber());
// get only first record we don't need other's // get only first record we don't need other's
CSVRecord firstRecord = parser.iterator().next(); // this fails final CSVRecord firstRecord = parser.iterator().next(); // this fails
return; return;
} }
} catch (IOException e) { } catch (final IOException e) {
throw new RuntimeException("Error while adding end channel to csv", e); throw new RuntimeException("Error while adding end channel to csv", e);
} }