mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[log] One more test on hash [de]serialization
This commit is contained in:
@@ -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<HashImpl> 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<HashImpl> readFromFile(@NotNull File file) throws IOException {
|
||||
List<HashImpl> 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user