mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
[bug-69715] add tests removing an old invalid one
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1926424 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c5ca5ae065
commit
c5df00b0a7
@ -20,11 +20,13 @@ package org.apache.poi.util;
|
|||||||
import static org.apache.poi.util.DefaultTempFileCreationStrategy.DELETE_FILES_ON_EXIT;
|
import static org.apache.poi.util.DefaultTempFileCreationStrategy.DELETE_FILES_ON_EXIT;
|
||||||
import static org.apache.poi.util.DefaultTempFileCreationStrategy.POIFILES;
|
import static org.apache.poi.util.DefaultTempFileCreationStrategy.POIFILES;
|
||||||
import static org.apache.poi.util.TempFile.JAVA_IO_TMPDIR;
|
import static org.apache.poi.util.TempFile.JAVA_IO_TMPDIR;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
@ -59,6 +61,42 @@ class DefaultTempFileCreationStrategyTest {
|
|||||||
checkGetFile(strategy);
|
checkGetFile(strategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testProvidedDir() throws IOException {
|
||||||
|
DefaultTempFileCreationStrategy parentStrategy = new DefaultTempFileCreationStrategy();
|
||||||
|
File dir = parentStrategy.createTempDirectory("testProvidedDir");
|
||||||
|
assertNotNull(dir, "Failed to create temp directory");
|
||||||
|
try {
|
||||||
|
assertTrue(Files.isDirectory(dir.toPath()), "File is not a directory: " + dir);
|
||||||
|
DefaultTempFileCreationStrategy testStrategy = new DefaultTempFileCreationStrategy(dir);
|
||||||
|
checkGetFile(testStrategy);
|
||||||
|
} finally {
|
||||||
|
// Clean up the directory after the test
|
||||||
|
FileUtils.deleteDirectory(dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testProvidedDirNotExists() throws IOException {
|
||||||
|
DefaultTempFileCreationStrategy parentStrategy = new DefaultTempFileCreationStrategy();
|
||||||
|
File dir = parentStrategy.createTempDirectory("testProvidedDir");
|
||||||
|
assertNotNull(dir, "Failed to create temp directory");
|
||||||
|
assertTrue(dir.delete(), "directory not deleted: " + dir);
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> new DefaultTempFileCreationStrategy(dir));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testProvidedDirIsActuallyAPlainFile() throws IOException {
|
||||||
|
DefaultTempFileCreationStrategy parentStrategy = new DefaultTempFileCreationStrategy();
|
||||||
|
File dir = parentStrategy.createTempFile("test123", ".tmp");
|
||||||
|
assertNotNull(dir, "Failed to create temp file");
|
||||||
|
try {
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> new DefaultTempFileCreationStrategy(dir));
|
||||||
|
} finally {
|
||||||
|
dir.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void checkGetFile(DefaultTempFileCreationStrategy strategy) throws IOException {
|
private static void checkGetFile(DefaultTempFileCreationStrategy strategy) throws IOException {
|
||||||
File file = strategy.createTempFile("POITest", ".tmp");
|
File file = strategy.createTempFile("POITest", ".tmp");
|
||||||
try {
|
try {
|
||||||
@ -105,19 +143,6 @@ class DefaultTempFileCreationStrategyTest {
|
|||||||
() -> strategy.createTempDirectory("POITest"));
|
() -> strategy.createTempDirectory("POITest"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void testCustomDir() throws IOException {
|
|
||||||
File dirTest = File.createTempFile("POITest", ".dir");
|
|
||||||
try {
|
|
||||||
assertTrue(dirTest.delete());
|
|
||||||
|
|
||||||
DefaultTempFileCreationStrategy strategy = new DefaultTempFileCreationStrategy(dirTest);
|
|
||||||
checkGetFile(strategy);
|
|
||||||
} finally {
|
|
||||||
FileUtils.deleteDirectory(dirTest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCustomDirExists() throws IOException {
|
void testCustomDirExists() throws IOException {
|
||||||
File dirTest = File.createTempFile("POITest", ".dir");
|
File dirTest = File.createTempFile("POITest", ".dir");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user