directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1706838 - in /directory/shared/trunk: ldap/model/src/test/java/org/apache/directory/api/ldap/model/ldif/LdifAttributesReaderTest.java util/src/test/java/org/apache/directory/api/util/UnicodeTest.java
Date Mon, 05 Oct 2015 13:37:53 GMT
Author: elecharny
Date: Mon Oct  5 13:37:53 2015
New Revision: 1706838

URL: http://svn.apache.org/viewvc?rev=1706838&view=rev
Log:
Used the Junit temporary folders (DIRAPI-115)

Modified:
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/ldif/LdifAttributesReaderTest.java
    directory/shared/trunk/util/src/test/java/org/apache/directory/api/util/UnicodeTest.java

Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/ldif/LdifAttributesReaderTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/ldif/LdifAttributesReaderTest.java?rev=1706838&r1=1706837&r2=1706838&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/ldif/LdifAttributesReaderTest.java
(original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/ldif/LdifAttributesReaderTest.java
Mon Oct  5 13:37:53 2015
@@ -44,7 +44,9 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.ldif.LdifAttributesReader;
 import org.apache.directory.api.util.Strings;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
 import org.junit.runner.RunWith;
 
 import com.mycila.junit.concurrent.Concurrency;
@@ -58,6 +60,10 @@ import com.mycila.junit.concurrent.Concu
 @Concurrency()
 public class LdifAttributesReaderTest
 {
+    /** Uses a temporary folder rule */
+    @Rule 
+    public TemporaryFolder tmpFolder= new TemporaryFolder();
+
     private byte[] data;
 
     private File HJENSEN_JPEG_FILE = null;
@@ -65,19 +71,13 @@ public class LdifAttributesReaderTest
 
     private File createFile( String name, byte[] data ) throws IOException
     {
-        File jpeg = File.createTempFile( name, "jpg" );
-
-        jpeg.createNewFile();
+        File jpeg = tmpFolder.newFile( name + ".jpg" );
 
         DataOutputStream os = new DataOutputStream( new FileOutputStream( jpeg ) );
 
         os.write( data );
         os.close();
 
-        // This file will be deleted when the JVM
-        // will exit.
-        jpeg.deleteOnExit();
-
         return jpeg;
     }
 

Modified: directory/shared/trunk/util/src/test/java/org/apache/directory/api/util/UnicodeTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/util/src/test/java/org/apache/directory/api/util/UnicodeTest.java?rev=1706838&r1=1706837&r2=1706838&view=diff
==============================================================================
--- directory/shared/trunk/util/src/test/java/org/apache/directory/api/util/UnicodeTest.java
(original)
+++ directory/shared/trunk/util/src/test/java/org/apache/directory/api/util/UnicodeTest.java
Mon Oct  5 13:37:53 2015
@@ -33,7 +33,11 @@ import java.util.Arrays;
 import com.mycila.junit.concurrent.Concurrency;
 import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
 import org.junit.runner.RunWith;
 
 
@@ -46,27 +50,46 @@ import org.junit.runner.RunWith;
 @Concurrency()
 public class UnicodeTest
 {
+    /** Uses a temporary folder rule */
+    @Rule 
+    public TemporaryFolder tmpFolder= new TemporaryFolder();
 
+    /** The file stream we use for this test */
     private FileOutputStream fos = null;
     private FileInputStream fis = null;
 
 
     /**
-     * 
-     * Creates a new instance of UnicodeTest.
-     *
+     * Initialize the temporary folder and the associated streams
      */
-    public UnicodeTest()
+    @Before
+    public void init()
     {
         try
         {
-            File tmpFile = File.createTempFile( "UTFUtils", "test" );
-            tmpFile.deleteOnExit();
+            File tmpFile = tmpFolder.newFile( "UTFUtils.test" );
             fos = new FileOutputStream( tmpFile );
             fis = new FileInputStream( tmpFile );
         }
         catch ( IOException e )
         {
+        }
+    }
+    
+    
+    /**
+     * Cleanup the streams after each test
+     */
+    @After
+    public void reset()
+    {
+        try
+        {
+            fos.close();
+            fis.close();
+        }
+        catch ( IOException e )
+        {
         }
     }
 



Mime
View raw message