You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/10/26 14:13:03 UTC
[commons-csv] branch master updated: Add @SuppressWarnings("resource") in test as narrowly as possible
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-csv.git
The following commit(s) were added to refs/heads/master by this push:
new 236b0f4f Add @SuppressWarnings("resource") in test as narrowly as possible
236b0f4f is described below
commit 236b0f4f84f1629df4bd68540cc9597fb8583aa4
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Oct 26 10:12:58 2022 -0400
Add @SuppressWarnings("resource") in test as narrowly as possible
---
src/test/java/org/apache/commons/csv/CSVParserTest.java | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java b/src/test/java/org/apache/commons/csv/CSVParserTest.java
index ae4769f0..dfae3094 100644
--- a/src/test/java/org/apache/commons/csv/CSVParserTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java
@@ -905,8 +905,10 @@ public class CSVParserTest {
final Iterator<CSVRecord> records = parser.iterator();
final CSVRecord record = records.next();
// Expect the null header to be missing
- assertEquals(Arrays.asList("header1", "header3"), record.getParser().getHeaderNames());
- assertEquals(2, record.getParser().getHeaderMap().size());
+ @SuppressWarnings("resource")
+ final CSVParser recordParser = record.getParser();
+ assertEquals(Arrays.asList("header1", "header3"), recordParser.getHeaderNames());
+ assertEquals(2, recordParser.getHeaderMap().size());
}
}
@@ -1132,7 +1134,8 @@ public class CSVParserTest {
final CSVFormat format = CSVFormat.DEFAULT.withHeader("A", "B", "C", "D");
final Charset charset = StandardCharsets.UTF_8;
- try (final CSVParser parser = CSVParser.parse(new InputStreamReader(url.openStream(), charset), format)) {
+ try (@SuppressWarnings("resource") // CSVParser closes the input resource
+ final CSVParser parser = CSVParser.parse(new InputStreamReader(url.openStream(), charset), format)) {
parseFully(parser);
}
try (final CSVParser parser = CSVParser.parse(new String(Files.readAllBytes(Paths.get(url.toURI())), charset), format)) {
@@ -1141,7 +1144,8 @@ public class CSVParserTest {
try (final CSVParser parser = CSVParser.parse(new File(url.toURI()), charset, format)) {
parseFully(parser);
}
- try (final CSVParser parser = CSVParser.parse(url.openStream(), charset, format)) {
+ try (@SuppressWarnings("resource") // CSVParser closes the input resource
+ final CSVParser parser = CSVParser.parse(url.openStream(), charset, format)) {
parseFully(parser);
}
try (final CSVParser parser = CSVParser.parse(Paths.get(url.toURI()), charset, format)) {
@@ -1313,7 +1317,9 @@ public class CSVParserTest {
try (final CSVParser parser = CSVFormat.DEFAULT.withFirstRecordAsHeader().withTrim().parse(in)) {
final Iterator<CSVRecord> records = parser.iterator();
final CSVRecord record = records.next();
- assertEquals(Arrays.asList("header1", "header2", "header1"), record.getParser().getHeaderNames());
+ @SuppressWarnings("resource")
+ final CSVParser recordParser = record.getParser();
+ assertEquals(Arrays.asList("header1", "header2", "header1"), recordParser.getHeaderNames());
}}
@Test