]> source.dussan.org Git - poi.git/commitdiff
One more try to avoid the test-failures related to ImageIO-cache dir
authorDominik Stadler <centic@apache.org>
Fri, 16 Nov 2018 15:08:59 +0000 (15:08 +0000)
committerDominik Stadler <centic@apache.org>
Fri, 16 Nov 2018 15:08:59 +0000 (15:08 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1846719 13f79535-47bb-0310-9956-ffa450edef68

src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java

index df7d7cf213d2ec6a1d60ecb7fbe357fd99933cce..d82423b86e1e2387a13fb322eeed8e31d96f3e7b 100644 (file)
@@ -19,7 +19,6 @@ package org.apache.poi.hssf.usermodel;
 
 import java.awt.image.BufferedImage;
 import java.io.ByteArrayInputStream;
-import java.io.File;
 import java.io.IOException;
 import java.util.List;
 
@@ -28,6 +27,7 @@ import javax.imageio.ImageIO;
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 
 /**
@@ -37,19 +37,19 @@ import org.junit.BeforeClass;
  * @author Yegor Kozlov (yegor at apache dot org)
  * @author Trejkaz (trejkaz at trypticon dot org)
  */
-public final class TestHSSFPictureData extends TestCase{
+public final class TestHSSFPictureData extends TestCase {
+    private static boolean cacheBefore = ImageIO.getUseCache();
+
     @BeforeClass
     public static void setUpClass() {
-        // ensure that temp-dir exists because ImageIO requires it
-        String tmpDirProperty = System.getProperty("java.io.tmpdir");
-        if(tmpDirProperty != null) {
-            final File tmpDir = new File(tmpDirProperty);
-            if(!tmpDir.exists()) {
-                if(!tmpDir.mkdirs()) {
-                    throw new IllegalStateException("Could not create temporary directory " + tmpDirProperty + ", full path " + tmpDir.getAbsolutePath());
-                }
-            }
-        }
+        // disable cache to avoid strange errors related to temporary directories in CI-builds
+        ImageIO.setUseCache(false);
+    }
+
+    @AfterClass
+    public static void tearDownClass() {
+        // reset image cache to previous state
+        ImageIO.setUseCache(cacheBefore);
     }
 
        public void testPictures() throws IOException {