diff options
Diffstat (limited to 'src/test/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethodTest.java')
-rw-r--r-- | src/test/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethodTest.java | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/test/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethodTest.java b/src/test/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethodTest.java index 0928c9e..0741004 100644 --- a/src/test/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethodTest.java +++ b/src/test/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethodTest.java @@ -17,6 +17,7 @@ import java.time.LocalDateTime; import java.util.*; import java.util.function.Function; import java.util.logging.Logger; +import java.util.stream.Stream; import static org.apache.commons.io.FileUtils.forceDelete; import static org.junit.Assert.*; @@ -135,13 +136,15 @@ public class ConfiguredIncrementalBackupMethodTest { int[] success = new int[1]; if (fake) { - Files.walk(sourcePath).filter(path -> path.toFile().isFile()).limit(4).forEach(path -> { - System.out.println("Deleted file `" + path.toFile().getName() + "`."); - if (!path.toFile().delete()) - fail(); - if (!Objects.equals(path.toFile().getName(), BackupMetadata.metadataFileName)) - success[0]++; - }); + try (Stream<Path> walk = Files.walk(sourcePath)) { + walk.filter(path -> path.toFile().isFile()).limit(4).forEach(path -> { + System.out.println("Deleted file `" + path.toFile().getName() + "`."); + if (!path.toFile().delete()) + fail(); + if (!Objects.equals(path.toFile().getName(), BackupMetadata.metadataFileName)) + success[0]++; + }); + } if (success[0] == 0) fake = false; } @@ -244,12 +247,11 @@ public class ConfiguredIncrementalBackupMethodTest { Set<String> ignoredFiles) { File[] fileList = dir.listFiles(); - Arrays.sort(fileList, // Need in reproducible order - new Comparator<File>() { - public int compare(File f1, File f2) { - return f1.getName().compareTo(f2.getName()); - } - }); + if (fileList == null) { + throw new RuntimeException("Failed to list files in directory " + dir); + } + // Need in reproducible order + Arrays.sort(fileList, Comparator.comparing(File::getName)); for (File f : fileList) { if (!includeHiddenFiles && f.getName().startsWith(".") || |