From 4e02db1272c2f47c4c4a3746f557d28646e77abc Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 24 Feb 2019 10:10:09 -0500 Subject: [PATCH] Use try-with-resources. --- .../commons/csv/issues/JiraCsv203Test.java | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) 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 bff193b5..847f05e3 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv203Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv203Test.java @@ -35,9 +35,9 @@ public class JiraCsv203Test { .withQuoteMode(QuoteMode.ALL); final StringBuffer buffer = new StringBuffer(); - final CSVPrinter printer = new CSVPrinter(buffer, format); - printer.printRecord(new Object[] { null, "Hello", null, "World" }); - + try (final CSVPrinter printer = new CSVPrinter(buffer, format)) { + printer.printRecord(new Object[] { null, "Hello", null, "World" }); + } Assert.assertEquals("\"N/A\",\"Hello\",\"N/A\",\"World\"\r\n", buffer.toString()); } @@ -49,9 +49,9 @@ public class JiraCsv203Test { .withQuoteMode(QuoteMode.ALL_NON_NULL); final StringBuffer buffer = new StringBuffer(); - final CSVPrinter printer = new CSVPrinter(buffer, format); - printer.printRecord(new Object[] { null, "Hello", null, "World" }); - + try (final CSVPrinter printer = new CSVPrinter(buffer, format)) { + printer.printRecord(new Object[] { null, "Hello", null, "World" }); + } Assert.assertEquals("N/A,\"Hello\",N/A,\"World\"\r\n", buffer.toString()); } @@ -62,9 +62,9 @@ public class JiraCsv203Test { .withIgnoreSurroundingSpaces(true); final StringBuffer buffer = new StringBuffer(); - final CSVPrinter printer = new CSVPrinter(buffer, format); - printer.printRecord(new Object[] { null, "Hello", null, "World" }); - + try (final CSVPrinter printer = new CSVPrinter(buffer, format)) { + printer.printRecord(new Object[] { null, "Hello", null, "World" }); + } Assert.assertEquals("N/A,Hello,N/A,World\r\n", buffer.toString()); } @@ -76,9 +76,9 @@ public class JiraCsv203Test { .withQuoteMode(QuoteMode.MINIMAL); final StringBuffer buffer = new StringBuffer(); - final CSVPrinter printer = new CSVPrinter(buffer, format); - printer.printRecord(new Object[] { null, "Hello", null, "World" }); - + try (final CSVPrinter printer = new CSVPrinter(buffer, format)) { + printer.printRecord(new Object[] { null, "Hello", null, "World" }); + } Assert.assertEquals("N/A,Hello,N/A,World\r\n", buffer.toString()); } @@ -90,9 +90,9 @@ public class JiraCsv203Test { .withQuoteMode(QuoteMode.NON_NUMERIC); final StringBuffer buffer = new StringBuffer(); - final CSVPrinter printer = new CSVPrinter(buffer, format); - printer.printRecord(new Object[] { null, "Hello", null, "World" }); - + try (final CSVPrinter printer = new CSVPrinter(buffer, format)) { + printer.printRecord(new Object[] { null, "Hello", null, "World" }); + } Assert.assertEquals("N/A,\"Hello\",N/A,\"World\"\r\n", buffer.toString()); } @@ -104,9 +104,9 @@ public class JiraCsv203Test { .withQuoteMode(QuoteMode.ALL); final StringBuffer buffer = new StringBuffer(); - final CSVPrinter printer = new CSVPrinter(buffer, format); - printer.printRecord(new Object[] { null, "Hello", null, "World" }); - + try (final CSVPrinter printer = new CSVPrinter(buffer, format)) { + printer.printRecord(new Object[] { null, "Hello", null, "World" }); + } Assert.assertEquals(",\"Hello\",,\"World\"\r\n", buffer.toString()); } @@ -118,10 +118,10 @@ public class JiraCsv203Test { .withQuoteMode(QuoteMode.ALL); final StringBuffer buffer = new StringBuffer(); - final CSVPrinter printer = new CSVPrinter(buffer, format); - printer.printRecord(new Object[] { "", "Hello", "", "World" }); - //printer.printRecord(new Object[] { null, "Hello", null, "World" }); - + try (final CSVPrinter printer = new CSVPrinter(buffer, format)) { + printer.printRecord(new Object[] { "", "Hello", "", "World" }); + //printer.printRecord(new Object[] { null, "Hello", null, "World" }); + } Assert.assertEquals("\"\",\"Hello\",\"\",\"World\"\r\n", buffer.toString()); } } \ No newline at end of file