Avoid resource leak warnings

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1582813 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2014-03-28 16:37:54 +00:00
parent d6294bc598
commit 1933f8abaf
6 changed files with 49 additions and 4 deletions

View File

@ -124,6 +124,7 @@ public class CSVFileParserTest {
final int count = record.size();
assertEquals(testName, readTestData(), count+":"+parsed);
}
parser.close();
}
@Test
@ -167,5 +168,6 @@ public class CSVFileParserTest {
final int count = record.size();
assertEquals(testName, readTestData(), count + ":" + parsed);
}
parser.close();
}
}

View File

@ -114,6 +114,7 @@ public class CSVParserTest {
assertTrue(records.size() > 0);
Utils.compare("Records do not match expected result", res, records);
parser.close();
}
@Test
@ -143,6 +144,7 @@ public class CSVParserTest {
assertTrue(records.size() > 0);
Utils.compare("", res, records);
parser.close();
}
@Test
@ -176,6 +178,7 @@ public class CSVParserTest {
for (int i = 0; i < res.length; i++) {
assertArrayEquals(res[i], records.get(i).values());
}
parser.close();
}
@Test
@ -207,6 +210,7 @@ public class CSVParserTest {
}
} finally {
parser.close();
reader.close();
}
}
@ -216,6 +220,7 @@ public class CSVParserTest {
final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
final List<CSVRecord> records = parser.getRecords();
assertEquals(4, records.size());
parser.close();
}
@Test
@ -224,6 +229,7 @@ public class CSVParserTest {
final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
final List<CSVRecord> records = parser.getRecords();
assertEquals(4, records.size());
parser.close();
}
@Test(expected = NoSuchElementException.class)
@ -243,6 +249,7 @@ public class CSVParserTest {
final List<CSVRecord> list = parser.getRecords();
assertNotNull(list);
assertEquals(0, list.size());
parser.close();
}
@Test
@ -275,16 +282,19 @@ public class CSVParserTest {
};
format = CSVFormat.DEFAULT.withCommentStart('#');
parser.close();
parser = CSVParser.parse(code, format);
records = parser.getRecords();
Utils.compare("Failed to parse with comments", res_comments, records);
parser.close();
}
@Test
public void testEmptyFile() throws Exception {
final CSVParser parser = CSVParser.parse("", CSVFormat.DEFAULT);
assertNull(parser.nextRecord());
parser.close();
}
@Test
@ -306,6 +316,7 @@ public class CSVParserTest {
for (int i = 0; i < res.length; i++) {
assertArrayEquals(res[i], records.get(i).values());
}
parser.close();
}
}
@ -330,6 +341,7 @@ public class CSVParserTest {
for (int i = 0; i < res.length; i++) {
assertArrayEquals(res[i], records.get(i).values());
}
parser.close();
}
}
@ -357,6 +369,7 @@ public class CSVParserTest {
for (int i = 0; i < res.length; i++) {
assertArrayEquals(res[i], records.get(i).values());
}
parser.close();
}
}
@ -386,6 +399,7 @@ public class CSVParserTest {
for (int i = 0; i < res.length; i++) {
assertArrayEquals(res[i], records.get(i).values());
}
parser.close();
}
}
@ -408,6 +422,7 @@ public class CSVParserTest {
for (int i = 0; i < res.length; i++) {
assertArrayEquals(res[i], records.get(i).values());
}
parser.close();
}
@Test
@ -427,6 +442,7 @@ public class CSVParserTest {
for (int i = 0; i < res.length; i++) {
assertArrayEquals(res[i], records.get(i).values());
}
parser.close();
}
@Test
@ -466,6 +482,7 @@ public class CSVParserTest {
}
assertFalse(records.hasNext());
parser.close();
}
@Test
@ -476,6 +493,7 @@ public class CSVParserTest {
}
assertNull(parser.nextRecord());
parser.close();
}
@Test
@ -517,6 +535,7 @@ public class CSVParserTest {
for (int i = 0; i < RESULT.length; i++) {
assertArrayEquals(RESULT[i], records.get(i).values());
}
parser.close();
}
@Test
@ -541,6 +560,7 @@ public class CSVParserTest {
assertNull(record = parser.nextRecord());
assertEquals(8, parser.getCurrentLineNumber());
assertEquals(3, parser.getRecordNumber());
parser.close();
}
@Test
@ -585,6 +605,7 @@ public class CSVParserTest {
final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
final List<CSVRecord> records = parser.getRecords();
assertEquals(3, records.size());
parser.close();
}
@Test(expected = IllegalArgumentException.class)
@ -628,6 +649,7 @@ public class CSVParserTest {
final CSVParser parser = CSVParser.parse(code, CSVFormat.DEFAULT);
final List<CSVRecord> records = parser.getRecords();
assertEquals(4, records.size());
parser.close();
}
@Test
@ -681,22 +703,24 @@ public class CSVParserTest {
assertEquals("d", second.get(0));
assertEquals("e", second.get(1));
assertEquals("f", second.get(2));
parser.close();
}
@Test(expected = IllegalArgumentException.class)
public void testNewCSVParserNullReaderFormat() throws Exception {
new CSVParser(null, CSVFormat.DEFAULT);
new CSVParser(null, CSVFormat.DEFAULT).close();
}
@Test(expected = IllegalArgumentException.class)
public void testNewCSVParserReaderNullFormat() throws Exception {
new CSVParser(new StringReader(""), null);
new CSVParser(new StringReader(""), null).close();
}
@Test
public void testNoHeaderMap() throws Exception {
final CSVParser parser = CSVParser.parse("a,b,c\n1,2,3\nx,y,z", CSVFormat.DEFAULT);
Assert.assertNull(parser.getHeaderMap());
parser.close();
}
@Test(expected = IllegalArgumentException.class)
@ -824,6 +848,7 @@ public class CSVParserTest {
assertNull(parser.nextRecord());
// Still 2 because the last line is does not have EOL chars
assertEquals(2, parser.getCurrentLineNumber());
parser.close();
}
private void validateRecordNumbers(final String lineSeparator) throws IOException {
@ -841,6 +866,7 @@ public class CSVParserTest {
assertEquals(3, parser.getRecordNumber());
assertNull(record = parser.nextRecord());
assertEquals(3, parser.getRecordNumber());
parser.close();
}
}

View File

@ -89,6 +89,7 @@ public class CSVPrinterTest {
final List<CSVRecord> parseResult = parser.getRecords();
Utils.compare("Printer output :" + printable(result), lines, parseResult);
parser.close();
}
private void doRandom(final CSVFormat format, final int iter) throws Exception {
@ -336,6 +337,7 @@ public class CSVPrinterTest {
assertEquals(null, record.get(1));
assertEquals("b", record.get(2));
assertFalse(iterator.hasNext());
((CSVParser) iterable).close();
}
@Test
@ -492,11 +494,11 @@ public class CSVPrinterTest {
@Test(expected = IllegalArgumentException.class)
public void testNewCSVPrinterNullAppendableFormat() throws Exception {
new CSVPrinter(null, CSVFormat.DEFAULT);
new CSVPrinter(null, CSVFormat.DEFAULT).close();
}
@Test(expected = IllegalArgumentException.class)
public void testNewCsvPrinterAppendableNullFormat() throws Exception {
new CSVPrinter(new StringWriter(), null);
new CSVPrinter(new StringWriter(), null).close();
}
}

View File

@ -151,6 +151,7 @@ public class CSVRecordTest {
Collections.sort(list);
printer.printRecord(list);
Assert.assertEquals("A,B,C,NewValue" + CSVFormat.DEFAULT.getRecordSeparator(), printer.getOut().toString());
printer.close();
}
@Test

View File

@ -42,6 +42,7 @@ public class ExtendedBufferedReaderTest {
assertEquals(END_OF_STREAM, br.getLastChar());
assertNull(br.readLine());
assertEquals(0, br.read(new char[10], 0, 0));
br.close();
}
@Test
@ -100,6 +101,7 @@ public class ExtendedBufferedReaderTest {
assertEquals(END_OF_STREAM, br.lookAhead());
assertEquals(3, br.getCurrentLineNumber());
br.close();
}
@Test
@ -120,6 +122,7 @@ public class ExtendedBufferedReaderTest {
assertEquals(1, br.read(res, 4, 1));
assertArrayEquals(ref, res);
assertEquals('d', br.getLastChar());
br.close();
}
@Test
@ -127,10 +130,12 @@ public class ExtendedBufferedReaderTest {
ExtendedBufferedReader br = getBufferedReader("");
assertNull(br.readLine());
br.close();
br = getBufferedReader("\n");
assertEquals("",br.readLine());
assertNull(br.readLine());
br.close();
br = getBufferedReader("foo\n\nhello");
assertEquals(0, br.getCurrentLineNumber());
assertEquals("foo",br.readLine());
@ -142,6 +147,7 @@ public class ExtendedBufferedReaderTest {
assertNull(br.readLine());
assertEquals(3, br.getCurrentLineNumber());
br.close();
br = getBufferedReader("foo\n\nhello");
assertEquals('f', br.read());
assertEquals('o', br.lookAhead());
@ -156,6 +162,7 @@ public class ExtendedBufferedReaderTest {
assertEquals(3, br.getCurrentLineNumber());
br.close();
br = getBufferedReader("foo\rbaar\r\nfoo");
assertEquals("foo",br.readLine());
assertEquals('b', br.lookAhead());
@ -163,6 +170,7 @@ public class ExtendedBufferedReaderTest {
assertEquals('f', br.lookAhead());
assertEquals("foo",br.readLine());
assertNull(br.readLine());
br.close();
}
/*
@ -184,6 +192,7 @@ public class ExtendedBufferedReaderTest {
}
assertEquals(EOLeolct, br.getCurrentLineNumber());
br.close();
br = getBufferedReader(test);
assertEquals(0, br.getCurrentLineNumber());
while (br.read() != -1) {
@ -191,6 +200,7 @@ public class ExtendedBufferedReaderTest {
}
assertEquals(EOLeolct, br.getCurrentLineNumber());
br.close();
br = getBufferedReader(test);
assertEquals(0, br.getCurrentLineNumber());
final char[] buff = new char[10];
@ -198,6 +208,7 @@ public class ExtendedBufferedReaderTest {
// consume all
}
assertEquals(EOLeolct, br.getCurrentLineNumber());
br.close();
}
private ExtendedBufferedReader getBufferedReader(final String s) {

View File

@ -219,6 +219,7 @@ public class PerformanceTest {
final Stats s = iterate(parser);
reader.close();
show("CSV", s, t0);
parser.close();
}
show();
}
@ -266,6 +267,8 @@ public class PerformanceTest {
break;
case COMMENT: // not really expecting these
break;
default:
throw new IllegalStateException("Unexpected Token type: " + token.type);
}
} while (!token.type.equals(Token.Type.EOF));