LOG4J2-435 added method isFollowSymbolicLinks; use Paths.get to create path instances
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/b174519d Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/b174519d Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/b174519d Branch: refs/heads/master Commit: b174519d3b625fe14af96ff4cbcefd461a4a7a45 Parents: 4b9b55e Author: rpopma <[email protected]> Authored: Thu Nov 26 23:46:52 2015 +0900 Committer: rpopma <[email protected]> Committed: Thu Nov 26 23:46:52 2015 +0900 ---------------------------------------------------------------------- .../rolling/action/DeletingVisitorTest.java | 40 ++++++++++---------- 1 file changed, 21 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b174519d/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java index aee976f..d4053d1 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java @@ -18,15 +18,13 @@ package org.apache.logging.log4j.core.appender.rolling.action; import java.io.IOException; -import java.nio.file.FileSystems; import java.nio.file.Path; +import java.nio.file.Paths; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.apache.logging.log4j.core.appender.rolling.action.DeletingVisitor; -import org.apache.logging.log4j.core.appender.rolling.action.PathCondition; import org.junit.Test; import static org.junit.Assert.*; @@ -36,8 +34,8 @@ import static org.junit.Assert.*; */ public class DeletingVisitorTest { /** - * Modifies {@code DeletingVisitor} for testing: - * instead of actually deleting a file, it adds the path to a list for later verification. + * Modifies {@code DeletingVisitor} for testing: instead of actually deleting a file, it adds the path to a list for + * later verification. */ static class DeletingVisitorHelper extends DeletingVisitor { List<Path> deleted = new ArrayList<Path>(); @@ -48,73 +46,77 @@ public class DeletingVisitorTest { @Override protected void delete(final Path file) throws IOException { - deleted.add(file); + deleted.add(file); // overrides and stores path instead of deleting } } @Test public void testAcceptedFilesAreDeleted() throws IOException { - Path base = FileSystems.getDefault().getPath("/a/b/c"); + Path base = Paths.get("/a/b/c"); final FixedCondition ACCEPT_ALL = new FixedCondition(true); DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Arrays.asList(ACCEPT_ALL)); - Path any = FileSystems.getDefault().getPath("/a/b/c/any"); + Path any = Paths.get("/a/b/c/any"); visitor.visitFile(any, null); assertTrue(visitor.deleted.contains(any)); } @Test public void testRejectedFilesAreNotDeleted() throws IOException { - Path base = FileSystems.getDefault().getPath("/a/b/c"); + Path base = Paths.get("/a/b/c"); final FixedCondition REJECT_ALL = new FixedCondition(false); DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Arrays.asList(REJECT_ALL)); - Path any = FileSystems.getDefault().getPath("/a/b/c/any"); + Path any = Paths.get("/a/b/c/any"); visitor.visitFile(any, null); assertFalse(visitor.deleted.contains(any)); } @Test public void testAllFiltersMustAcceptOrFileIsNotDeleted() throws IOException { - Path base = FileSystems.getDefault().getPath("/a/b/c"); + Path base = Paths.get("/a/b/c"); final FixedCondition ACCEPT_ALL = new FixedCondition(true); final FixedCondition REJECT_ALL = new FixedCondition(false); List<? extends PathCondition> filters = Arrays.asList(ACCEPT_ALL, ACCEPT_ALL, REJECT_ALL); DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, filters); - Path any = FileSystems.getDefault().getPath("/a/b/c/any"); + Path any = Paths.get("/a/b/c/any"); visitor.visitFile(any, null); assertFalse(visitor.deleted.contains(any)); } @Test public void testIfAllFiltersAcceptFileIsDeleted() throws IOException { - Path base = FileSystems.getDefault().getPath("/a/b/c"); + Path base = Paths.get("/a/b/c"); final FixedCondition ACCEPT_ALL = new FixedCondition(true); List<? extends PathCondition> filters = Arrays.asList(ACCEPT_ALL, ACCEPT_ALL, ACCEPT_ALL); DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, filters); - Path any = FileSystems.getDefault().getPath("/a/b/c/any"); + Path any = Paths.get("/a/b/c/any"); visitor.visitFile(any, null); assertTrue(visitor.deleted.contains(any)); } @Test public void testVisitFileRelativizesAgainstBase() throws IOException { - + PathCondition filter = new PathCondition() { - + @Override public boolean accept(Path baseDir, Path relativePath, BasicFileAttributes attrs) { - Path expected = FileSystems.getDefault().getPath("relative"); + Path expected = Paths.get("relative"); assertEquals(expected, relativePath); return true; } + + @Override + public void beforeFileTreeWalk() { + } }; - Path base = FileSystems.getDefault().getPath("/a/b/c"); + Path base = Paths.get("/a/b/c"); DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Arrays.asList(filter)); - Path child = FileSystems.getDefault().getPath("/a/b/c/relative"); + Path child = Paths.get("/a/b/c/relative"); visitor.visitFile(child, null); } }
