From 98a0ac8335910a79987e15864d8d9f4d90981a41 Mon Sep 17 00:00:00 2001 From: Frank Grimes Date: Wed, 20 Nov 2024 10:10:11 -0500 Subject: [PATCH] Improve temp file creation in test suite This is to try to address following errors seen in some GitHub Action Workflow runs on Windows: "Warning: Files with unapproved licenses: force_original.txt" --- .../internal/AllocateDirectWritableMapMemoryTest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java b/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java index a44484cd..fcc9a391 100644 --- a/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java +++ b/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java @@ -127,7 +127,7 @@ public void checkNonNativeFile() public void testMapExceptionNoTWR() throws IllegalArgumentException, InvalidPathException, IllegalStateException, UnsupportedOperationException, IOException, SecurityException { - File dummy = createFile("dummy.txt", ""); //zero length + File dummy = createTempFile("dummy", ".txt" , ""); //zero length try (Arena arena = Arena.ofConfined()) { Memory.map(arena, dummy, 0, dummy.length(), ByteOrder.nativeOrder()); } @@ -161,7 +161,7 @@ public void testForce() throws IllegalArgumentException, InvalidPathException, IllegalStateException, UnsupportedOperationException, IOException, SecurityException { String origStr = "Corectng spellng mistks"; - File origFile = createFile("force_original.txt", origStr); //23 + File origFile = createTempFile("force_original", ".txt", origStr); //23 assertTrue(origFile.setWritable(true, false)); long origBytes = origFile.length(); String correctStr = "Correcting spelling mistakes"; //28 @@ -194,8 +194,9 @@ public void testForce() } } - private static File createFile(String fileName, String text) throws FileNotFoundException { - File file = new File(fileName); + private static File createTempFile(String fileNamePrefix, String fileNameSuffix, String text) + throws FileNotFoundException, IOException { + File file = File.createTempFile(fileNamePrefix, fileNameSuffix); file.deleteOnExit(); PrintWriter writer; try {