From 8e67084b86e076bd95b452acf528f0642fa66c80 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 13 Nov 2014 16:17:26 +0300 Subject: [PATCH] [log] One more test on hash [de]serialization --- .../vcs/log/impl/HashSerializeTest.java | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/platform/vcs-log/impl/test/com/intellij/vcs/log/impl/HashSerializeTest.java b/platform/vcs-log/impl/test/com/intellij/vcs/log/impl/HashSerializeTest.java index af8c703e1811..7ce352c05f04 100644 --- a/platform/vcs-log/impl/test/com/intellij/vcs/log/impl/HashSerializeTest.java +++ b/platform/vcs-log/impl/test/com/intellij/vcs/log/impl/HashSerializeTest.java @@ -16,11 +16,14 @@ package com.intellij.vcs.log.impl; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.io.DataOutputStream; import org.jetbrains.annotations.NotNull; import org.junit.Test; import java.io.*; +import java.util.Arrays; +import java.util.List; import static org.junit.Assert.assertEquals; @@ -30,7 +33,7 @@ public class HashSerializeTest { public void full_hash() throws IOException { HashImpl hash = (HashImpl)HashImpl.build("d35ee91fad4a04bce0ea91a762cc8f3bf3e1929f"); File file = writeToTempFile(hash); - HashImpl newHash = readFromFile(file); + HashImpl newHash = readFromFile(file).get(0); assertEquals(hash, newHash); } @@ -38,16 +41,28 @@ public class HashSerializeTest { public void short_hash() throws IOException { HashImpl hash = (HashImpl)HashImpl.build("d35ee91"); File file = writeToTempFile(hash); - HashImpl newHash = readFromFile(file); + HashImpl newHash = readFromFile(file).get(0); assertEquals(hash, newHash); } + + @Test + public void two_different_hashes() throws IOException { + HashImpl hash1 = (HashImpl)HashImpl.build("d35ee91"); + HashImpl hash2 = (HashImpl)HashImpl.build("d35ee91fad4a04bce0ea91a762cc8f3bf3e1929f"); + File file = writeToTempFile(hash1, hash2); + List hashes = readFromFile(file); + assertEquals(Arrays.asList(hash1, hash2), hashes); + + } @NotNull - private static File writeToTempFile(@NotNull HashImpl hash) throws IOException { + private static File writeToTempFile(@NotNull HashImpl... hashes) throws IOException { File file = FileUtil.createTempFile("", ""); DataOutputStream out = new DataOutputStream(new FileOutputStream(file)); try { - hash.write(out); + for (HashImpl hash : hashes) { + hash.write(out); + } } finally { out.close(); @@ -56,15 +71,17 @@ public class HashSerializeTest { } @NotNull - private static HashImpl readFromFile(@NotNull File file) throws IOException { - HashImpl newHash; + private static List readFromFile(@NotNull File file) throws IOException { + List result = ContainerUtil.newArrayList(); DataInputStream in = new DataInputStream(new FileInputStream(file)); try { - newHash = (HashImpl)HashImpl.read(in); + while (in.available() > 0) { + result.add((HashImpl)HashImpl.read(in)); + } } finally { in.close(); } - return newHash; + return result; } }