]> source.dussan.org Git - poi.git/commitdiff
Try to create the temporary directory for ImageIO to see if that makes
authorDominik Stadler <centic@apache.org>
Fri, 16 Nov 2018 11:25:59 +0000 (11:25 +0000)
committerDominik Stadler <centic@apache.org>
Fri, 16 Nov 2018 11:25:59 +0000 (11:25 +0000)
the tests work again when built with Maven

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1846706 13f79535-47bb-0310-9956-ffa450edef68

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

index 5326e759d9314fb58bf65378e3e0f32ba5fff590..df7d7cf213d2ec6a1d60ecb7fbe357fd99933cce 100644 (file)
@@ -19,6 +19,7 @@ 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;
 
@@ -27,6 +28,7 @@ import javax.imageio.ImageIO;
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.junit.BeforeClass;
 
 /**
  * Test <code>HSSFPictureData</code>.
@@ -36,7 +38,19 @@ import org.apache.poi.hssf.HSSFTestDataSamples;
  * @author Trejkaz (trejkaz at trypticon dot org)
  */
 public final class TestHSSFPictureData extends TestCase{
-
+    @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());
+                }
+            }
+        }
+    }
 
        public void testPictures() throws IOException {
         HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithImages.xls");
@@ -64,8 +78,8 @@ public final class TestHSSFPictureData extends TestCase{
                 assertEquals(300, png.getHeight());
                 assertEquals(HSSFWorkbook.PICTURE_TYPE_PNG, pict.getFormat());
                 assertEquals("image/png", pict.getMimeType());
-            } else {
-                //TODO: test code for PICT, WMF and EMF
+            /*} else {
+                //TODO: test code for PICT, WMF and EMF*/
             }
         }
     }
@@ -93,7 +107,7 @@ public final class TestHSSFPictureData extends TestCase{
         assertEquals("image/png", pict.getMimeType());
     }
 
-    public void testNotNullPictures() throws IOException {
+    public void testNotNullPictures() {
 
         HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SheetWithDrawing.xls");
 
@@ -103,5 +117,4 @@ public final class TestHSSFPictureData extends TestCase{
             assertNotNull(pict);
         }
     }
-
 }