diff options
author | Keuin <[email protected]> | 2021-01-12 16:54:03 +0800 |
---|---|---|
committer | keuin <[email protected]> | 2021-01-12 16:54:03 +0800 |
commit | f4d926c1eb91749a4b0f89c7a35538821ff7e21b (patch) | |
tree | 32890a856dfe67f80762000793d6140d43dd1795 /src/test/java/com/keuin | |
parent | 4a52f5e6ce06cb6717510c6a975d5490be627c98 (diff) |
Add serialization and deserialization for ObjectCollection
Diffstat (limited to 'src/test/java/com/keuin')
2 files changed, 29 insertions, 1 deletions
diff --git a/src/test/java/com/keuin/kbackupfabric/util/backup/incremental/ObjectCollectionFactoryTest.java b/src/test/java/com/keuin/kbackupfabric/util/backup/incremental/ObjectCollectionFactoryTest.java index 60a42cf..b7e0aad 100644 --- a/src/test/java/com/keuin/kbackupfabric/util/backup/incremental/ObjectCollectionFactoryTest.java +++ b/src/test/java/com/keuin/kbackupfabric/util/backup/incremental/ObjectCollectionFactoryTest.java @@ -72,7 +72,6 @@ public class ObjectCollectionFactoryTest { // check `12` validate(collection.getSubCollectionMap().get("1").getSubCollectionMap().get("12"), Collections.emptyList(), Collections.emptyMap()); - } catch (IOException e) { e.printStackTrace(); fail(); diff --git a/src/test/java/com/keuin/kbackupfabric/util/backup/incremental/ObjectCollectionSerializerTest.java b/src/test/java/com/keuin/kbackupfabric/util/backup/incremental/ObjectCollectionSerializerTest.java new file mode 100644 index 0000000..0edfe01 --- /dev/null +++ b/src/test/java/com/keuin/kbackupfabric/util/backup/incremental/ObjectCollectionSerializerTest.java @@ -0,0 +1,29 @@ +package com.keuin.kbackupfabric.util.backup.incremental; + +import com.keuin.kbackupfabric.util.backup.incremental.identifier.Sha256Identifier; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; + +import static org.junit.Assert.assertEquals; + +public class ObjectCollectionSerializerTest { + @Test + public void testSerializationConsistency() throws IOException { + ObjectCollectionFactory<Sha256Identifier> factory = + new ObjectCollectionFactory<>(Sha256Identifier.getFactory()); + ObjectCollection collection = + factory.fromDirectory(new File("./testfile/ObjectCollectionFactoryTest")); + File file = new File("./testfile/serialized"); + if (file.exists()) { + Files.delete(file.toPath()); + } + ObjectCollectionSerializer.toFile(collection, file); + ObjectCollection collection2 = ObjectCollectionSerializer.fromFile(file); + Files.delete(file.toPath()); + assertEquals(collection, collection2); + } + +}
\ No newline at end of file |