summaryrefslogtreecommitdiff
path: root/src/test/java/com/keuin/kbackupfabric
diff options
context:
space:
mode:
authorKeuin <[email protected]>2023-01-13 02:49:57 +0800
committerKeuin <[email protected]>2023-01-13 02:49:57 +0800
commit5dc6e700cbcbc01833a02a193f660a286b934898 (patch)
tree72cf4cc3cfae2b3a7fb978bc0c465e329909db3e /src/test/java/com/keuin/kbackupfabric
parentff7d23b5b915f04c2b5f3614701cb56cfc605228 (diff)
Code cleanup.
Diffstat (limited to 'src/test/java/com/keuin/kbackupfabric')
-rw-r--r--src/test/java/com/keuin/kbackupfabric/backup/incremental/manager/IncrementalBackupStorageManagerTest.java18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/test/java/com/keuin/kbackupfabric/backup/incremental/manager/IncrementalBackupStorageManagerTest.java b/src/test/java/com/keuin/kbackupfabric/backup/incremental/manager/IncrementalBackupStorageManagerTest.java
index 2a9420a..7b2d7f0 100644
--- a/src/test/java/com/keuin/kbackupfabric/backup/incremental/manager/IncrementalBackupStorageManagerTest.java
+++ b/src/test/java/com/keuin/kbackupfabric/backup/incremental/manager/IncrementalBackupStorageManagerTest.java
@@ -18,6 +18,7 @@ import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.*;
+import java.util.stream.Stream;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -71,13 +72,16 @@ public class IncrementalBackupStorageManagerTest {
throw new IllegalArgumentException("negative count");
int[] c = new int[]{0};
Random rnd = new Random();
- Files.walk(new File(srcRoot).toPath(), 1).map(p -> rnd.nextBoolean() ? p : null)
- .filter(Objects::nonNull).forEach(p -> {
- if (c[0]++ != count) {
- if (!p.toFile().delete() && p.toFile().isFile())
- throw new RuntimeException("Failed to delete file " + p);
- }
- });
+ try (Stream<Path> walk = Files.walk(new File(srcRoot).toPath(), 1)) {
+ walk.map(p -> rnd.nextBoolean() ? p : null)
+ .filter(Objects::nonNull)
+ .forEach(p -> {
+ if (c[0]++ != count) {
+ if (!p.toFile().delete() && p.toFile().isFile())
+ throw new RuntimeException("Failed to delete file " + p);
+ }
+ });
+ }
}
private static String getRandomString(int length) {