From 03abb9edf410f0b6b199127f950209e63ae03161 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Fri, 16 Nov 2018 11:25:59 +0000 Subject: [PATCH] Try to create the temporary directory for ImageIO to see if that makes 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 --- .../hssf/usermodel/TestHSSFPictureData.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java index 5326e759d9..df7d7cf213 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java @@ -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 HSSFPictureData. @@ -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); } } - } -- 2.39.5