This is an automated email from the ASF dual-hosted git repository.

rgoers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/master by this push:
     new 79b1568  test files must only be created in the target directory. 
Copied FileRenameActionTest from release-2.x
79b1568 is described below

commit 79b1568b3c735db74e55323b5c2f5e57ad1b0a5f
Author: Ralph Goers <[email protected]>
AuthorDate: Sun Feb 7 14:37:11 2021 -0700

    test files must only be created in the target directory. Copied 
FileRenameActionTest from release-2.x
---
 .../rolling/action/FileRenameActionTest.java       | 32 ++++++++++++++++++----
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FileRenameActionTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FileRenameActionTest.java
index 3ab9ff8..c9a811d 100644
--- 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FileRenameActionTest.java
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FileRenameActionTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.logging.log4j.core.appender.rolling.action;
 
+import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
 
@@ -27,8 +28,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class FileRenameActionTest {
 
-    @TempDir
-    File tempDir;
+    static File tempDir = new File("./target");
+
+    @AfterEach
+    public void cleanup() {
+        File file = new File(tempDir, "newFile.log");
+        file.delete();
+    }
 
     @Test
     public void testRename1() throws Exception {
@@ -52,12 +58,26 @@ public class FileRenameActionTest {
         try (final PrintStream pos = new PrintStream(file)) {
             // do nothing
         }
-
+        assertTrue(file.exists(), "File to rename does not exist");
         final File dest = new File(tempDir, "newFile.log");
         final FileRenameAction action = new FileRenameAction(file, dest, 
false);
         action.execute();
-        assertFalse(dest.exists(), "Renamed file does not exist");
-        assertFalse(file.exists(), "Old file does not exist");
+        assertFalse(dest.exists(), "Renamed file should not exist");
+        assertFalse(file.exists(), "Old file still exists");
+    }
+
+    @Test
+    public void testRenameEmpty() throws Exception {
+        final File file = new File(tempDir, "fileRename.log");
+        try (final PrintStream pos = new PrintStream(file)) {
+            // do nothing
+        }
+        assertTrue(file.exists(), "File to rename does not exist");
+        final File dest = new File(tempDir, "newFile.log");
+        final FileRenameAction action = new FileRenameAction(file, dest, true);
+        action.execute();
+        assertTrue(dest.exists(), "Renamed file should exist");
+        assertFalse(file.exists(), "Old file still exists");
     }
 
 
@@ -70,7 +90,7 @@ public class FileRenameActionTest {
             }
         }
 
-        final File dest = new File("newFile.log");
+        final File dest = new File(tempDir, "newFile.log");
         final FileRenameAction action = new FileRenameAction(file, dest, 
false);
         action.execute();
         assertTrue(dest.exists(), "Renamed file does not exist");

Reply via email to