You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2020/02/20 00:34:03 UTC

[logging-log4j2] branch release-2.x updated: Fix unit test - Java doesn't close streams automatically

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

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


The following commit(s) were added to refs/heads/release-2.x by this push:
     new 1f7381c  Fix unit test - Java doesn't close streams automatically
1f7381c is described below

commit 1f7381c563708029226360d79a2d99240b6587e2
Author: Ralph Goers <Ra...@dslextreme.com>
AuthorDate: Wed Feb 19 17:33:45 2020 -0700

    Fix unit test - Java doesn't close streams automatically
---
 .../core/appender/rolling/RollingAppenderOnStartupTest.java      | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderOnStartupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderOnStartupTest.java
index e15c621..7e498cd 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderOnStartupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderOnStartupTest.java
@@ -32,6 +32,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.junit.LoggerContextRule;
@@ -94,11 +95,11 @@ public class RollingAppenderOnStartupTest {
                 if (!path.toFile().getName().endsWith(FILENAME)) {
                     rolled = true;
                 }
-                List<String> lines = Files.lines(path).collect(Collectors.toList());
-                assertTrue("No header present for " + path.toFile().getName(), lines.get(0).startsWith("<!DOCTYPE HTML"));
+                try (Stream<String> stream = Files.lines(path)) {
+                    List<String> lines = stream.collect(Collectors.toList());
+                    assertTrue("No header present for " + path.toFile().getName(), lines.get(0).startsWith("<!DOCTYPE HTML"));
+                }
                 Files.delete(path);
-                System.out.println(path.toFile().toString() + " was deleted");
-                System.out.println(path.toFile().toString() + (path.toFile().exists() ? " exists" : " does not exist"));
             }
             assertTrue("File did not roll", rolled);
         }