From ae79aeaa0bae191c9cde99f40971b6aa5788245d Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 14 Sep 2024 09:41:02 -0400 Subject: [PATCH] Use try-with-resources --- .../commons/csv/issues/JiraCsv290Test.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv290Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv290Test.java index 0fbac052..9c6badbb 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv290Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv290Test.java @@ -94,22 +94,18 @@ public class JiraCsv290Test { @Test public void testWriteThenRead() throws Exception { final StringWriter sw = new StringWriter(); - try (CSVPrinter printer = new CSVPrinter(sw, CSVFormat.POSTGRESQL_CSV.builder().setHeader().setSkipHeaderRecord(true).build())) { - printer.printRecord("column1", "column2"); printer.printRecord("v11", "v12"); printer.printRecord("v21", "v22"); printer.close(); - - final CSVParser parser = new CSVParser(new StringReader(sw.toString()), - CSVFormat.POSTGRESQL_CSV.builder().setHeader().setSkipHeaderRecord(true).build()); - - assertArrayEquals(new Object[] { "column1", "column2" }, parser.getHeaderNames().toArray()); - - final Iterator i = parser.iterator(); - assertArrayEquals(new String[] { "v11", "v12" }, i.next().toList().toArray()); - assertArrayEquals(new String[] { "v21", "v22" }, i.next().toList().toArray()); + try (CSVParser parser = new CSVParser(new StringReader(sw.toString()), + CSVFormat.POSTGRESQL_CSV.builder().setHeader().setSkipHeaderRecord(true).build())) { + assertArrayEquals(new Object[] { "column1", "column2" }, parser.getHeaderNames().toArray()); + final Iterator i = parser.iterator(); + assertArrayEquals(new String[] { "v11", "v12" }, i.next().toList().toArray()); + assertArrayEquals(new String[] { "v21", "v22" }, i.next().toList().toArray()); + } } } -} \ No newline at end of file +}