From b8eeb720448ec8fbeb77495f42573bfa56d4b36a Mon Sep 17 00:00:00 2001 From: str4d Date: Sat, 2 Dec 2017 17:42:59 +0000 Subject: [PATCH] Fix net.i2p.data.*Key tests, remove dead code Broken in 463f5347b682f23a159bdeb06ffc8f55c5c2cff7 by an underlying API change. The dead code threw the previously-expected exception. --- core/java/src/net/i2p/data/SimpleDataStructure.java | 6 ++---- core/java/test/junit/net/i2p/data/PrivateKeyTest.java | 5 +++-- core/java/test/junit/net/i2p/data/PublicKeyTest.java | 5 +++-- .../java/test/junit/net/i2p/data/SigningPrivateKeyTest.java | 5 +++-- core/java/test/junit/net/i2p/data/SigningPublicKeyTest.java | 5 +++-- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/core/java/src/net/i2p/data/SimpleDataStructure.java b/core/java/src/net/i2p/data/SimpleDataStructure.java index 3983be17d..707253fc3 100644 --- a/core/java/src/net/i2p/data/SimpleDataStructure.java +++ b/core/java/src/net/i2p/data/SimpleDataStructure.java @@ -80,10 +80,8 @@ public abstract class SimpleDataStructure extends DataStructureImpl { throw new RuntimeException("Data already set"); int length = length(); _data = new byte[length]; - int read = read(in, _data); - if (read != length) - throw new DataFormatException("EOF reading " + getClass().getSimpleName() + - ", read: " + read + ", required: " + length); + // Throws on incomplete read + read(in, _data); } public void writeBytes(OutputStream out) throws DataFormatException, IOException { diff --git a/core/java/test/junit/net/i2p/data/PrivateKeyTest.java b/core/java/test/junit/net/i2p/data/PrivateKeyTest.java index 53a6d89af..d882920a0 100644 --- a/core/java/test/junit/net/i2p/data/PrivateKeyTest.java +++ b/core/java/test/junit/net/i2p/data/PrivateKeyTest.java @@ -12,6 +12,7 @@ import static org.junit.Assert.*; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.EOFException; import org.junit.Rule; import org.junit.Test; @@ -87,8 +88,8 @@ public class PrivateKeyTest extends StructureTest { PrivateKey privateKey = new PrivateKey(); ByteArrayInputStream in = new ByteArrayInputStream(DataHelper.getASCII("six times nine equals forty-two")); - exception.expect(DataFormatException.class); - exception.expectMessage("EOF reading PrivateKey, read: 31, required: " + PrivateKey.KEYSIZE_BYTES); + exception.expect(EOFException.class); + exception.expectMessage("EOF after reading 31 bytes of " + PrivateKey.KEYSIZE_BYTES + " byte value"); privateKey.readBytes(in); } } diff --git a/core/java/test/junit/net/i2p/data/PublicKeyTest.java b/core/java/test/junit/net/i2p/data/PublicKeyTest.java index 9115aacc2..2a4ece3ca 100644 --- a/core/java/test/junit/net/i2p/data/PublicKeyTest.java +++ b/core/java/test/junit/net/i2p/data/PublicKeyTest.java @@ -12,6 +12,7 @@ import static org.junit.Assert.*; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.EOFException; import org.junit.Rule; import org.junit.Test; @@ -88,8 +89,8 @@ public class PublicKeyTest extends StructureTest { PublicKey publicKey = new PublicKey(); ByteArrayInputStream in = new ByteArrayInputStream(DataHelper.getASCII("six times nine equals forty-two")); - exception.expect(DataFormatException.class); - exception.expectMessage("EOF reading PublicKey, read: 31, required: " + PublicKey.KEYSIZE_BYTES); + exception.expect(EOFException.class); + exception.expectMessage("EOF after reading 31 bytes of " + PublicKey.KEYSIZE_BYTES + " byte value"); publicKey.readBytes(in); } } diff --git a/core/java/test/junit/net/i2p/data/SigningPrivateKeyTest.java b/core/java/test/junit/net/i2p/data/SigningPrivateKeyTest.java index c40cf725d..aeece36e1 100644 --- a/core/java/test/junit/net/i2p/data/SigningPrivateKeyTest.java +++ b/core/java/test/junit/net/i2p/data/SigningPrivateKeyTest.java @@ -12,6 +12,7 @@ import static org.junit.Assert.*; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.EOFException; import org.junit.Rule; import org.junit.Test; @@ -88,8 +89,8 @@ public class SigningPrivateKeyTest extends StructureTest { SigningPrivateKey signingPrivateKey = new SigningPrivateKey(); ByteArrayInputStream in = new ByteArrayInputStream(DataHelper.getASCII("short")); - exception.expect(DataFormatException.class); - exception.expectMessage("EOF reading SigningPrivateKey, read: 5, required: " + SigningPrivateKey.KEYSIZE_BYTES); + exception.expect(EOFException.class); + exception.expectMessage("EOF after reading 5 bytes of " + SigningPrivateKey.KEYSIZE_BYTES + " byte value"); signingPrivateKey.readBytes(in); } } diff --git a/core/java/test/junit/net/i2p/data/SigningPublicKeyTest.java b/core/java/test/junit/net/i2p/data/SigningPublicKeyTest.java index 6398b4a86..825543d68 100644 --- a/core/java/test/junit/net/i2p/data/SigningPublicKeyTest.java +++ b/core/java/test/junit/net/i2p/data/SigningPublicKeyTest.java @@ -12,6 +12,7 @@ import static org.junit.Assert.*; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.EOFException; import org.junit.Rule; import org.junit.Test; @@ -88,8 +89,8 @@ public class SigningPublicKeyTest extends StructureTest { SigningPublicKey publicKey = new SigningPublicKey(); ByteArrayInputStream in = new ByteArrayInputStream(DataHelper.getASCII("six times nine equals forty-two")); - exception.expect(DataFormatException.class); - exception.expectMessage("EOF reading SigningPublicKey, read: 31, required: " + SigningPublicKey.KEYSIZE_BYTES); + exception.expect(EOFException.class); + exception.expectMessage("EOF after reading 31 bytes of " + SigningPublicKey.KEYSIZE_BYTES + " byte value"); publicKey.readBytes(in); } }