commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1441282 - in /commons/proper/io/trunk/src/test/java/org/apache/commons/io: input/ input/compatibility/ output/
Date Fri, 01 Feb 2013 00:43:59 GMT
Author: sebb
Date: Fri Feb  1 00:43:58 2013
New Revision: 1441282

URL: http://svn.apache.org/viewvc?rev=1441282&view=rev
Log:
Ensure stream is closed

Modified:
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ClosedInputStreamTest.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestParamBlockSize.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestSimple.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/input/XmlStreamReaderUtilitiesTest.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReaderUtilitiesCompatibilityTest.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ByteArrayOutputStreamTestCase.java

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ClosedInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ClosedInputStreamTest.java?rev=1441282&r1=1441281&r2=1441282&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ClosedInputStreamTest.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ClosedInputStreamTest.java
Fri Feb  1 00:43:58 2013
@@ -26,8 +26,10 @@ public class ClosedInputStreamTest exten
     /**
      * Test the <code>read()</code> method.
      */
-    public void testRead() {
-        assertEquals("read()", -1, new ClosedInputStream().read());
+    public void testRead() throws Exception {
+        final ClosedInputStream cis = new ClosedInputStream();
+        assertEquals("read()", -1, cis.read());
+        cis.close();
     }
 
 }

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestParamBlockSize.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestParamBlockSize.java?rev=1441282&r1=1441281&r2=1441282&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestParamBlockSize.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestParamBlockSize.java
Fri Feb  1 00:43:58 2013
@@ -161,13 +161,13 @@ public class ReversedLinesFileReaderTest
     @Test(expected=UnsupportedEncodingException.class)
     public void testUnsupportedEncodingUTF16() throws URISyntaxException, IOException {
         final File testFileEmpty = new File(this.getClass().getResource("/test-file-empty.bin").toURI());
-        new ReversedLinesFileReader(testFileEmpty, testParamBlockSize, "UTF-16");
+        new ReversedLinesFileReader(testFileEmpty, testParamBlockSize, "UTF-16").close();
     }
 
     @Test(expected=UnsupportedEncodingException.class)
     public void testUnsupportedEncodingBig5() throws URISyntaxException, IOException {
         final File testFileEncodingBig5 = new File(this.getClass().getResource("/test-file-empty.bin").toURI());
-        new ReversedLinesFileReader(testFileEncodingBig5, testParamBlockSize, "Big5");
+        new ReversedLinesFileReader(testFileEncodingBig5, testParamBlockSize, "Big5").close();
     }
 
     private void assertFileWithShrinkingTestLines(final ReversedLinesFileReader reversedLinesFileReader)
throws IOException {

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestSimple.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestSimple.java?rev=1441282&r1=1441281&r2=1441282&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestSimple.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestSimple.java
Fri Feb  1 00:43:58 2013
@@ -53,13 +53,13 @@ public class ReversedLinesFileReaderTest
     @Test(expected=UnsupportedEncodingException.class)
     public void testUnsupportedEncodingUTF16() throws URISyntaxException, IOException {
         final File testFileEmpty = new File(this.getClass().getResource("/test-file-empty.bin").toURI());
-        new ReversedLinesFileReader(testFileEmpty, 4096, "UTF-16");
+        new ReversedLinesFileReader(testFileEmpty, 4096, "UTF-16").close();
     }
 
     @Test(expected=UnsupportedEncodingException.class)
     public void testUnsupportedEncodingBig5() throws URISyntaxException, IOException {
         final File testFileEncodingBig5 = new File(this.getClass().getResource("/test-file-empty.bin").toURI());
-        new ReversedLinesFileReader(testFileEncodingBig5, 4096, "Big5");
+        new ReversedLinesFileReader(testFileEncodingBig5, 4096, "Big5").close();
     }
 
 

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=1441282&r1=1441281&r2=1441282&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
Fri Feb  1 00:43:58 2013
@@ -46,22 +46,27 @@ public class XmlStreamReaderTest {
         InputStream is = getXmlStream("no-bom", XML1, encoding, encoding);
         XmlStreamReader xmlReader = new XmlStreamReader(is, false);
         assertEquals(xmlReader.getEncoding(), "UTF-8");
+        xmlReader.close();
 
         is = getXmlStream("no-bom", XML2, encoding, encoding);
         xmlReader = new XmlStreamReader(is);
         assertEquals(xmlReader.getEncoding(), "UTF-8");
+        xmlReader.close();
 
         is = getXmlStream("no-bom", XML3, encoding, encoding);
         xmlReader = new XmlStreamReader(is);
         assertEquals(xmlReader.getEncoding(), encoding);
+        xmlReader.close();
 
         is = getXmlStream("no-bom", XML4, encoding, encoding);
         xmlReader = new XmlStreamReader(is);
         assertEquals(xmlReader.getEncoding(), encoding);
+        xmlReader.close();
 
         is = getXmlStream("no-bom", XML5, encoding, encoding);
         xmlReader = new XmlStreamReader(is);
         assertEquals(xmlReader.getEncoding(), encoding);
+        xmlReader.close();
     }
 
     protected void _testRawNoBomInvalid(final String encoding) throws Exception {
@@ -124,13 +129,15 @@ public class XmlStreamReaderTest {
             assertEquals(xmlReader.getEncoding()
                     .substring(0, encoding.length()), encoding);
         }
+        xmlReader.close();
     }
 
     protected void _testRawBomInvalid(final String bomEnc, final String streamEnc,
             final String prologEnc) throws Exception {
         final InputStream is = getXmlStream(bomEnc, XML3, streamEnc, prologEnc);
+        XmlStreamReader xmlReader = null;
         try {
-            final XmlStreamReader xmlReader = new XmlStreamReader(is, false);
+            xmlReader = new XmlStreamReader(is, false);
             final String foundEnc = xmlReader.getEncoding();
             fail("Expected IOException for BOM " + bomEnc + ", streamEnc "
                     + streamEnc + " and prologEnc " + prologEnc + ": found "
@@ -138,6 +145,9 @@ public class XmlStreamReaderTest {
         } catch (final IOException ex) {
             assertTrue(ex.getMessage().indexOf("Invalid encoding,") > -1);
         }
+        if (xmlReader != null) {
+            xmlReader.close();
+        }
     }
 
     @Test
@@ -306,6 +316,7 @@ public class XmlStreamReaderTest {
             assertEquals(xmlReader.getEncoding().substring(0,
                     streamEnc.length()), streamEnc);
         }
+        xmlReader.close();
     }
 
     public void _testHttpValid(final String cT, final String bomEnc, final String streamEnc,
@@ -322,6 +333,7 @@ public class XmlStreamReaderTest {
             assertEquals(xmlReader.getEncoding().substring(0,
                     streamEnc.length()), streamEnc);
         }
+        xmlReader.close();
     }
 
     protected void _testHttpInvalid(final String cT, final String bomEnc, final String streamEnc,
@@ -344,6 +356,7 @@ public class XmlStreamReaderTest {
                 prologEnc == null ? XML2 : XML3, streamEnc, prologEnc);
         final XmlStreamReader xmlReader = new XmlStreamReader(is, cT, true);
         assertEquals(xmlReader.getEncoding(), shouldbe);
+        xmlReader.close();
     }
 
     private static final String ENCODING_ATTRIBUTE_XML = "<?xml version=\"1.0\" ?>
\n"
@@ -359,6 +372,7 @@ public class XmlStreamReaderTest {
                 .getBytes("UTF-8"));
         final XmlStreamReader xmlReader = new XmlStreamReader(is, "", true);
         assertEquals(xmlReader.getEncoding(), "UTF-8");
+        xmlReader.close();
     }
 
     // XML Stream generator

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/XmlStreamReaderUtilitiesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/XmlStreamReaderUtilitiesTest.java?rev=1441282&r1=1441281&r2=1441282&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/XmlStreamReaderUtilitiesTest.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/XmlStreamReaderUtilitiesTest.java
Fri Feb  1 00:43:58 2013
@@ -223,7 +223,9 @@ public class XmlStreamReaderUtilitiesTes
     protected String calculateRawEncoding(final String bomEnc, final String xmlGuessEnc,
final String xmlEnc,
             final String defaultEncoding) throws IOException {
         final MockXmlStreamReader mock = new MockXmlStreamReader(defaultEncoding);
-        return mock.calculateRawEncoding(bomEnc, xmlGuessEnc, xmlEnc);
+        final String enc = mock.calculateRawEncoding(bomEnc, xmlGuessEnc, xmlEnc);
+        mock.close();
+        return enc;
     }
     
     private void checkRawError(final String msgSuffix,
@@ -306,7 +308,9 @@ public class XmlStreamReaderUtilitiesTes
     protected String calculateHttpEncoding(final String httpContentType, final String bomEnc,
final String xmlGuessEnc,
             final String xmlEnc, final boolean lenient, final String defaultEncoding) throws
IOException {
         final MockXmlStreamReader mock = new MockXmlStreamReader(defaultEncoding);
-        return mock.calculateHttpEncoding(httpContentType, bomEnc, xmlGuessEnc, xmlEnc, lenient);
+        final String enc = mock.calculateHttpEncoding(httpContentType, bomEnc, xmlGuessEnc,
xmlEnc, lenient);
+        mock.close();
+        return enc;
     }
     
     private void checkHttpError(final String msgSuffix, final boolean lenient, final String
httpContentType,

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReaderUtilitiesCompatibilityTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReaderUtilitiesCompatibilityTest.java?rev=1441282&r1=1441281&r2=1441282&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReaderUtilitiesCompatibilityTest.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReaderUtilitiesCompatibilityTest.java
Fri Feb  1 00:43:58 2013
@@ -30,16 +30,20 @@ public class XmlStreamReaderUtilitiesCom
     protected String calculateRawEncoding(final String bomEnc, final String xmlGuessEnc,
final String xmlEnc,
             final String defaultEncoding) throws IOException {
         final MockXmlStreamReader mock = new MockXmlStreamReader(defaultEncoding);
-        return mock.calculateRawEncoding(bomEnc, xmlGuessEnc, xmlEnc, null);
+        final String enc = mock.calculateRawEncoding(bomEnc, xmlGuessEnc, xmlEnc, null);
+        mock.close();
+        return enc;
     }
     @Override
     protected String calculateHttpEncoding(final String httpContentType, final String bomEnc,
final String xmlGuessEnc,
             final String xmlEnc, final boolean lenient, final String defaultEncoding) throws
IOException {
         final MockXmlStreamReader mock = new MockXmlStreamReader(defaultEncoding);
-        return mock.calculateHttpEncoding(
+        String enc = mock.calculateHttpEncoding(
                 XmlStreamReader.getContentTypeMime(httpContentType),
                 XmlStreamReader.getContentTypeEncoding(httpContentType),
                 bomEnc, xmlGuessEnc, xmlEnc, null, lenient);
+        mock.close();
+        return enc;
     }
 
     /** Mock {@link XmlStreamReader} implementation */

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ByteArrayOutputStreamTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ByteArrayOutputStreamTestCase.java?rev=1441282&r1=1441281&r2=1441282&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ByteArrayOutputStreamTestCase.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ByteArrayOutputStreamTestCase.java
Fri Feb  1 00:43:58 2013
@@ -140,8 +140,11 @@ public class ByteArrayOutputStreamTestCa
         
         //Make sure that empty ByteArrayOutputStreams really don't create garbage
         //on toByteArray()
-        assertSame(new ByteArrayOutputStream().toByteArray(),
-            new ByteArrayOutputStream().toByteArray());
+        final ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
+        final ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
+        assertSame(baos1.toByteArray(), baos2.toByteArray());
+        baos1.close();
+        baos2.close();
     }
 }
 



Mime
View raw message