Fix DeterministicKeyChainTest failing on Windows

Git changes line endings in files to CR+LF on Windows by default, while
protobuf always uses LF. That makes serialization tests fail.
This commit is contained in:
Kosta Korenkov
2014-08-17 01:07:55 +07:00
parent 4834fe6eb6
commit e2dbd2a3f7
2 changed files with 13 additions and 3 deletions

View File

@@ -18,9 +18,11 @@
package com.google.bitcoin.core; package com.google.bitcoin.core;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Ordering; import com.google.common.collect.Ordering;
import com.google.common.io.BaseEncoding; import com.google.common.io.BaseEncoding;
import com.google.common.io.Resources;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import com.google.common.primitives.UnsignedLongs; import com.google.common.primitives.UnsignedLongs;
@@ -30,6 +32,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.math.BigInteger; import java.math.BigInteger;
import java.net.URL;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.*; import java.util.*;
@@ -591,4 +594,13 @@ public class Utils {
} }
return maxItem; return maxItem;
} }
/**
* Reads and joins together with LF char (\n) all the lines from given file. It's assumed that file is in UTF-8.
*/
public static String getResourceAsString(URL url) throws IOException {
List<String> lines = Resources.readLines(url, Charsets.UTF_8);
return Joiner.on('\n').join(lines);
}
} }

View File

@@ -23,9 +23,7 @@ import com.google.bitcoin.params.UnitTestParams;
import com.google.bitcoin.store.UnreadableWalletException; import com.google.bitcoin.store.UnreadableWalletException;
import com.google.bitcoin.utils.BriefLogFormatter; import com.google.bitcoin.utils.BriefLogFormatter;
import com.google.bitcoin.utils.Threading; import com.google.bitcoin.utils.Threading;
import com.google.common.base.Charsets;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.io.Resources;
import org.bitcoinj.wallet.Protos; import org.bitcoinj.wallet.Protos;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -310,7 +308,7 @@ public class DeterministicKeyChainTest {
private String checkSerialization(List<Protos.Key> keys, String filename) { private String checkSerialization(List<Protos.Key> keys, String filename) {
try { try {
String sb = protoToString(keys); String sb = protoToString(keys);
String expected = Resources.toString(getClass().getResource(filename), Charsets.UTF_8); String expected = Utils.getResourceAsString(getClass().getResource(filename));
assertEquals(expected, sb); assertEquals(expected, sb);
return expected; return expected;
} catch (IOException e) { } catch (IOException e) {