You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2015/08/10 13:26:23 UTC
svn commit: r1695021 - in
/commons/proper/io/trunk/src/test/java/org/apache/commons/io: input/ output/
Author: sebb
Date: Mon Aug 10 11:26:22 2015
New Revision: 1695021
URL: http://svn.apache.org/r1695021
Log:
Ensure streams are closed
Modified:
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ChunkedOutputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ChunkedWriterTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ClosedOutputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java?rev=1695021&r1=1695020&r2=1695021&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java Mon Aug 10 11:26:22 2015
@@ -367,13 +367,13 @@ public class BOMInputStreamTest {
public void testNoBoms() throws Exception {
final byte[] data = new byte[] { 'A', 'B', 'C' };
try {
- new BOMInputStream(createUtf8DataStream(data, true), false, (ByteOrderMark[])null);
+ (new BOMInputStream(createUtf8DataStream(data, true), false, (ByteOrderMark[])null)).close();;
fail("Null BOMs, expected IllegalArgumentException");
} catch (final IllegalArgumentException e) {
// expected
}
try {
- new BOMInputStream(createUtf8DataStream(data, true), false, new ByteOrderMark[0]);
+ (new BOMInputStream(createUtf8DataStream(data, true), false, new ByteOrderMark[0])).close();;
fail("Null BOMs, expected IllegalArgumentException");
} catch (final IllegalArgumentException e) {
// expected
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java?rev=1695021&r1=1695020&r2=1695021&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java Mon Aug 10 11:26:22 2015
@@ -68,7 +68,7 @@ public class XmlStreamReaderTest {
protected void _testRawNoBomInvalid(final String encoding) throws Exception {
final InputStream is = getXmlStream("no-bom", XML3, encoding, encoding);
try {
- new XmlStreamReader(is, false);
+ (new XmlStreamReader(is, false)).close();;
fail("It should have failed");
} catch (final IOException ex) {
assertTrue(ex.getMessage().contains("Invalid encoding,"));
@@ -337,7 +337,7 @@ public class XmlStreamReaderTest {
final InputStream is = getXmlStream(bomEnc,
prologEnc == null ? XML2 : XML3, streamEnc, prologEnc);
try {
- new XmlStreamReader(is, cT, false);
+ (new XmlStreamReader(is, cT, false)).close();;
fail("It should have failed for HTTP Content-type " + cT + ", BOM "
+ bomEnc + ", streamEnc " + streamEnc + " and prologEnc "
+ prologEnc);
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ChunkedOutputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ChunkedOutputStreamTest.java?rev=1695021&r1=1695020&r2=1695021&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ChunkedOutputStreamTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ChunkedOutputStreamTest.java Mon Aug 10 11:26:22 2015
@@ -35,11 +35,13 @@ public class ChunkedOutputStreamTest {
ChunkedOutputStream chunked = new ChunkedOutputStream(baos, 10);
chunked.write("0123456789012345678901234567891".getBytes());
assertEquals(4, numWrites.get());
+ chunked.close();
}
@Test(expected = IllegalArgumentException.class)
- public void negative_chunksize_not_permitted() {
- new ChunkedOutputStream(new ByteArrayOutputStream(), 0);
+ public void negative_chunksize_not_permitted() throws Exception{
+ ChunkedOutputStream chunked = new ChunkedOutputStream(new ByteArrayOutputStream(), 0);
+ chunked.close();
}
@Test
@@ -49,6 +51,7 @@ public class ChunkedOutputStreamTest {
ChunkedOutputStream chunked = new ChunkedOutputStream(baos);
chunked.write(new byte[1024 * 4 + 1]);
assertEquals(2, numWrites.get());
+ chunked.close();
}
private ByteArrayOutputStream getByteArrayOutputStream(final AtomicInteger numWrites) {
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ChunkedWriterTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ChunkedWriterTest.java?rev=1695021&r1=1695020&r2=1695021&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ChunkedWriterTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ChunkedWriterTest.java Mon Aug 10 11:26:22 2015
@@ -34,6 +34,7 @@ public class ChunkedWriterTest {
chunked.write("0123456789012345678901234567891".toCharArray());
chunked.flush();
assertEquals(4, numWrites.get());
+ chunked.close();
}
@Test
@@ -45,6 +46,7 @@ public class ChunkedWriterTest {
chunked.write(new char[1024 * 4 + 1]);
chunked.flush();
assertEquals(2, numWrites.get());
+ chunked.close();
}
private OutputStreamWriter getOutputStreamWriter(final AtomicInteger numWrites) {
@@ -59,7 +61,7 @@ public class ChunkedWriterTest {
}
@Test(expected = IllegalArgumentException.class)
- public void negative_chunksize_not_permitted() {
- new ChunkedWriter(new OutputStreamWriter(new ByteArrayOutputStream()), 0);
+ public void negative_chunksize_not_permitted() throws Exception {
+ (new ChunkedWriter(new OutputStreamWriter(new ByteArrayOutputStream()), 0)).close();;
}
}
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ClosedOutputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ClosedOutputStreamTest.java?rev=1695021&r1=1695020&r2=1695021&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ClosedOutputStreamTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ClosedOutputStreamTest.java Mon Aug 10 11:26:22 2015
@@ -27,13 +27,18 @@ public class ClosedOutputStreamTest exte
/**
* Test the <code>write(b)</code> method.
+ * @throws Exception
*/
- public void testRead() {
+ public void testRead() throws Exception {
+ ClosedOutputStream cos = null;
try {
- new ClosedOutputStream().write('x');
+ cos = new ClosedOutputStream();
+ cos.write('x');
fail("write(b)");
} catch (final IOException e) {
// expected
+ } finally {
+ cos.close();
}
}
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java?rev=1695021&r1=1695020&r2=1695021&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java Mon Aug 10 11:26:22 2015
@@ -324,15 +324,16 @@ public class DeferredFileOutputStreamTes
/**
* Test specifying a temporary file and the threshold is reached.
+ * @throws Exception
*/
- public void testTempFileError() {
+ public void testTempFileError() throws Exception {
final String prefix = null;
final String suffix = ".out";
final File tempDir = new File(".");
try
{
- new DeferredFileOutputStream(testBytes.length - 5, prefix, suffix, tempDir);
+ (new DeferredFileOutputStream(testBytes.length - 5, prefix, suffix, tempDir)).close();
fail("Expected IllegalArgumentException ");
}
catch (final IllegalArgumentException e) {