Use try-with-resources
This commit is contained in:
parent
1667e5734d
commit
ae79aeaa0b
|
@ -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());
|
||||
|
||||
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<CSVRecord> i = parser.iterator();
|
||||
assertArrayEquals(new String[] { "v11", "v12" }, i.next().toList().toArray());
|
||||
assertArrayEquals(new String[] { "v21", "v22" }, i.next().toList().toArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue