Skip to content

Commit 4e02db1

Browse files
author
Gary Gregory
committed
Use try-with-resources.
1 parent 574ed87 commit 4e02db1

1 file changed

Lines changed: 22 additions & 22 deletions

File tree

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public void testQuoteModeAll() throws Exception {
3535
.withQuoteMode(QuoteMode.ALL);
3636

3737
final StringBuffer buffer = new StringBuffer();
38-
final CSVPrinter printer = new CSVPrinter(buffer, format);
39-
printer.printRecord(new Object[] { null, "Hello", null, "World" });
40-
38+
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
39+
printer.printRecord(new Object[] { null, "Hello", null, "World" });
40+
}
4141
Assert.assertEquals("\"N/A\",\"Hello\",\"N/A\",\"World\"\r\n", buffer.toString());
4242
}
4343

@@ -49,9 +49,9 @@ public void testQuoteModeAllNonNull() throws Exception {
4949
.withQuoteMode(QuoteMode.ALL_NON_NULL);
5050

5151
final StringBuffer buffer = new StringBuffer();
52-
final CSVPrinter printer = new CSVPrinter(buffer, format);
53-
printer.printRecord(new Object[] { null, "Hello", null, "World" });
54-
52+
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
53+
printer.printRecord(new Object[] { null, "Hello", null, "World" });
54+
}
5555
Assert.assertEquals("N/A,\"Hello\",N/A,\"World\"\r\n", buffer.toString());
5656
}
5757

@@ -62,9 +62,9 @@ public void testWithoutQuoteMode() throws Exception {
6262
.withIgnoreSurroundingSpaces(true);
6363

6464
final StringBuffer buffer = new StringBuffer();
65-
final CSVPrinter printer = new CSVPrinter(buffer, format);
66-
printer.printRecord(new Object[] { null, "Hello", null, "World" });
67-
65+
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
66+
printer.printRecord(new Object[] { null, "Hello", null, "World" });
67+
}
6868
Assert.assertEquals("N/A,Hello,N/A,World\r\n", buffer.toString());
6969
}
7070

@@ -76,9 +76,9 @@ public void testQuoteModeMinimal() throws Exception {
7676
.withQuoteMode(QuoteMode.MINIMAL);
7777

7878
final StringBuffer buffer = new StringBuffer();
79-
final CSVPrinter printer = new CSVPrinter(buffer, format);
80-
printer.printRecord(new Object[] { null, "Hello", null, "World" });
81-
79+
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
80+
printer.printRecord(new Object[] { null, "Hello", null, "World" });
81+
}
8282
Assert.assertEquals("N/A,Hello,N/A,World\r\n", buffer.toString());
8383
}
8484

@@ -90,9 +90,9 @@ public void testQuoteModeNonNumeric() throws Exception {
9090
.withQuoteMode(QuoteMode.NON_NUMERIC);
9191

9292
final StringBuffer buffer = new StringBuffer();
93-
final CSVPrinter printer = new CSVPrinter(buffer, format);
94-
printer.printRecord(new Object[] { null, "Hello", null, "World" });
95-
93+
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
94+
printer.printRecord(new Object[] { null, "Hello", null, "World" });
95+
}
9696
Assert.assertEquals("N/A,\"Hello\",N/A,\"World\"\r\n", buffer.toString());
9797
}
9898

@@ -104,9 +104,9 @@ public void testWithoutNullString() throws Exception {
104104
.withQuoteMode(QuoteMode.ALL);
105105

106106
final StringBuffer buffer = new StringBuffer();
107-
final CSVPrinter printer = new CSVPrinter(buffer, format);
108-
printer.printRecord(new Object[] { null, "Hello", null, "World" });
109-
107+
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
108+
printer.printRecord(new Object[] { null, "Hello", null, "World" });
109+
}
110110
Assert.assertEquals(",\"Hello\",,\"World\"\r\n", buffer.toString());
111111
}
112112

@@ -118,10 +118,10 @@ public void testWithEmptyValues() throws Exception {
118118
.withQuoteMode(QuoteMode.ALL);
119119

120120
final StringBuffer buffer = new StringBuffer();
121-
final CSVPrinter printer = new CSVPrinter(buffer, format);
122-
printer.printRecord(new Object[] { "", "Hello", "", "World" });
123-
//printer.printRecord(new Object[] { null, "Hello", null, "World" });
124-
121+
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
122+
printer.printRecord(new Object[] { "", "Hello", "", "World" });
123+
//printer.printRecord(new Object[] { null, "Hello", null, "World" });
124+
}
125125
Assert.assertEquals("\"\",\"Hello\",\"\",\"World\"\r\n", buffer.toString());
126126
}
127127
}

0 commit comments

Comments
 (0)