Ensure that the temporary directory does exist before using it in tests

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1871507 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2019-12-14 13:10:21 +00:00
parent befd31663f
commit 129b8215ce
1 changed files with 19 additions and 12 deletions

View File

@ -43,6 +43,10 @@ public class TestTempFile {
@Before
public void setUp() throws IOException {
previousTempDir = System.getProperty(TempFile.JAVA_IO_TMPDIR);
if(previousTempDir != null) {
assertTrue("Failed to create directory " + previousTempDir,
new File(previousTempDir).exists() || new File(previousTempDir).mkdirs());
}
// use a separate tempdir for the tests to be able to check for leftover files
tempDir = File.createTempFile("TestTempFile", ".tst");
@ -53,6 +57,7 @@ public class TestTempFile {
@After
public void tearDown() throws IOException {
if(tempDir != null) {
String[] files = tempDir.list();
assertNotNull(files);
// can have the "poifiles" subdir
@ -67,6 +72,7 @@ public class TestTempFile {
// remove the directory after the tests
TestPOIFSDump.deleteDirectory(tempDir);
}
if(previousTempDir == null) {
System.clearProperty(TempFile.JAVA_IO_TMPDIR);
@ -141,6 +147,7 @@ public class TestTempFile {
assertTrue(file1.delete());
thrown.expect(IllegalArgumentException.class);
//noinspection ConstantConditions
TempFile.setTempFileCreationStrategy(null);
}
}