private void visitPath( Path transactionalLogsPath, Predicate<Path> exclude, ArchiveOutputStream stream ) throws IOException { Files.walkFileTree( transactionalLogsPath, onlyMatching( not( exclude ), throwExceptions( onDirectory( dir -> dumpDirectory( transactionalLogsPath, stream, dir ), onFile( file -> dumpFile( transactionalLogsPath, stream, file ), justContinue() ) ) ) ) ); }
@Test public void shouldNotDelegateVisitFileFailedIfPredicateDoesntMatch() throws IOException { onlyMatching( alwaysFalse(), wrapped).visitFileFailed( null, null ); verify( wrapped, never() ).visitFileFailed( any(), any() ); }
@Test public void shouldNotDelegatePostVisitDirectoryIfPredicateDoesntMatch() throws IOException { onlyMatching( alwaysFalse(), wrapped).postVisitDirectory( null, null ); verify( wrapped, never() ).postVisitDirectory( any(), any() ); }
@Test public void shouldNotDelegatePreVisitDirectoryIfPredicateDoesntMatch() throws IOException { onlyMatching( alwaysFalse(), wrapped).preVisitDirectory( null, null ); verify( wrapped, never() ).preVisitDirectory( any(), any() ); }
@Test public void shouldNotDelegateVisitFileIfPredicateDoesntMatch() throws IOException { onlyMatching( alwaysFalse(), wrapped).visitFile( null, null ); verify( wrapped, never() ).visitFile( any(), any() ); }
@Test public void shouldContinueAfterVisitFileIfPredicateDoesntMatch() throws IOException { assertThat( onlyMatching( alwaysFalse(), wrapped).visitFile( null, null ), is( FileVisitResult.CONTINUE)); }
@Test public void shouldContinueAfterPostVisitDirectoryIfPredicateDoesntMatch() throws IOException { assertThat( onlyMatching( alwaysFalse(), wrapped).postVisitDirectory( null, null ), is( FileVisitResult.CONTINUE)); }
@Test public void shouldNotSkipSubtreeFromPreVisitDirectoryIfPredicateDoesntMatch() throws IOException { assertThat( onlyMatching( alwaysFalse(), wrapped).preVisitDirectory( null, null ), is( FileVisitResult.SKIP_SUBTREE)); }
@Test public void shouldContinueAfterVisitFileFailedIfPredicateDoesntMatch() throws IOException { assertThat( onlyMatching( alwaysFalse(), wrapped).visitFileFailed( null, null ), is( FileVisitResult.CONTINUE)); } }
@Parameterized.Parameters( name = "{0}" ) public static List<Object[]> formats() { return asList( new Object[]{"decorator", (Function<FileVisitor<Path>, FileVisitor<Path>>) FileVisitors.Decorator::new, false }, new Object[]{"onFile", (Function<FileVisitor<Path>, FileVisitor<Path>>) wrapped -> FileVisitors.onFile( noop(), wrapped ), false }, new Object[]{"onDirectory", (Function<FileVisitor<Path>, FileVisitor<Path>>) wrapped -> FileVisitors.onDirectory( noop(), wrapped ), false }, new Object[]{"throwExceptions", (Function<FileVisitor<Path>, FileVisitor<Path>>) FileVisitors::throwExceptions, true }, new Object[]{"onlyMatching", (Function<FileVisitor<Path>, FileVisitor<Path>>) wrapped -> FileVisitors.onlyMatching( Predicates.alwaysTrue(), wrapped ), false } ); }
private void visitPath( Path transactionalLogsPath, Predicate<Path> exclude, ArchiveOutputStream stream ) throws IOException { Files.walkFileTree( transactionalLogsPath, onlyMatching( not( exclude ), throwExceptions( onDirectory( dir -> dumpDirectory( transactionalLogsPath, stream, dir ), onFile( file -> dumpFile( transactionalLogsPath, stream, file ), justContinue() ) ) ) ) ); }