diff options
Diffstat (limited to 'src/test/java/com/keuin/kbackupfabric/backup')
2 files changed, 28 insertions, 9 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) { diff --git a/src/test/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBakupBackwardCompatibilityTest.java b/src/test/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBakupBackwardCompatibilityTest.java index 3de75b9..fc72e9a 100644 --- a/src/test/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBakupBackwardCompatibilityTest.java +++ b/src/test/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBakupBackwardCompatibilityTest.java @@ -1,10 +1,14 @@ package com.keuin.kbackupfabric.backup.incremental.serializer; +import com.keuin.kbackupfabric.TestUtils; import com.keuin.kbackupfabric.backup.incremental.ObjectCollection2; import com.keuin.kbackupfabric.backup.incremental.ObjectCollectionFactory; import com.keuin.kbackupfabric.backup.incremental.ObjectCollectionSerializer; import com.keuin.kbackupfabric.backup.incremental.identifier.Sha256Identifier; import com.keuin.kbackupfabric.backup.name.IncrementalBackupFileNameEncoder; +import org.apache.commons.io.FileUtils; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import java.io.File; @@ -21,8 +25,19 @@ public class IncBakupBackwardCompatibilityTest { private final String customName = "test_backup"; private final LocalDateTime backupTime = LocalDateTime.of(2000, 1, 1, 1, 1, 1, 1); - private final Path testRoot = Paths.get(".\\testfile\\IncBackupBackwardCompatibilityTest"); - private final File indexFile = new File(testRoot.toString(), IncrementalBackupFileNameEncoder.INSTANCE.encode(customName, backupTime)); + private Path testRoot; + private File indexFile; + + @Before + public void setUp() throws IOException { + testRoot = Paths.get(TestUtils.getTempDirectory("IncBackupBackwardCompatibilityTest")); + indexFile = new File(testRoot.toString(), IncrementalBackupFileNameEncoder.INSTANCE.encode(customName, backupTime)); + } + + @After + public void tearDown() throws IOException { + FileUtils.deleteDirectory(new File(testRoot.toString())); + } @Test public void testBackwardCompatibility() throws IOException { |