Author: kkolinko
Date: Thu Jun  7 12:14:02 2012
New Revision: 1347583

URL: http://svn.apache.org/viewvc?rev=1347583&view=rev
Log:
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/trunk/test/org/apache/naming/resources/TestNamingContext.java

Modified: tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java?rev=1347583&r1=1347582&r2=1347583&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java 
(original)
+++ tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java Thu 
Jun  7 12:14:02 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