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
This commit is contained in:
Dominik Stadler 2018-11-16 11:25:59 +00:00
parent 6a198bf5f2
commit d1642a89a9

View File

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