Author: kkolinko
Date: Thu Jun  7 12:22:35 2012
New Revision: 1347584

URL: http://svn.apache.org/viewvc?rev=1347584&view=rev
Log:
Merged revision 1347583 from tomcat/trunk:
Review of r1347108.
Better cleanup if the test fails:
- schedule temporary directory for after-test cleanup immediately, instead of 
after successful test run.
- close output streams even if write fails.

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/test/org/apache/naming/resources/TestNamingContext.java

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1347583

Modified: 
tomcat/tc7.0.x/trunk/test/org/apache/naming/resources/TestNamingContext.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/naming/resources/TestNamingContext.java?rev=1347584&r1=1347583&r2=1347584&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/test/org/apache/naming/resources/TestNamingContext.java 
(original)
+++ 
tomcat/tc7.0.x/trunk/test/org/apache/naming/resources/TestNamingContext.java 
Thu Jun  7 12:22:35 2012
@@ -112,6 +112,9 @@ public class TestNamingContext extends T
         File alternate1 = new File(tmpDir, "alternate1");
         File alternate2 = new File(tmpDir, "alternate2");
 
+        // Register for clean-up
+        addDeleteOnTearDown(tmpDir);
+
         if(!tmpDir.mkdirs())
             throw new IOException("Could not create temp directory " + tmpDir);
         if(!docBase.mkdir())
@@ -123,12 +126,20 @@ public class TestNamingContext extends T
 
         // Create a file in each alternate directory that we can attempt to 
access
         FileOutputStream fos = new FileOutputStream(new File(alternate1, 
"test1.txt"));
-        fos.write(foxText.getBytes("UTF-8"));
-        fos.flush(); fos.close();
+        try {
+            fos.write(foxText.getBytes("UTF-8"));
+            fos.flush();
+        } finally {
+            fos.close();
+        }
 
         fos = new FileOutputStream(new File(alternate2, "test2.txt"));
-        fos.write(loremIpsum.getBytes("UTF-8"));
-        fos.flush(); fos.close();
+        try {
+            fos.write(loremIpsum.getBytes("UTF-8"));
+            fos.flush();
+        } finally {
+            fos.close();
+        }
 
         // Finally, create the Context
         FileDirContext ctx = new FileDirContext();
@@ -191,9 +202,6 @@ public class TestNamingContext extends T
         contents = new String(buffer, 0, len, "UTF-8");
 
         assertEquals(loremIpsum, contents);
-
-        // Clean-up
-        addDeleteOnTearDown(tmpDir);
     }
 
     public static final class Bug49994Servlet extends HttpServlet {



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to