Modernize and secure temp file creation

This commit is contained in:
pixeebot[bot] 2025-07-24 12:44:47 +00:00 committed by GitHub
parent d8e1c693da
commit f0b1cb11d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,6 @@
package stirling.software.common.util; package stirling.software.common.util;
import java.nio.file.Files;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
@ -47,8 +48,8 @@ public class FileToPdfTest {
// Mock the temp file creation to return real temp files // Mock the temp file creation to return real temp files
try { try {
when(tempFileManager.createTempFile(anyString())) when(tempFileManager.createTempFile(anyString()))
.thenReturn(File.createTempFile("test", ".pdf")) .thenReturn(Files.createTempFile("test", ".pdf").toFile())
.thenReturn(File.createTempFile("test", ".html")); .thenReturn(Files.createTempFile("test", ".html").toFile());
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }