diff --git a/core/java/test/junit/net/i2p/client/naming/SingleFileNamingServiceTest.java b/core/java/test/junit/net/i2p/client/naming/SingleFileNamingServiceTest.java index 9d4dcbf9ecdbcedce4c4ea1386ede5d57560ef91..8268127a2d7989965502d81b51811b4ae0da46e2 100644 --- a/core/java/test/junit/net/i2p/client/naming/SingleFileNamingServiceTest.java +++ b/core/java/test/junit/net/i2p/client/naming/SingleFileNamingServiceTest.java @@ -1,8 +1,8 @@ package net.i2p.client.naming; import junit.framework.TestCase; -import static org.junit.Assert.*; import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; import java.io.File; import java.util.Collections; diff --git a/core/java/test/junit/net/i2p/crypto/eddsa/EdDSAEngineTest.java b/core/java/test/junit/net/i2p/crypto/eddsa/EdDSAEngineTest.java index e392818389d078ccc4c759f8e080e8792e34c7a3..bcb80d3239e8b115ace2c00ec0d10e06fdd28a0f 100644 --- a/core/java/test/junit/net/i2p/crypto/eddsa/EdDSAEngineTest.java +++ b/core/java/test/junit/net/i2p/crypto/eddsa/EdDSAEngineTest.java @@ -13,7 +13,9 @@ package net.i2p.crypto.eddsa; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; import java.nio.charset.Charset; import java.security.MessageDigest; @@ -27,9 +29,7 @@ import net.i2p.crypto.eddsa.spec.EdDSAParameterSpec; import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec; import net.i2p.crypto.eddsa.spec.EdDSAPublicKeySpec; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; /** * @author str4d @@ -41,9 +41,6 @@ public class EdDSAEngineTest { static final byte[] TEST_MSG = "This is a secret message".getBytes(Charset.forName("UTF-8")); static final byte[] TEST_MSG_SIG = Utils.hexToBytes("94825896c7075c31bcb81f06dba2bdcd9dcf16e79288d4b9f87c248215c8468d475f429f3de3b4a2cf67fe17077ae19686020364d6d4fa7a0174bab4a123ba0f"); - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void testSign() throws Exception { EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.ED_25519); @@ -93,9 +90,11 @@ public class EdDSAEngineTest { sgr.update(TEST_MSG); - exception.expect(SignatureException.class); - exception.expectMessage("signature length is wrong"); - sgr.verify(new byte[] {0}); + try { + sgr.verify(new byte[]{0}); + } catch (SignatureException expected) { + assertEquals("signature length is wrong", expected.getMessage()); + } } @Test @@ -171,9 +170,12 @@ public class EdDSAEngineTest { sgr.update(TEST_MSG); - exception.expect(SignatureException.class); - exception.expectMessage("update() already called"); - sgr.update(TEST_MSG); + try { + sgr.update(TEST_MSG); + fail("exception not thrown"); + } catch (SignatureException expected) { + assertEquals("update() already called", expected.getMessage()); + } } @Test @@ -187,9 +189,12 @@ public class EdDSAEngineTest { sgr.update(TEST_MSG); - exception.expect(SignatureException.class); - exception.expectMessage("update() already called"); - sgr.update(TEST_MSG); + try { + sgr.update(TEST_MSG); + fail("exception not thrown"); + } catch (SignatureException expected) { + assertEquals("update() already called", expected.getMessage()); + } } @Test diff --git a/core/java/test/junit/net/i2p/crypto/eddsa/UtilsTest.java b/core/java/test/junit/net/i2p/crypto/eddsa/UtilsTest.java index e04cf1d312a5442fa87ceff872f1d3da1241a5bd..d90e94fff0f0cb09b8f97b7381fc938933c037d0 100644 --- a/core/java/test/junit/net/i2p/crypto/eddsa/UtilsTest.java +++ b/core/java/test/junit/net/i2p/crypto/eddsa/UtilsTest.java @@ -16,8 +16,8 @@ import org.junit.*; import java.security.SecureRandom; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; /** * @author str4d @@ -58,7 +58,7 @@ public class UtilsTest { for (int i=0; i<100; i++) { random.nextBytes(bytes1); System.arraycopy(bytes1, 0, bytes2, 0, 32); - Assert.assertThat(Utils.equal(bytes1, bytes2), IsEqual.equalTo(1)); + assertThat(Utils.equal(bytes1, bytes2), IsEqual.equalTo(1)); } } @@ -71,7 +71,7 @@ public class UtilsTest { for (int i=0; i<32; i++) { System.arraycopy(bytes1, 0, bytes2, 0, 32); bytes2[i] = (byte)(bytes2[i] ^ 0xff); - Assert.assertThat(Utils.equal(bytes1, bytes2), IsEqual.equalTo(0)); + assertThat(Utils.equal(bytes1, bytes2), IsEqual.equalTo(0)); } } @@ -123,15 +123,15 @@ public class UtilsTest { @Test public void hexToBytesReturnsCorrectByteArray() { - Assert.assertThat(Utils.hexToBytes(hex1), IsEqual.equalTo(bytes1)); - Assert.assertThat(Utils.hexToBytes(hex2), IsEqual.equalTo(bytes2)); - Assert.assertThat(Utils.hexToBytes(hex3), IsEqual.equalTo(bytes3)); + assertThat(Utils.hexToBytes(hex1), IsEqual.equalTo(bytes1)); + assertThat(Utils.hexToBytes(hex2), IsEqual.equalTo(bytes2)); + assertThat(Utils.hexToBytes(hex3), IsEqual.equalTo(bytes3)); } @Test public void bytesToHexReturnsCorrectHexString() { - Assert.assertThat(Utils.bytesToHex(bytes1), IsEqual.equalTo(hex1)); - Assert.assertThat(Utils.bytesToHex(bytes2), IsEqual.equalTo(hex2)); - Assert.assertThat(Utils.bytesToHex(bytes3), IsEqual.equalTo(hex3)); + assertThat(Utils.bytesToHex(bytes1), IsEqual.equalTo(hex1)); + assertThat(Utils.bytesToHex(bytes2), IsEqual.equalTo(hex2)); + assertThat(Utils.bytesToHex(bytes3), IsEqual.equalTo(hex3)); } } diff --git a/core/java/test/junit/net/i2p/crypto/eddsa/math/AbstractFieldElementTest.java b/core/java/test/junit/net/i2p/crypto/eddsa/math/AbstractFieldElementTest.java index 091afa04ea4d21cc3481112f6ac285d27040349e..91496b8e6ae124b9f93d1523b74aee472a88974c 100644 --- a/core/java/test/junit/net/i2p/crypto/eddsa/math/AbstractFieldElementTest.java +++ b/core/java/test/junit/net/i2p/crypto/eddsa/math/AbstractFieldElementTest.java @@ -14,6 +14,8 @@ package net.i2p.crypto.eddsa.math; import org.hamcrest.core.*; import org.junit.*; +import static org.hamcrest.MatcherAssert.assertThat; + import java.math.BigInteger; /** @@ -37,7 +39,7 @@ public abstract class AbstractFieldElementTest { final FieldElement f = getZeroFieldElement(); // Assert: - Assert.assertThat(f.isNonZero(), IsEqual.equalTo(false)); + assertThat(f.isNonZero(), IsEqual.equalTo(false)); } @Test @@ -46,7 +48,7 @@ public abstract class AbstractFieldElementTest { final FieldElement f = getNonZeroFieldElement(); // Assert: - Assert.assertThat(f.isNonZero(), IsEqual.equalTo(true)); + assertThat(f.isNonZero(), IsEqual.equalTo(true)); } // endregion @@ -67,7 +69,7 @@ public abstract class AbstractFieldElementTest { final BigInteger b3 = toBigInteger(f3).mod(getQ()); // Assert: - Assert.assertThat(b3, IsEqual.equalTo(b1.add(b2).mod(getQ()))); + assertThat(b3, IsEqual.equalTo(b1.add(b2).mod(getQ()))); } } @@ -85,7 +87,7 @@ public abstract class AbstractFieldElementTest { final BigInteger b3 = toBigInteger(f3).mod(getQ()); // Assert: - Assert.assertThat(b3, IsEqual.equalTo(b1.subtract(b2).mod(getQ()))); + assertThat(b3, IsEqual.equalTo(b1.subtract(b2).mod(getQ()))); } } @@ -101,7 +103,7 @@ public abstract class AbstractFieldElementTest { final BigInteger b2 = toBigInteger(f2).mod(getQ()); // Assert: - Assert.assertThat(b2, IsEqual.equalTo(b1.negate().mod(getQ()))); + assertThat(b2, IsEqual.equalTo(b1.negate().mod(getQ()))); } } @@ -119,7 +121,7 @@ public abstract class AbstractFieldElementTest { final BigInteger b3 = toBigInteger(f3).mod(getQ()); // Assert: - Assert.assertThat(b3, IsEqual.equalTo(b1.multiply(b2).mod(getQ()))); + assertThat(b3, IsEqual.equalTo(b1.multiply(b2).mod(getQ()))); } } @@ -135,7 +137,7 @@ public abstract class AbstractFieldElementTest { final BigInteger b2 = toBigInteger(f2).mod(getQ()); // Assert: - Assert.assertThat(b2, IsEqual.equalTo(b1.multiply(b1).mod(getQ()))); + assertThat(b2, IsEqual.equalTo(b1.multiply(b1).mod(getQ()))); } } @@ -151,7 +153,7 @@ public abstract class AbstractFieldElementTest { final BigInteger b2 = toBigInteger(f2).mod(getQ()); // Assert: - Assert.assertThat(b2, IsEqual.equalTo(b1.multiply(b1).multiply(new BigInteger("2")).mod(getQ()))); + assertThat(b2, IsEqual.equalTo(b1.multiply(b1).multiply(new BigInteger("2")).mod(getQ()))); } } @@ -167,7 +169,7 @@ public abstract class AbstractFieldElementTest { final BigInteger b2 = toBigInteger(f2).mod(getQ()); // Assert: - Assert.assertThat(b2, IsEqual.equalTo(b1.modInverse(getQ()))); + assertThat(b2, IsEqual.equalTo(b1.modInverse(getQ()))); } } @@ -183,7 +185,7 @@ public abstract class AbstractFieldElementTest { final BigInteger b2 = toBigInteger(f2).mod(getQ()); // Assert: - Assert.assertThat(b2, IsEqual.equalTo(b1.modPow(BigInteger.ONE.shiftLeft(252).subtract(new BigInteger("3")), getQ()))); + assertThat(b2, IsEqual.equalTo(b1.modPow(BigInteger.ONE.shiftLeft(252).subtract(new BigInteger("3")), getQ()))); } } @@ -197,11 +199,11 @@ public abstract class AbstractFieldElementTest { final FieldElement nz = getNonZeroFieldElement(); final FieldElement f = getRandomFieldElement(); - Assert.assertThat(zero.cmov(nz, 0), IsEqual.equalTo(zero)); - Assert.assertThat(zero.cmov(nz, 1), IsEqual.equalTo(nz)); + assertThat(zero.cmov(nz, 0), IsEqual.equalTo(zero)); + assertThat(zero.cmov(nz, 1), IsEqual.equalTo(nz)); - Assert.assertThat(f.cmov(nz, 0), IsEqual.equalTo(f)); - Assert.assertThat(f.cmov(nz, 1), IsEqual.equalTo(nz)); + assertThat(f.cmov(nz, 0), IsEqual.equalTo(f)); + assertThat(f.cmov(nz, 1), IsEqual.equalTo(nz)); } // endregion @@ -217,10 +219,10 @@ public abstract class AbstractFieldElementTest { final FieldElement f4 = getRandomFieldElement(); // Assert: - Assert.assertThat(f1, IsEqual.equalTo(f2)); - Assert.assertThat(f1, IsNot.not(IsEqual.equalTo(f3))); - Assert.assertThat(f1, IsNot.not(IsEqual.equalTo(f4))); - Assert.assertThat(f3, IsNot.not(IsEqual.equalTo(f4))); + assertThat(f1, IsEqual.equalTo(f2)); + assertThat(f1, IsNot.not(IsEqual.equalTo(f3))); + assertThat(f1, IsNot.not(IsEqual.equalTo(f4))); + assertThat(f3, IsNot.not(IsEqual.equalTo(f4))); } @Test @@ -232,10 +234,10 @@ public abstract class AbstractFieldElementTest { final FieldElement f4 = getRandomFieldElement(); // Assert: - Assert.assertThat(f1.hashCode(), IsEqual.equalTo(f2.hashCode())); - Assert.assertThat(f1.hashCode(), IsNot.not(IsEqual.equalTo(f3.hashCode()))); - Assert.assertThat(f1.hashCode(), IsNot.not(IsEqual.equalTo(f4.hashCode()))); - Assert.assertThat(f3.hashCode(), IsNot.not(IsEqual.equalTo(f4.hashCode()))); + assertThat(f1.hashCode(), IsEqual.equalTo(f2.hashCode())); + assertThat(f1.hashCode(), IsNot.not(IsEqual.equalTo(f3.hashCode()))); + assertThat(f1.hashCode(), IsNot.not(IsEqual.equalTo(f4.hashCode()))); + assertThat(f3.hashCode(), IsNot.not(IsEqual.equalTo(f4.hashCode()))); } // endregion diff --git a/core/java/test/junit/net/i2p/crypto/eddsa/math/ConstantsTest.java b/core/java/test/junit/net/i2p/crypto/eddsa/math/ConstantsTest.java index 0054eaf0882823b430927e89750589fe9b9749cf..6895a7edc2c0aeda1f59fc36e2d11fbeda006995 100644 --- a/core/java/test/junit/net/i2p/crypto/eddsa/math/ConstantsTest.java +++ b/core/java/test/junit/net/i2p/crypto/eddsa/math/ConstantsTest.java @@ -14,8 +14,9 @@ package net.i2p.crypto.eddsa.math; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; + import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; diff --git a/core/java/test/junit/net/i2p/crypto/eddsa/math/GroupElementTest.java b/core/java/test/junit/net/i2p/crypto/eddsa/math/GroupElementTest.java index 29297f6b52de4bf5d7d1d88dbd22fa2181d6a5d0..58b5fa7958373e2015a61610cc60cdc564a01dd3 100644 --- a/core/java/test/junit/net/i2p/crypto/eddsa/math/GroupElementTest.java +++ b/core/java/test/junit/net/i2p/crypto/eddsa/math/GroupElementTest.java @@ -21,7 +21,8 @@ import java.math.BigInteger; import java.util.Arrays; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; + /** * @author str4d @@ -50,9 +51,6 @@ public class GroupElementTest { }; static final byte[] BYTES_PKR = Utils.hexToBytes("3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29"); - @Rule - public ExpectedException exception = ExpectedException.none(); - /** * Test method for {@link GroupElement#p2(Curve, FieldElement, FieldElement, FieldElement)}. */ @@ -201,7 +199,7 @@ public class GroupElementTest { final GroupElement h2 = MathUtils.toGroupElement(bytes); // Assert: - Assert.assertThat(h1, IsEqual.equalTo(h2)); + assertThat(h1, IsEqual.equalTo(h2)); } } @@ -247,7 +245,7 @@ public class GroupElementTest { } // Assert: - Assert.assertThat(Arrays.equals(gBytes, bytes), IsEqual.equalTo(true)); + assertThat(Arrays.equals(gBytes, bytes), IsEqual.equalTo(true)); } } @@ -303,12 +301,12 @@ public class GroupElementTest { final GroupElement h = g.toP2(); // Assert: - Assert.assertThat(h, IsEqual.equalTo(g)); - Assert.assertThat(h.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P2)); - Assert.assertThat(h.getX(), IsEqual.equalTo(g.getX())); - Assert.assertThat(h.getY(), IsEqual.equalTo(g.getY())); - Assert.assertThat(h.getZ(), IsEqual.equalTo(g.getZ())); - Assert.assertThat(h.getT(), IsEqual.equalTo(null)); + assertThat(h, IsEqual.equalTo(g)); + assertThat(h.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P2)); + assertThat(h.getX(), IsEqual.equalTo(g.getX())); + assertThat(h.getY(), IsEqual.equalTo(g.getY())); + assertThat(h.getZ(), IsEqual.equalTo(g.getZ())); + assertThat(h.getT(), IsEqual.equalTo(null)); } } @@ -323,12 +321,12 @@ public class GroupElementTest { final GroupElement h2 = MathUtils.toRepresentation(g, GroupElement.Representation.P2); // Assert: - Assert.assertThat(h1, IsEqual.equalTo(h2)); - Assert.assertThat(h1.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P2)); - Assert.assertThat(h1.getX(), IsEqual.equalTo(g.getX())); - Assert.assertThat(h1.getY(), IsEqual.equalTo(g.getY())); - Assert.assertThat(h1.getZ(), IsEqual.equalTo(g.getZ())); - Assert.assertThat(h1.getT(), IsEqual.equalTo(null)); + assertThat(h1, IsEqual.equalTo(h2)); + assertThat(h1.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P2)); + assertThat(h1.getX(), IsEqual.equalTo(g.getX())); + assertThat(h1.getY(), IsEqual.equalTo(g.getY())); + assertThat(h1.getZ(), IsEqual.equalTo(g.getZ())); + assertThat(h1.getT(), IsEqual.equalTo(null)); } } @@ -343,12 +341,12 @@ public class GroupElementTest { final GroupElement h2 = MathUtils.toRepresentation(g, GroupElement.Representation.P2); // Assert: - Assert.assertThat(h1, IsEqual.equalTo(h2)); - Assert.assertThat(h1.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P2)); - Assert.assertThat(h1.getX(), IsEqual.equalTo(g.getX().multiply(g.getT()))); - Assert.assertThat(h1.getY(), IsEqual.equalTo(g.getY().multiply(g.getZ()))); - Assert.assertThat(h1.getZ(), IsEqual.equalTo(g.getZ().multiply(g.getT()))); - Assert.assertThat(h1.getT(), IsEqual.equalTo(null)); + assertThat(h1, IsEqual.equalTo(h2)); + assertThat(h1.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P2)); + assertThat(h1.getX(), IsEqual.equalTo(g.getX().multiply(g.getT()))); + assertThat(h1.getY(), IsEqual.equalTo(g.getY().multiply(g.getZ()))); + assertThat(h1.getZ(), IsEqual.equalTo(g.getZ().multiply(g.getT()))); + assertThat(h1.getT(), IsEqual.equalTo(null)); } } @@ -390,12 +388,12 @@ public class GroupElementTest { final GroupElement h2 = MathUtils.toRepresentation(g, GroupElement.Representation.P3); // Assert: - Assert.assertThat(h1, IsEqual.equalTo(h2)); - Assert.assertThat(h1.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P3)); - Assert.assertThat(h1.getX(), IsEqual.equalTo(g.getX().multiply(g.getT()))); - Assert.assertThat(h1.getY(), IsEqual.equalTo(g.getY().multiply(g.getZ()))); - Assert.assertThat(h1.getZ(), IsEqual.equalTo(g.getZ().multiply(g.getT()))); - Assert.assertThat(h1.getT(), IsEqual.equalTo(g.getX().multiply(g.getY()))); + assertThat(h1, IsEqual.equalTo(h2)); + assertThat(h1.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P3)); + assertThat(h1.getX(), IsEqual.equalTo(g.getX().multiply(g.getT()))); + assertThat(h1.getY(), IsEqual.equalTo(g.getY().multiply(g.getZ()))); + assertThat(h1.getZ(), IsEqual.equalTo(g.getZ().multiply(g.getT()))); + assertThat(h1.getT(), IsEqual.equalTo(g.getX().multiply(g.getY()))); } } @@ -409,13 +407,13 @@ public class GroupElementTest { final GroupElement h = g.toP3(); // Assert: - Assert.assertThat(h, IsEqual.equalTo(g)); - Assert.assertThat(h.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P3)); - Assert.assertThat(h, IsEqual.equalTo(g)); - Assert.assertThat(h.getX(), IsEqual.equalTo(g.getX())); - Assert.assertThat(h.getY(), IsEqual.equalTo(g.getY())); - Assert.assertThat(h.getZ(), IsEqual.equalTo(g.getZ())); - Assert.assertThat(h.getT(), IsEqual.equalTo(g.getT())); + assertThat(h, IsEqual.equalTo(g)); + assertThat(h.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P3)); + assertThat(h, IsEqual.equalTo(g)); + assertThat(h.getX(), IsEqual.equalTo(g.getX())); + assertThat(h.getY(), IsEqual.equalTo(g.getY())); + assertThat(h.getZ(), IsEqual.equalTo(g.getZ())); + assertThat(h.getT(), IsEqual.equalTo(g.getT())); } } @@ -430,15 +428,15 @@ public class GroupElementTest { final GroupElement h2 = MathUtils.toRepresentation(g, GroupElement.Representation.P3PrecomputedDouble); // Assert: - Assert.assertThat(h1, IsEqual.equalTo(h2)); - Assert.assertThat(h1.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P3)); - Assert.assertThat(h1.getX(), IsEqual.equalTo(g.getX().multiply(g.getT()))); - Assert.assertThat(h1.getY(), IsEqual.equalTo(g.getY().multiply(g.getZ()))); - Assert.assertThat(h1.getZ(), IsEqual.equalTo(g.getZ().multiply(g.getT()))); - Assert.assertThat(h1.getT(), IsEqual.equalTo(g.getX().multiply(g.getY()))); - Assert.assertThat(h1.precmp, IsNull.nullValue()); - Assert.assertThat(h1.dblPrecmp, IsNull.notNullValue()); - Assert.assertThat(h1.dblPrecmp, IsEqual.equalTo(h2.dblPrecmp)); + assertThat(h1, IsEqual.equalTo(h2)); + assertThat(h1.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.P3)); + assertThat(h1.getX(), IsEqual.equalTo(g.getX().multiply(g.getT()))); + assertThat(h1.getY(), IsEqual.equalTo(g.getY().multiply(g.getZ()))); + assertThat(h1.getZ(), IsEqual.equalTo(g.getZ().multiply(g.getT()))); + assertThat(h1.getT(), IsEqual.equalTo(g.getX().multiply(g.getY()))); + assertThat(h1.precmp, IsNull.nullValue()); + assertThat(h1.dblPrecmp, IsNull.notNullValue()); + assertThat(h1.dblPrecmp, IsEqual.equalTo(h2.dblPrecmp)); } } @@ -479,13 +477,13 @@ public class GroupElementTest { final GroupElement h = g.toCached(); // Assert: - Assert.assertThat(h, IsEqual.equalTo(g)); - Assert.assertThat(h.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.CACHED)); - Assert.assertThat(h, IsEqual.equalTo(g)); - Assert.assertThat(h.getX(), IsEqual.equalTo(g.getX())); - Assert.assertThat(h.getY(), IsEqual.equalTo(g.getY())); - Assert.assertThat(h.getZ(), IsEqual.equalTo(g.getZ())); - Assert.assertThat(h.getT(), IsEqual.equalTo(g.getT())); + assertThat(h, IsEqual.equalTo(g)); + assertThat(h.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.CACHED)); + assertThat(h, IsEqual.equalTo(g)); + assertThat(h.getX(), IsEqual.equalTo(g.getX())); + assertThat(h.getY(), IsEqual.equalTo(g.getY())); + assertThat(h.getZ(), IsEqual.equalTo(g.getZ())); + assertThat(h.getT(), IsEqual.equalTo(g.getT())); } } @@ -500,13 +498,13 @@ public class GroupElementTest { final GroupElement h2 = MathUtils.toRepresentation(g, GroupElement.Representation.CACHED); // Assert: - Assert.assertThat(h1, IsEqual.equalTo(h2)); - Assert.assertThat(h1.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.CACHED)); - Assert.assertThat(h1, IsEqual.equalTo(g)); - Assert.assertThat(h1.getX(), IsEqual.equalTo(g.getY().add(g.getX()))); - Assert.assertThat(h1.getY(), IsEqual.equalTo(g.getY().subtract(g.getX()))); - Assert.assertThat(h1.getZ(), IsEqual.equalTo(g.getZ())); - Assert.assertThat(h1.getT(), IsEqual.equalTo(g.getT().multiply(curve.get2D()))); + assertThat(h1, IsEqual.equalTo(h2)); + assertThat(h1.getRepresentation(), IsEqual.equalTo(GroupElement.Representation.CACHED)); + assertThat(h1, IsEqual.equalTo(g)); + assertThat(h1.getX(), IsEqual.equalTo(g.getY().add(g.getX()))); + assertThat(h1.getY(), IsEqual.equalTo(g.getY().subtract(g.getX()))); + assertThat(h1.getZ(), IsEqual.equalTo(g.getZ())); + assertThat(h1.getT(), IsEqual.equalTo(g.getT().multiply(curve.get2D()))); } } @@ -531,7 +529,7 @@ public class GroupElementTest { for (int i = 0; i < 32; i++) { GroupElement h = g; for (int j = 0; j < 8; j++) { - Assert.assertThat(MathUtils.toRepresentation(h, GroupElement.Representation.PRECOMP), IsEqual.equalTo(ed25519.getB().precmp[i][j])); + assertThat(MathUtils.toRepresentation(h, GroupElement.Representation.PRECOMP), IsEqual.equalTo(ed25519.getB().precmp[i][j])); h = MathUtils.addGroupElements(h, g); } for (int k = 0; k < 8; k++) { @@ -548,7 +546,7 @@ public class GroupElementTest { // Act + Assert: for (int i=0; i<8; i++) { - Assert.assertThat(MathUtils.toRepresentation(g, GroupElement.Representation.PRECOMP), IsEqual.equalTo(ed25519.getB().dblPrecmp[i])); + assertThat(MathUtils.toRepresentation(g, GroupElement.Representation.PRECOMP), IsEqual.equalTo(ed25519.getB().dblPrecmp[i])); g = MathUtils.addGroupElements(g, h); } } @@ -574,7 +572,7 @@ public class GroupElementTest { final GroupElement h2 = MathUtils.doubleGroupElement(g); // Assert: - Assert.assertThat(h2, IsEqual.equalTo(h1)); + assertThat(h2, IsEqual.equalTo(h1)); } } @@ -590,8 +588,8 @@ public class GroupElementTest { final GroupElement h2 = neutral.add(g.toCached()); // Assert: - Assert.assertThat(g, IsEqual.equalTo(h1)); - Assert.assertThat(g, IsEqual.equalTo(h2)); + assertThat(g, IsEqual.equalTo(h1)); + assertThat(g, IsEqual.equalTo(h2)); } } @@ -607,7 +605,7 @@ public class GroupElementTest { final GroupElement h2 = MathUtils.addGroupElements(g1, g2); // Assert: - Assert.assertThat(h2, IsEqual.equalTo(h1)); + assertThat(h2, IsEqual.equalTo(h1)); } } @@ -623,7 +621,7 @@ public class GroupElementTest { final GroupElement h2 = MathUtils.addGroupElements(g1, MathUtils.negateGroupElement(g2)); // Assert: - Assert.assertThat(h2, IsEqual.equalTo(h1)); + assertThat(h2, IsEqual.equalTo(h1)); } } @@ -647,13 +645,13 @@ public class GroupElementTest { final GroupElement g5 = MathUtils.getRandomGroupElement(); // Assert - Assert.assertThat(g2, IsEqual.equalTo(g1)); - Assert.assertThat(g3, IsEqual.equalTo(g1)); - Assert.assertThat(g1, IsEqual.equalTo(g4)); - Assert.assertThat(g1, IsNot.not(IsEqual.equalTo(g5))); - Assert.assertThat(g2, IsNot.not(IsEqual.equalTo(g5))); - Assert.assertThat(g3, IsNot.not(IsEqual.equalTo(g5))); - Assert.assertThat(g5, IsNot.not(IsEqual.equalTo(g4))); + assertThat(g2, IsEqual.equalTo(g1)); + assertThat(g3, IsEqual.equalTo(g1)); + assertThat(g1, IsEqual.equalTo(g4)); + assertThat(g1, IsNot.not(IsEqual.equalTo(g5))); + assertThat(g2, IsNot.not(IsEqual.equalTo(g5))); + assertThat(g3, IsNot.not(IsEqual.equalTo(g5))); + assertThat(g5, IsNot.not(IsEqual.equalTo(g4))); } @Test @@ -665,11 +663,11 @@ public class GroupElementTest { final GroupElement g4 = MathUtils.getRandomGroupElement(); // Assert - Assert.assertThat(g2.hashCode(), IsEqual.equalTo(g1.hashCode())); - Assert.assertThat(g3.hashCode(), IsEqual.equalTo(g1.hashCode())); - Assert.assertThat(g1.hashCode(), IsNot.not(IsEqual.equalTo(g4.hashCode()))); - Assert.assertThat(g2.hashCode(), IsNot.not(IsEqual.equalTo(g4.hashCode()))); - Assert.assertThat(g3.hashCode(), IsNot.not(IsEqual.equalTo(g4.hashCode()))); + assertThat(g2.hashCode(), IsEqual.equalTo(g1.hashCode())); + assertThat(g3.hashCode(), IsEqual.equalTo(g1.hashCode())); + assertThat(g1.hashCode(), IsNot.not(IsEqual.equalTo(g4.hashCode()))); + assertThat(g2.hashCode(), IsNot.not(IsEqual.equalTo(g4.hashCode()))); + assertThat(g3.hashCode(), IsNot.not(IsEqual.equalTo(g4.hashCode()))); } // endregion @@ -780,7 +778,7 @@ public class GroupElementTest { final GroupElement g = basePoint.scalarMultiply(curve.getField().ZERO.toByteArray()); // Assert: - Assert.assertThat(curve.getZero(GroupElement.Representation.P3), IsEqual.equalTo(g)); + assertThat(curve.getZero(GroupElement.Representation.P3), IsEqual.equalTo(g)); } @Test @@ -792,7 +790,7 @@ public class GroupElementTest { final GroupElement g = basePoint.scalarMultiply(curve.getField().ONE.toByteArray()); // Assert: - Assert.assertThat(basePoint, IsEqual.equalTo(g)); + assertThat(basePoint, IsEqual.equalTo(g)); } // This test is slow (~6s) due to math utils using an inferior algorithm to calculate the result. @@ -808,7 +806,7 @@ public class GroupElementTest { final GroupElement h = MathUtils.scalarMultiplyGroupElement(basePoint, f); // Assert: - Assert.assertThat(g, IsEqual.equalTo(h)); + assertThat(g, IsEqual.equalTo(h)); } } @@ -871,7 +869,7 @@ public class GroupElementTest { final GroupElement h2 = MathUtils.doubleScalarMultiplyGroupElements(basePoint, f1, g, f2); // Assert: - Assert.assertThat(h1, IsEqual.equalTo(h2)); + assertThat(h1, IsEqual.equalTo(h2)); } } @@ -903,7 +901,7 @@ public class GroupElementTest { final GroupElement g = MathUtils.getRandomGroupElement(); // Assert: - Assert.assertThat(g.isOnCurve(), IsEqual.equalTo(true)); + assertThat(g.isOnCurve(), IsEqual.equalTo(true)); } } @@ -915,7 +913,7 @@ public class GroupElementTest { final GroupElement h = GroupElement.p2(curve, g.getX(), g.getY(), g.getZ().multiply(curve.getField().TWO)); // Assert (can only fail for 5*Z^2=1): - Assert.assertThat(h.isOnCurve(), IsEqual.equalTo(false)); + assertThat(h.isOnCurve(), IsEqual.equalTo(false)); } } } diff --git a/core/java/test/junit/net/i2p/crypto/eddsa/math/MathUtils.java b/core/java/test/junit/net/i2p/crypto/eddsa/math/MathUtils.java index 198debcb92c6625166a7bc55900708d362fb1b3a..1bcc3c87a2e82227ef37dc61cd7eb48b7e93c402 100644 --- a/core/java/test/junit/net/i2p/crypto/eddsa/math/MathUtils.java +++ b/core/java/test/junit/net/i2p/crypto/eddsa/math/MathUtils.java @@ -16,6 +16,7 @@ import net.i2p.crypto.eddsa.math.ed25519.*; import net.i2p.crypto.eddsa.spec.*; import org.hamcrest.core.IsEqual; import org.junit.*; +import static org.hamcrest.MatcherAssert.assertThat; import java.math.BigInteger; import java.security.SecureRandom; @@ -451,8 +452,8 @@ public class MathUtils { final GroupElement h2 = addGroupElements(neutral, g); // Assert: - Assert.assertThat(g, IsEqual.equalTo(h1)); - Assert.assertThat(g, IsEqual.equalTo(h2)); + assertThat(g, IsEqual.equalTo(h1)); + assertThat(g, IsEqual.equalTo(h2)); } for (int i=0; i<1000; i++) { @@ -460,24 +461,24 @@ public class MathUtils { // P3 -> P2. GroupElement h = toRepresentation(g, GroupElement.Representation.P2); - Assert.assertThat(h, IsEqual.equalTo(g)); + assertThat(h, IsEqual.equalTo(g)); // P3 -> P1P1. h = toRepresentation(g, GroupElement.Representation.P1P1); - Assert.assertThat(g, IsEqual.equalTo(h)); + assertThat(g, IsEqual.equalTo(h)); // P3 -> CACHED. h = toRepresentation(g, GroupElement.Representation.CACHED); - Assert.assertThat(h, IsEqual.equalTo(g)); + assertThat(h, IsEqual.equalTo(g)); // P3 -> P2 -> P3. g = toRepresentation(g, GroupElement.Representation.P2); h = toRepresentation(g, GroupElement.Representation.P3); - Assert.assertThat(g, IsEqual.equalTo(h)); + assertThat(g, IsEqual.equalTo(h)); // P3 -> P2 -> P1P1. g = toRepresentation(g, GroupElement.Representation.P2); h = toRepresentation(g, GroupElement.Representation.P1P1); - Assert.assertThat(g, IsEqual.equalTo(h)); + assertThat(g, IsEqual.equalTo(h)); } for (int i=0; i<10; i++) { @@ -488,7 +489,7 @@ public class MathUtils { final GroupElement h = MathUtils.scalarMultiplyGroupElement(g, curve.getField().ZERO); // Assert: - Assert.assertThat(curve.getZero(GroupElement.Representation.P3), IsEqual.equalTo(h)); + assertThat(curve.getZero(GroupElement.Representation.P3), IsEqual.equalTo(h)); } } // End TODO BR: Remove when finished! diff --git a/core/java/test/junit/net/i2p/crypto/eddsa/math/bigint/BigIntegerFieldElementTest.java b/core/java/test/junit/net/i2p/crypto/eddsa/math/bigint/BigIntegerFieldElementTest.java index fdd443c493fa0c26aadbd9cb11eb925d2ef83742..6c71e64aa281ff15bec8fa5543231438c13177a1 100644 --- a/core/java/test/junit/net/i2p/crypto/eddsa/math/bigint/BigIntegerFieldElementTest.java +++ b/core/java/test/junit/net/i2p/crypto/eddsa/math/bigint/BigIntegerFieldElementTest.java @@ -12,7 +12,7 @@ package net.i2p.crypto.eddsa.math.bigint; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; import java.math.BigInteger; import java.util.Random; diff --git a/core/java/test/junit/net/i2p/crypto/eddsa/math/bigint/BigIntegerScalarOpsTest.java b/core/java/test/junit/net/i2p/crypto/eddsa/math/bigint/BigIntegerScalarOpsTest.java index 8e8040e402da69773e26d2273c1efc0133294585..c32dffc060c914563b40ad342a7dd061f08b8f32 100644 --- a/core/java/test/junit/net/i2p/crypto/eddsa/math/bigint/BigIntegerScalarOpsTest.java +++ b/core/java/test/junit/net/i2p/crypto/eddsa/math/bigint/BigIntegerScalarOpsTest.java @@ -12,7 +12,8 @@ package net.i2p.crypto.eddsa.math.bigint; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; + import java.math.BigInteger; diff --git a/core/java/test/junit/net/i2p/crypto/eddsa/math/ed25519/Ed25519FieldElementTest.java b/core/java/test/junit/net/i2p/crypto/eddsa/math/ed25519/Ed25519FieldElementTest.java index 0c2bacfafbf73514dccc69e0d1623f1704daa3bd..22d408659a0697f4eba5582b79558f89b0ee208c 100644 --- a/core/java/test/junit/net/i2p/crypto/eddsa/math/ed25519/Ed25519FieldElementTest.java +++ b/core/java/test/junit/net/i2p/crypto/eddsa/math/ed25519/Ed25519FieldElementTest.java @@ -14,6 +14,8 @@ package net.i2p.crypto.eddsa.math.ed25519; import net.i2p.crypto.eddsa.math.*; import org.hamcrest.core.*; import org.junit.*; +import static org.hamcrest.MatcherAssert.assertThat; + import java.math.BigInteger; @@ -95,7 +97,7 @@ public class Ed25519FieldElementTest extends AbstractFieldElementTest { builder.append("]"); // Assert: - Assert.assertThat(fAsString, IsEqual.equalTo(builder.toString())); + assertThat(fAsString, IsEqual.equalTo(builder.toString())); } // endregion diff --git a/core/java/test/junit/net/i2p/crypto/eddsa/math/ed25519/Ed25519LittleEndianEncodingTest.java b/core/java/test/junit/net/i2p/crypto/eddsa/math/ed25519/Ed25519LittleEndianEncodingTest.java index 4bf39a74d632b85eaf1ede6155135dcdac385626..27204faee1e328507ae788fcb40bad96f2edad0d 100644 --- a/core/java/test/junit/net/i2p/crypto/eddsa/math/ed25519/Ed25519LittleEndianEncodingTest.java +++ b/core/java/test/junit/net/i2p/crypto/eddsa/math/ed25519/Ed25519LittleEndianEncodingTest.java @@ -14,6 +14,8 @@ package net.i2p.crypto.eddsa.math.ed25519; import net.i2p.crypto.eddsa.math.*; import org.hamcrest.core.IsEqual; import org.junit.*; +import static org.hamcrest.MatcherAssert.assertThat; + import java.math.BigInteger; import java.security.SecureRandom; @@ -39,8 +41,8 @@ public class Ed25519LittleEndianEncodingTest { final byte[] bytes2 = MathUtils.getField().getEncoding().encode(fieldElement2); // Assert: - Assert.assertThat(bytes1, IsEqual.equalTo(MathUtils.toByteArray(BigInteger.ZERO))); - Assert.assertThat(bytes2, IsEqual.equalTo(MathUtils.toByteArray(BigInteger.ONE))); + assertThat(bytes1, IsEqual.equalTo(MathUtils.toByteArray(BigInteger.ZERO))); + assertThat(bytes2, IsEqual.equalTo(MathUtils.toByteArray(BigInteger.ONE))); } @Test @@ -58,7 +60,7 @@ public class Ed25519LittleEndianEncodingTest { final byte[] bytes = MathUtils.getField().getEncoding().encode(fieldElement1); // Assert: - Assert.assertThat(bytes, IsEqual.equalTo(MathUtils.toByteArray(b.mod(MathUtils.getQ())))); + assertThat(bytes, IsEqual.equalTo(MathUtils.toByteArray(b.mod(MathUtils.getQ())))); } } @@ -76,8 +78,8 @@ public class Ed25519LittleEndianEncodingTest { final BigInteger b2 = MathUtils.toBigInteger(f2.t); // Assert: - Assert.assertThat(b1, IsEqual.equalTo(BigInteger.ZERO)); - Assert.assertThat(b2, IsEqual.equalTo(BigInteger.ONE)); + assertThat(b1, IsEqual.equalTo(BigInteger.ZERO)); + assertThat(b2, IsEqual.equalTo(BigInteger.ONE)); } @Test @@ -94,7 +96,7 @@ public class Ed25519LittleEndianEncodingTest { final BigInteger b2 = MathUtils.toBigInteger(f.t).mod(MathUtils.getQ()); // Assert: - Assert.assertThat(b2, IsEqual.equalTo(b1)); + assertThat(b2, IsEqual.equalTo(b1)); } } @@ -110,7 +112,7 @@ public class Ed25519LittleEndianEncodingTest { final FieldElement f = new Ed25519FieldElement(MathUtils.getField(), t); // Assert: - Assert.assertThat(MathUtils.getField().getEncoding().isNegative(f), IsEqual.equalTo(isNegative)); + assertThat(MathUtils.getField().getEncoding().isNegative(f), IsEqual.equalTo(isNegative)); } } } diff --git a/core/java/test/junit/net/i2p/crypto/eddsa/math/ed25519/Ed25519ScalarOpsTest.java b/core/java/test/junit/net/i2p/crypto/eddsa/math/ed25519/Ed25519ScalarOpsTest.java index cc01942f309cf6e0a34c74eba53bb985ac38538a..5be40b6aa11d7c8e14996fd50a124feedbc1c877 100644 --- a/core/java/test/junit/net/i2p/crypto/eddsa/math/ed25519/Ed25519ScalarOpsTest.java +++ b/core/java/test/junit/net/i2p/crypto/eddsa/math/ed25519/Ed25519ScalarOpsTest.java @@ -20,7 +20,8 @@ import java.math.BigInteger; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; + /** * @author str4d @@ -52,9 +53,9 @@ public class Ed25519ScalarOpsTest { final byte[] reduced2 = MathUtils.reduceModGroupOrder(bytes); // Assert: - Assert.assertThat(MathUtils.toBigInteger(reduced1).compareTo(MathUtils.getGroupOrder()), IsEqual.equalTo(-1)); - Assert.assertThat(MathUtils.toBigInteger(reduced1).compareTo(new BigInteger("-1")), IsEqual.equalTo(1)); - Assert.assertThat(reduced1, IsEqual.equalTo(reduced2)); + assertThat(MathUtils.toBigInteger(reduced1).compareTo(MathUtils.getGroupOrder()), IsEqual.equalTo(-1)); + assertThat(MathUtils.toBigInteger(reduced1).compareTo(new BigInteger("-1")), IsEqual.equalTo(1)); + assertThat(reduced1, IsEqual.equalTo(reduced2)); } } @@ -84,9 +85,9 @@ public class Ed25519ScalarOpsTest { final byte[] result2 = MathUtils.multiplyAndAddModGroupOrder(bytes1, bytes2, bytes3); // Assert: - Assert.assertThat(MathUtils.toBigInteger(result1).compareTo(MathUtils.getGroupOrder()), IsEqual.equalTo(-1)); - Assert.assertThat(MathUtils.toBigInteger(result1).compareTo(new BigInteger("-1")), IsEqual.equalTo(1)); - Assert.assertThat(result1, IsEqual.equalTo(result2)); + assertThat(MathUtils.toBigInteger(result1).compareTo(MathUtils.getGroupOrder()), IsEqual.equalTo(-1)); + assertThat(MathUtils.toBigInteger(result1).compareTo(new BigInteger("-1")), IsEqual.equalTo(1)); + assertThat(result1, IsEqual.equalTo(result2)); } } } diff --git a/core/java/test/junit/net/i2p/crypto/eddsa/spec/EdDSAPrivateKeySpecTest.java b/core/java/test/junit/net/i2p/crypto/eddsa/spec/EdDSAPrivateKeySpecTest.java index 262e5e1a93bcc04ff55018e82d4fdd6f5ee99031..6ec6cf8cc263170020f4dcd120dba03ab06b5922 100644 --- a/core/java/test/junit/net/i2p/crypto/eddsa/spec/EdDSAPrivateKeySpecTest.java +++ b/core/java/test/junit/net/i2p/crypto/eddsa/spec/EdDSAPrivateKeySpecTest.java @@ -12,13 +12,14 @@ package net.i2p.crypto.eddsa.spec; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; import net.i2p.crypto.eddsa.Utils; -import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.Assert; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; /** * @author str4d @@ -31,9 +32,6 @@ public class EdDSAPrivateKeySpecTest { static final EdDSANamedCurveSpec ed25519 = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.ED_25519); - @Rule - public ExpectedException exception = ExpectedException.none(); - /** * Test method for {@link net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec#EdDSAPrivateKeySpec(byte[], net.i2p.crypto.eddsa.spec.EdDSAParameterSpec)}. */ @@ -47,9 +45,12 @@ public class EdDSAPrivateKeySpecTest { @Test public void incorrectSeedLengthThrows() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("seed length is wrong"); - new EdDSAPrivateKeySpec(new byte[2], ed25519); + try { + new EdDSAPrivateKeySpec(new byte[2], ed25519); + Assert.fail("exception not thrown"); + } catch (IllegalArgumentException expected) { + assertEquals("seed length is wrong", expected.getMessage()); + } } /** @@ -65,8 +66,11 @@ public class EdDSAPrivateKeySpecTest { @Test public void incorrectHashLengthThrows() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("hash length is wrong"); - new EdDSAPrivateKeySpec(ed25519, new byte[2]); + try { + new EdDSAPrivateKeySpec(ed25519, new byte[2]); + fail("exception not thrown"); + } catch (IllegalArgumentException expected) { + assertEquals("hash length is wrong", expected.getMessage()); + } } } diff --git a/core/java/test/junit/net/i2p/data/DataStructureImplTest.java b/core/java/test/junit/net/i2p/data/DataStructureImplTest.java index f37dcd8ff439e41e1ef11ac039dbe8cbdac623cb..770b3db83b6cad8400457fb949c1dfe166e8e87f 100644 --- a/core/java/test/junit/net/i2p/data/DataStructureImplTest.java +++ b/core/java/test/junit/net/i2p/data/DataStructureImplTest.java @@ -1,9 +1,9 @@ package net.i2p.data; /* * free (adj.): unencumbered; not under the control of others - * Written by jrandom in 2003 and released into the public domain - * with no warranty of any kind, either expressed or implied. - * It probably won't make your computer catch on fire, or eat + * Written by jrandom in 2003 and released into the public domain + * with no warranty of any kind, either expressed or implied. + * It probably won't make your computer catch on fire, or eat * your children, but it might. Use at your own risk. * */ @@ -15,9 +15,7 @@ import java.io.InputStream; import java.io.OutputStream; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; /** * @author Comwiz @@ -25,9 +23,6 @@ import org.junit.rules.ExpectedException; public class DataStructureImplTest { DataStructure _struct; - @Rule - public ExpectedException exception = ExpectedException.none(); - @Before public void setUp(){ _struct = new DataStructureImpl(){ @@ -45,38 +40,47 @@ public class DataStructureImplTest { } @Test - public void toBase64ReturnsNull() throws Exception{ + public void toBase64ReturnsNull() { assertNull(_struct.toBase64()); } @Test - public void fromBase64ThrowsOnNull() throws Exception{ - exception.expect(DataFormatException.class); - exception.expectMessage("Null data passed in"); - _struct.fromBase64(null); + public void fromBase64ThrowsOnNull() { + try { + _struct.fromBase64(null); + fail("exception not thrown"); + } catch (DataFormatException expected) { + assertEquals("Null data passed in", expected.getMessage()); + } } @Test - public void calculateHashReturnsNull() throws Exception{ + public void calculateHashReturnsNull() { assertNull(_struct.calculateHash()); } @Test - public void fromByteArrayThrowsOnNull() throws Exception{ - exception.expect(DataFormatException.class); - exception.expectMessage("Null data passed in"); - _struct.fromByteArray(null); + public void fromByteArrayThrowsOnNull() { + try { + _struct.fromByteArray(null); + fail("exception not thrown"); + } catch (DataFormatException expected) { + assertEquals("Null data passed in", expected.getMessage()); + } } @Test - public void fromByteArrayThrowsOnError() throws Exception{ - exception.expect(DataFormatException.class); - exception.expectMessage("Error reading the byte array"); - _struct.fromByteArray(DataHelper.getASCII("water is poison")); + public void fromByteArrayThrowsOnError() { + try { + _struct.fromByteArray(DataHelper.getASCII("water is poison")); + fail("exception not thrown"); + } catch (DataFormatException expected) { + assertEquals("Error reading the byte array", expected.getMessage()); + } } @Test - public void toByteArrayReturnsNullOnError() throws Exception{ + public void toByteArrayReturnsNullOnError() { assertNull(_struct.toByteArray()); } } diff --git a/core/java/test/junit/net/i2p/data/KeyCertificateTest.java b/core/java/test/junit/net/i2p/data/KeyCertificateTest.java index 3c543da9a8b7c5826a30c5211eb2516f86fca226..37d069ba43bc48ea4f9691d2df3bc343e473fbb4 100644 --- a/core/java/test/junit/net/i2p/data/KeyCertificateTest.java +++ b/core/java/test/junit/net/i2p/data/KeyCertificateTest.java @@ -1,15 +1,15 @@ package net.i2p.data; /* * free (adj.): unencumbered; not under the control of others - * Written by str4d in 2015 and released into the public domain - * with no warranty of any kind, either expressed or implied. - * It probably won't make your computer catch on fire, or eat + * Written by str4d in 2015 and released into the public domain + * with no warranty of any kind, either expressed or implied. + * It probably won't make your computer catch on fire, or eat * your children, but it might. Use at your own risk. * */ import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; import net.i2p.crypto.EncType; import net.i2p.crypto.SigType; diff --git a/core/java/test/junit/net/i2p/data/LeaseSetTest.java b/core/java/test/junit/net/i2p/data/LeaseSetTest.java index 893596e5c0b5d9aa4751831d4052ce2a3a5e670a..11bd386ba6431ab6e98b9a41d7829c84c826570c 100644 --- a/core/java/test/junit/net/i2p/data/LeaseSetTest.java +++ b/core/java/test/junit/net/i2p/data/LeaseSetTest.java @@ -1,18 +1,16 @@ package net.i2p.data; /* * free (adj.): unencumbered; not under the control of others - * Written by jrandom in 2003 and released into the public domain - * with no warranty of any kind, either expressed or implied. - * It probably won't make your computer catch on fire, or eat + * Written by jrandom in 2003 and released into the public domain + * with no warranty of any kind, either expressed or implied. + * It probably won't make your computer catch on fire, or eat * your children, but it might. Use at your own risk. * */ import static org.junit.Assert.*; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; /** * Test harness for loading / storing Lease objects @@ -21,9 +19,6 @@ import org.junit.rules.ExpectedException; */ public class LeaseSetTest extends StructureTest { - @Rule - public ExpectedException exception = ExpectedException.none(); - public DataStructure createDataStructure() throws DataFormatException { LeaseSet leaseSet = new LeaseSet(); leaseSet.setDestination((Destination)(new DestinationTest()).createDataStructure()); @@ -31,7 +26,7 @@ public class LeaseSetTest extends StructureTest { leaseSet.setSignature((Signature)(new SignatureTest()).createDataStructure()); leaseSet.setSigningKey((SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure()); //leaseSet.setVersion(42l); - return leaseSet; + return leaseSet; } public DataStructure createStructureToRead() { return new LeaseSet(); } @@ -41,8 +36,10 @@ public class LeaseSetTest extends StructureTest { LeaseSet subj = new LeaseSet(); // should contain no leases now. - exception.expect(IndexOutOfBoundsException.class); - subj.getLease(0); + try { + subj.getLease(0); + fail("exception not thrown"); + } catch (IndexOutOfBoundsException expected) {} } @Test @@ -51,8 +48,10 @@ public class LeaseSetTest extends StructureTest { LeaseSet subj = new LeaseSet(); // this shouldn't work either - exception.expect(IndexOutOfBoundsException.class); - subj.getLease(-1); + try { + subj.getLease(-1); + fail("exception not thrown"); + } catch (IndexOutOfBoundsException expected) {} } @Test @@ -61,9 +60,12 @@ public class LeaseSetTest extends StructureTest { LeaseSet subj = new LeaseSet(); // now add an null lease - exception.expect(IllegalArgumentException.class); - exception.expectMessage("erm, null lease"); - subj.addLease(null); + try { + subj.addLease(null); + fail("exception not thrown"); + } catch (IllegalArgumentException expected) { + assertEquals("erm, null lease", expected.getMessage()); + } } @Test @@ -72,8 +74,11 @@ public class LeaseSetTest extends StructureTest { LeaseSet subj = new LeaseSet(); // try to add completely invalid lease(ie. no data) - exception.expect(IllegalArgumentException.class); - exception.expectMessage("erm, lease has no gateway"); - subj.addLease(new Lease()); + try { + subj.addLease(new Lease()); + fail("exception not thrown"); + } catch (IllegalArgumentException expected) { + assertEquals("erm, lease has no gateway", expected.getMessage()); + } } } diff --git a/core/java/test/junit/net/i2p/data/LeaseTest.java b/core/java/test/junit/net/i2p/data/LeaseTest.java index 34e6d8b58b615b1162db189d414d9c4a79e9c6b1..82033f4fd1dd7db155dce80167c43f2e1997adb5 100644 --- a/core/java/test/junit/net/i2p/data/LeaseTest.java +++ b/core/java/test/junit/net/i2p/data/LeaseTest.java @@ -1,9 +1,9 @@ package net.i2p.data; /* * free (adj.): unencumbered; not under the control of others - * Written by jrandom in 2003 and released into the public domain - * with no warranty of any kind, either expressed or implied. - * It probably won't make your computer catch on fire, or eat + * Written by jrandom in 2003 and released into the public domain + * with no warranty of any kind, either expressed or implied. + * It probably won't make your computer catch on fire, or eat * your children, but it might. Use at your own risk. * */ @@ -13,9 +13,7 @@ import static org.junit.Assert.*; import java.io.ByteArrayOutputStream; import java.util.Date; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; /** * Test harness for loading / storing Lease objects @@ -24,9 +22,6 @@ import org.junit.rules.ExpectedException; */ public class LeaseTest extends StructureTest { - @Rule - public ExpectedException exception = ExpectedException.none(); - public DataStructure createDataStructure() throws DataFormatException { Lease lease = new Lease(); lease.setEndDate(new Date(1000*60*2)); @@ -35,7 +30,7 @@ public class LeaseTest extends StructureTest { StructureTest tst = new TunnelIdTest(); lease.setTunnelId((TunnelId)tst.createDataStructure()); - return lease; + return lease; } public DataStructure createStructureToRead() { return new Lease(); } @@ -75,9 +70,12 @@ public class LeaseTest extends StructureTest { lease.setGateway(new Hash(h)); lease.setTunnelId(null); - exception.expect(DataFormatException.class); - exception.expectMessage("Not enough data to write out a Lease"); - lease.writeBytes(new ByteArrayOutputStream()); + try { + lease.writeBytes(new ByteArrayOutputStream()); + fail("exception not thrown"); + } catch (DataFormatException expected) { + assertEquals("Not enough data to write out a Lease", expected.getMessage()); + } } @Test @@ -89,9 +87,12 @@ public class LeaseTest extends StructureTest { StructureTest tst = new TunnelIdTest(); lease.setTunnelId((TunnelId)tst.createDataStructure()); - exception.expect(DataFormatException.class); - exception.expectMessage("Not enough data to write out a Lease"); - lease.writeBytes(new ByteArrayOutputStream()); + try { + lease.writeBytes(new ByteArrayOutputStream()); + fail("exception not thrown"); + } catch (DataFormatException expected) { + assertEquals("Not enough data to write out a Lease", expected.getMessage()); + } } @Test diff --git a/core/java/test/junit/net/i2p/data/PrivateKeyTest.java b/core/java/test/junit/net/i2p/data/PrivateKeyTest.java index d882920a0068104ea10cb21897fd7b421bfd4fb0..3f04444bd1e710e81cd3d7b9a21f0d4e7390209e 100644 --- a/core/java/test/junit/net/i2p/data/PrivateKeyTest.java +++ b/core/java/test/junit/net/i2p/data/PrivateKeyTest.java @@ -1,22 +1,20 @@ package net.i2p.data; /* * free (adj.): unencumbered; not under the control of others - * Written by jrandom in 2003 and released into the Private domain - * with no warranty of any kind, either expressed or implied. - * It probably won't make your computer catch on fire, or eat + * Written by jrandom in 2003 and released into the Private domain + * with no warranty of any kind, either expressed or implied. + * It probably won't make your computer catch on fire, or eat * your children, but it might. Use at your own risk. * */ - + 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; -import org.junit.rules.ExpectedException; /** * Test harness for loading / storing PrivateKey objects @@ -25,16 +23,13 @@ import org.junit.rules.ExpectedException; */ public class PrivateKeyTest extends StructureTest { - @Rule - public ExpectedException exception = ExpectedException.none(); - public DataStructure createDataStructure() throws DataFormatException { PrivateKey privateKey = new PrivateKey(); byte data[] = new byte[PrivateKey.KEYSIZE_BYTES]; for (int i = 0; i < data.length; i++) data[i] = (byte)(i%16); privateKey.setData(data); - return privateKey; + return privateKey; } public DataStructure createStructureToRead() { return new PrivateKey(); } @@ -66,9 +61,12 @@ public class PrivateKeyTest extends StructureTest { PrivateKey privateKey = new PrivateKey(); privateKey.toString(); - exception.expect(DataFormatException.class); - exception.expectMessage("No data to write out"); - privateKey.writeBytes(new ByteArrayOutputStream()); + try { + privateKey.writeBytes(new ByteArrayOutputStream()); + fail("exception not thrown"); + } catch (DataFormatException expected) { + assertEquals("No data to write out", expected.getMessage()); + } } @Test @@ -78,9 +76,12 @@ public class PrivateKeyTest extends StructureTest { for (int i = 0; i < data.length; i++) data[i] = (byte)(i); - exception.expect(IllegalArgumentException.class); - exception.expectMessage("Bad data length: 56; required: " + PrivateKey.KEYSIZE_BYTES); - privateKey.setData(data); + try { + privateKey.setData(data); + fail("exception not thrown"); + } catch (IllegalArgumentException expected) { + assertEquals("Bad data length: 56; required: " + PrivateKey.KEYSIZE_BYTES, expected.getMessage()); + } } @Test @@ -88,8 +89,11 @@ public class PrivateKeyTest extends StructureTest { PrivateKey privateKey = new PrivateKey(); ByteArrayInputStream in = new ByteArrayInputStream(DataHelper.getASCII("six times nine equals forty-two")); - exception.expect(EOFException.class); - exception.expectMessage("EOF after reading 31 bytes of " + PrivateKey.KEYSIZE_BYTES + " byte value"); - privateKey.readBytes(in); + try { + privateKey.readBytes(in); + fail("exception not thrown"); + } catch (EOFException expected) { + assertEquals("EOF after reading 31 bytes of " + PrivateKey.KEYSIZE_BYTES + " byte value", expected.getMessage()); + } } } diff --git a/core/java/test/junit/net/i2p/data/PublicKeyTest.java b/core/java/test/junit/net/i2p/data/PublicKeyTest.java index 2a4ece3cab020d03c0527bfafcba464d24c79426..26076b7fb8ff5ef9cf7f6aa6035c8deb9f6674ed 100644 --- a/core/java/test/junit/net/i2p/data/PublicKeyTest.java +++ b/core/java/test/junit/net/i2p/data/PublicKeyTest.java @@ -1,9 +1,9 @@ package net.i2p.data; /* * free (adj.): unencumbered; not under the control of others - * Written by jrandom in 2003 and released into the public domain - * with no warranty of any kind, either expressed or implied. - * It probably won't make your computer catch on fire, or eat + * Written by jrandom in 2003 and released into the public domain + * with no warranty of any kind, either expressed or implied. + * It probably won't make your computer catch on fire, or eat * your children, but it might. Use at your own risk. * */ @@ -14,9 +14,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.EOFException; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; /** * Test harness for loading / storing PublicKey objects @@ -25,16 +23,13 @@ import org.junit.rules.ExpectedException; */ public class PublicKeyTest extends StructureTest { - @Rule - public ExpectedException exception = ExpectedException.none(); - public DataStructure createDataStructure() throws DataFormatException { PublicKey publicKey = new PublicKey(); byte data[] = new byte[PublicKey.KEYSIZE_BYTES]; for (int i = 0; i < data.length; i++) data[i] = (byte)(i%16); publicKey.setData(data); - return publicKey; + return publicKey; } public DataStructure createStructureToRead() { return new PublicKey(); } @@ -66,9 +61,12 @@ public class PublicKeyTest extends StructureTest { PublicKey publicKey = new PublicKey(); publicKey.toString(); - exception.expect(DataFormatException.class); - exception.expectMessage("No data to write out"); - publicKey.writeBytes(new ByteArrayOutputStream()); + try { + publicKey.writeBytes(new ByteArrayOutputStream()); + fail("exception not thrown"); + } catch (DataFormatException expected) { + assertEquals("No data to write out", expected.getMessage()); + } } @Test @@ -78,10 +76,13 @@ public class PublicKeyTest extends StructureTest { for (int i = 0; i < data.length; i++) data[i] = (byte)(i); - exception.expect(IllegalArgumentException.class); - exception.expectMessage("Bad data length: 56; required: " + PublicKey.KEYSIZE_BYTES); - publicKey.setData(data); - publicKey.writeBytes(new ByteArrayOutputStream()); + try { + publicKey.setData(data); + publicKey.writeBytes(new ByteArrayOutputStream()); + fail("exception not thrown"); + } catch (IllegalArgumentException expected) { + assertEquals("Bad data length: 56; required: " + PublicKey.KEYSIZE_BYTES, expected.getMessage()); + } } @Test @@ -89,8 +90,11 @@ public class PublicKeyTest extends StructureTest { PublicKey publicKey = new PublicKey(); ByteArrayInputStream in = new ByteArrayInputStream(DataHelper.getASCII("six times nine equals forty-two")); - exception.expect(EOFException.class); - exception.expectMessage("EOF after reading 31 bytes of " + PublicKey.KEYSIZE_BYTES + " byte value"); - publicKey.readBytes(in); + try { + publicKey.readBytes(in); + fail("exception not thrown"); + } catch (EOFException expected) { + assertEquals("EOF after reading 31 bytes of " + PublicKey.KEYSIZE_BYTES + " byte value", expected.getMessage()); + } } } diff --git a/core/java/test/junit/net/i2p/data/SigningPrivateKeyTest.java b/core/java/test/junit/net/i2p/data/SigningPrivateKeyTest.java index aeece36e1d0aca5635430a5c4d296943f3c79b28..656f73e60d9154ac5b9d557e229aef9a1cab379d 100644 --- a/core/java/test/junit/net/i2p/data/SigningPrivateKeyTest.java +++ b/core/java/test/junit/net/i2p/data/SigningPrivateKeyTest.java @@ -1,22 +1,20 @@ package net.i2p.data; /* * free (adj.): unencumbered; not under the control of others - * Written by jrandom in 2003 and released into the public domain - * with no warranty of any kind, either expressed or implied. - * It probably won't make your computer catch on fire, or eat + * Written by jrandom in 2003 and released into the public domain + * with no warranty of any kind, either expressed or implied. + * It probably won't make your computer catch on fire, or eat * your children, but it might. Use at your own risk. * */ - + 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; -import org.junit.rules.ExpectedException; /** * Test harness for loading / storing SigningPrivateKey objects @@ -25,16 +23,13 @@ import org.junit.rules.ExpectedException; */ public class SigningPrivateKeyTest extends StructureTest { - @Rule - public ExpectedException exception = ExpectedException.none(); - public DataStructure createDataStructure() throws DataFormatException { SigningPrivateKey signingPrivateKey = new SigningPrivateKey(); byte data[] = new byte[SigningPrivateKey.KEYSIZE_BYTES]; for (int i = 0; i < data.length; i++) data[i] = (byte)(i%16); signingPrivateKey.setData(data); - return signingPrivateKey; + return signingPrivateKey; } public DataStructure createStructureToRead() { return new SigningPrivateKey(); } @@ -66,9 +61,12 @@ public class SigningPrivateKeyTest extends StructureTest { SigningPrivateKey signingPrivateKey = new SigningPrivateKey(); signingPrivateKey.toString(); - exception.expect(DataFormatException.class); - exception.expectMessage("No data to write out"); - signingPrivateKey.writeBytes(new ByteArrayOutputStream()); + try { + signingPrivateKey.writeBytes(new ByteArrayOutputStream()); + fail("exception not thrown"); + } catch (DataFormatException expected) { + assertEquals("No data to write out", expected.getMessage()); + } } @Test @@ -78,10 +76,13 @@ public class SigningPrivateKeyTest extends StructureTest { for (int i = 0; i < data.length; i++) data[i] = (byte)(i); - exception.expect(IllegalArgumentException.class); - exception.expectMessage("Bad data length: 56; required: " + SigningPrivateKey.KEYSIZE_BYTES); - signingPrivateKey.setData(data); - signingPrivateKey.writeBytes(new ByteArrayOutputStream()); + try { + signingPrivateKey.setData(data); + signingPrivateKey.writeBytes(new ByteArrayOutputStream()); + fail("no exception thrown"); + } catch (IllegalArgumentException expected) { + assertEquals("Bad data length: 56; required: " + SigningPrivateKey.KEYSIZE_BYTES, expected.getMessage()); + } } @Test @@ -89,8 +90,11 @@ public class SigningPrivateKeyTest extends StructureTest { SigningPrivateKey signingPrivateKey = new SigningPrivateKey(); ByteArrayInputStream in = new ByteArrayInputStream(DataHelper.getASCII("short")); - exception.expect(EOFException.class); - exception.expectMessage("EOF after reading 5 bytes of " + SigningPrivateKey.KEYSIZE_BYTES + " byte value"); - signingPrivateKey.readBytes(in); + try { + signingPrivateKey.readBytes(in); + fail("no exception thrown"); + } catch (EOFException expected) { + assertEquals("EOF after reading 5 bytes of " + SigningPrivateKey.KEYSIZE_BYTES + " byte value", expected.getMessage()); + } } } diff --git a/core/java/test/junit/net/i2p/data/SigningPublicKeyTest.java b/core/java/test/junit/net/i2p/data/SigningPublicKeyTest.java index 825543d68d08a7a45a678f56850eb605e9d3e118..085b1eaa3d61e012c051cfe6025e30741ff47a1b 100644 --- a/core/java/test/junit/net/i2p/data/SigningPublicKeyTest.java +++ b/core/java/test/junit/net/i2p/data/SigningPublicKeyTest.java @@ -1,9 +1,9 @@ package net.i2p.data; /* * free (adj.): unencumbered; not under the control of others - * Written by jrandom in 2003 and released into the public domain - * with no warranty of any kind, either expressed or implied. - * It probably won't make your computer catch on fire, or eat + * Written by jrandom in 2003 and released into the public domain + * with no warranty of any kind, either expressed or implied. + * It probably won't make your computer catch on fire, or eat * your children, but it might. Use at your own risk. * */ @@ -14,9 +14,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.EOFException; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; /** * Test harness for loading / storing PublicKey objects @@ -25,16 +23,13 @@ import org.junit.rules.ExpectedException; */ public class SigningPublicKeyTest extends StructureTest { - @Rule - public ExpectedException exception = ExpectedException.none(); - public DataStructure createDataStructure() throws DataFormatException { SigningPublicKey publicKey = new SigningPublicKey(); byte data[] = new byte[SigningPublicKey.KEYSIZE_BYTES]; for (int i = 0; i < data.length; i++) data[i] = (byte)(i%16); publicKey.setData(data); - return publicKey; + return publicKey; } public DataStructure createStructureToRead() { return new SigningPublicKey(); } @@ -66,9 +61,13 @@ public class SigningPublicKeyTest extends StructureTest { SigningPublicKey publicKey = new SigningPublicKey(); publicKey.toString(); - exception.expect(DataFormatException.class); - exception.expectMessage("No data to write out"); - publicKey.writeBytes(new ByteArrayOutputStream()); + try { + publicKey.writeBytes(new ByteArrayOutputStream()); + fail("no exception thrown"); + } catch (DataFormatException expected) { + assertEquals("No data to write out", expected.getMessage()); + } + } @Test @@ -78,10 +77,13 @@ public class SigningPublicKeyTest extends StructureTest { for (int i = 0; i < data.length; i++) data[i] = (byte)(i); - exception.expect(IllegalArgumentException.class); - exception.expectMessage("Bad data length: 56; required: " + SigningPublicKey.KEYSIZE_BYTES); - publicKey.setData(data); - publicKey.writeBytes(new ByteArrayOutputStream()); + try { + publicKey.setData(data); + publicKey.writeBytes(new ByteArrayOutputStream()); + fail("no exception thrown"); + } catch (IllegalArgumentException expected) { + assertEquals("Bad data length: 56; required: " + SigningPublicKey.KEYSIZE_BYTES, expected.getMessage()); + } } @Test @@ -89,8 +91,11 @@ public class SigningPublicKeyTest extends StructureTest { SigningPublicKey publicKey = new SigningPublicKey(); ByteArrayInputStream in = new ByteArrayInputStream(DataHelper.getASCII("six times nine equals forty-two")); - exception.expect(EOFException.class); - exception.expectMessage("EOF after reading 31 bytes of " + SigningPublicKey.KEYSIZE_BYTES + " byte value"); - publicKey.readBytes(in); + try { + publicKey.readBytes(in); + fail("exception not thrown"); + } catch (EOFException expected) { + assertEquals("EOF after reading 31 bytes of " + SigningPublicKey.KEYSIZE_BYTES + " byte value", expected.getMessage()); + } } } diff --git a/core/java/test/junit/net/i2p/data/SimpleDataStructureTest.java b/core/java/test/junit/net/i2p/data/SimpleDataStructureTest.java index d96e44dbb14db95b7db87bd6336279f0bb9398a1..68b66746588c487652987cd3bc0199006ca9c87b 100644 --- a/core/java/test/junit/net/i2p/data/SimpleDataStructureTest.java +++ b/core/java/test/junit/net/i2p/data/SimpleDataStructureTest.java @@ -1,18 +1,16 @@ package net.i2p.data; /* * free (adj.): unencumbered; not under the control of others - * Written by jrandom in 2003 and released into the public domain - * with no warranty of any kind, either expressed or implied. - * It probably won't make your computer catch on fire, or eat + * Written by jrandom in 2003 and released into the public domain + * with no warranty of any kind, either expressed or implied. + * It probably won't make your computer catch on fire, or eat * your children, but it might. Use at your own risk. * */ import static org.junit.Assert.*; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; /** * Test harness for the simple data structure @@ -21,9 +19,6 @@ import org.junit.rules.ExpectedException; */ public class SimpleDataStructureTest { - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void setDataThrowsOnNullAfterDataSet() throws Exception { // create new test subject @@ -36,9 +31,12 @@ public class SimpleDataStructureTest { struct.setData(new byte[3]); // now setting it to null should fail - exception.expect(RuntimeException.class); - exception.expectMessage("Data already set"); - struct.setData(null); + try { + struct.setData(null); + fail("exception not thrown"); + } catch (RuntimeException expected) { + assertEquals("Data already set", expected.getMessage()); + } } @Test @@ -53,9 +51,12 @@ public class SimpleDataStructureTest { struct.setData(new byte[3]); // setting it to something non-null should fail. - exception.expect(RuntimeException.class); - exception.expectMessage("Data already set"); - struct.setData(new byte[3]); + try { + struct.setData(new byte[3]); + fail("exception not thrown"); + } catch (RuntimeException expected) { + assertEquals("Data already set", expected.getMessage()); + } } @Test diff --git a/router/java/test/junit/net/i2p/data/i2np/DatabaseStoreMessageTest.java b/router/java/test/junit/net/i2p/data/i2np/DatabaseStoreMessageTest.java index add6e2c7d5c6051b987dc4415436ff5364836b6d..f41639ea1be285cbdb6a3acc0b493fd877807aa4 100644 --- a/router/java/test/junit/net/i2p/data/i2np/DatabaseStoreMessageTest.java +++ b/router/java/test/junit/net/i2p/data/i2np/DatabaseStoreMessageTest.java @@ -10,9 +10,7 @@ package net.i2p.data.i2np; import static org.junit.Assert.*; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import net.i2p.I2PAppContext; import net.i2p.data.DataFormatException; @@ -30,9 +28,6 @@ import net.i2p.util.Clock; */ public class DatabaseStoreMessageTest extends StructureTest { - @Rule - public ExpectedException exception = ExpectedException.none(); - public DataStructure createDataStructure() throws DataFormatException { DSMStructure msg = new DSMStructure(I2PAppContext.getGlobalContext()); RouterInfo info = (RouterInfo)new RouterInfoTest().createDataStructure(); @@ -41,16 +36,18 @@ public class DatabaseStoreMessageTest extends StructureTest { msg.setEntry(info); return msg; } - - public DataStructure createStructureToRead() { - return new DSMStructure(I2PAppContext.getGlobalContext()); + + public DataStructure createStructureToRead() { + return new DSMStructure(I2PAppContext.getGlobalContext()); } - + @Override @Test public void testStructure() throws Exception { - exception.expect(UnsupportedOperationException.class); - super.testStructure(); + try { + super.testStructure(); + fail("no exception thrown"); + } catch (UnsupportedOperationException expected) {} } private static class DSMStructure extends DatabaseStoreMessage implements DataStructure { diff --git a/router/java/test/junit/net/i2p/data/router/RouterAddressTest.java b/router/java/test/junit/net/i2p/data/router/RouterAddressTest.java index e14e782505a61e1e625990f0363b1e8cb4badbf4..62caf6fcbb00448259f994f72d5fee035fd62e40 100644 --- a/router/java/test/junit/net/i2p/data/router/RouterAddressTest.java +++ b/router/java/test/junit/net/i2p/data/router/RouterAddressTest.java @@ -1,21 +1,19 @@ package net.i2p.data.router; /* * free (adj.): unencumbered; not under the control of others - * Written by jrandom in 2003 and released into the public domain - * with no warranty of any kind, either expressed or implied. - * It probably won't make your computer catch on fire, or eat + * Written by jrandom in 2003 and released into the public domain + * with no warranty of any kind, either expressed or implied. + * It probably won't make your computer catch on fire, or eat * your children, but it might. Use at your own risk. * */ - + import static org.junit.Assert.*; import java.io.ByteArrayOutputStream; import java.util.Properties; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import net.i2p.data.DataFormatException; import net.i2p.data.DataStructure; @@ -29,16 +27,13 @@ import net.i2p.util.OrderedProperties; */ public class RouterAddressTest extends StructureTest { - @Rule - public ExpectedException exception = ExpectedException.none(); - public DataStructure createDataStructure() throws DataFormatException { //addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970 OrderedProperties options = new OrderedProperties(); options.setProperty("hostname", "localhost"); options.setProperty("portnum", "1234"); RouterAddress addr = new RouterAddress("Blah", options, 42); - return addr; + return addr; } public DataStructure createStructureToRead() { return new RouterAddress(); } @@ -47,8 +42,10 @@ public class RouterAddressTest extends StructureTest { public void testSetNullOptions(){ RouterAddress addr = new RouterAddress(); - exception.expect(NullPointerException.class); - addr.setOptions(null); + try { + addr.setOptions(null); + fail("no exception thrown"); + } catch (NullPointerException expected) {} } @SuppressWarnings("deprecation") @@ -60,17 +57,22 @@ public class RouterAddressTest extends StructureTest { RouterAddress addr = new RouterAddress("Blah", options, 42); options.setProperty("portnum", "2345"); - exception.expect(IllegalStateException.class); - addr.setOptions(options); + try { + addr.setOptions(options); + fail("no exception thrown"); + } catch (IllegalStateException expected) {} } @Test public void testBadWrite() throws Exception{ RouterAddress addr = new RouterAddress(); - exception.expect(DataFormatException.class); - exception.expectMessage("uninitialized"); - addr.writeBytes(new ByteArrayOutputStream()); + try { + addr.writeBytes(new ByteArrayOutputStream()); + fail("no exception thrown"); + } catch (DataFormatException expected) { + assertEquals("uninitialized", expected.getMessage()); + } } @Test diff --git a/router/java/test/junit/net/i2p/data/router/RouterIdentityTest.java b/router/java/test/junit/net/i2p/data/router/RouterIdentityTest.java index 5557c33ba816074ba2407efae52f6464f345600d..b0219bb9445b24b4a1d3ffab94baa46fe72c7792 100644 --- a/router/java/test/junit/net/i2p/data/router/RouterIdentityTest.java +++ b/router/java/test/junit/net/i2p/data/router/RouterIdentityTest.java @@ -1,9 +1,9 @@ package net.i2p.data.router; /* * free (adj.): unencumbered; not under the control of others - * Written by jrandom in 2003 and released into the public domain - * with no warranty of any kind, either expressed or implied. - * It probably won't make your computer catch on fire, or eat + * Written by jrandom in 2003 and released into the public domain + * with no warranty of any kind, either expressed or implied. + * It probably won't make your computer catch on fire, or eat * your children, but it might. Use at your own risk. * */ @@ -12,9 +12,7 @@ import static org.junit.Assert.*; import java.io.ByteArrayOutputStream; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import net.i2p.data.Certificate; import net.i2p.data.CertificateTest; @@ -33,9 +31,6 @@ import net.i2p.data.StructureTest; */ public class RouterIdentityTest extends StructureTest { - @Rule - public ExpectedException exception = ExpectedException.none(); - public DataStructure createDataStructure() throws DataFormatException { RouterIdentity ident = new RouterIdentity(); Certificate cert = (Certificate)(new CertificateTest()).createDataStructure(); @@ -57,9 +52,12 @@ public class RouterIdentityTest extends StructureTest { SigningPublicKey k = (SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure(); ident.setSigningPublicKey(k); - exception.expect(DataFormatException.class); - exception.expectMessage("Not enough data to format the router identity"); - ident.writeBytes(new ByteArrayOutputStream()); + try { + ident.writeBytes(new ByteArrayOutputStream()); + fail("no exception thrown"); + } catch (DataFormatException expected) { + assertEquals("Not enough data to format the router identity", expected.getMessage()); + } } @Test @@ -71,9 +69,12 @@ public class RouterIdentityTest extends StructureTest { SigningPublicKey k = (SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure(); ident.setSigningPublicKey(k); - exception.expect(DataFormatException.class); - exception.expectMessage("Not enough data to format the router identity"); - ident.writeBytes(new ByteArrayOutputStream()); + try { + ident.writeBytes(new ByteArrayOutputStream()); + fail("no exception thrown"); + } catch (DataFormatException expected) { + assertEquals("Not enough data to format the router identity", expected.getMessage()); + } } @Test @@ -85,9 +86,12 @@ public class RouterIdentityTest extends StructureTest { ident.setPublicKey(pk); ident.setSigningPublicKey(null); - exception.expect(DataFormatException.class); - exception.expectMessage("Not enough data to format the router identity"); - ident.writeBytes(new ByteArrayOutputStream()); + try { + ident.writeBytes(new ByteArrayOutputStream()); + fail("no exception thrown"); + } catch (DataFormatException expected) { + assertEquals("Not enough data to format the router identity", expected.getMessage()); + } } @Test @@ -117,8 +121,11 @@ public class RouterIdentityTest extends StructureTest { public void testBadHash() throws Exception { RouterIdentity ident = new RouterIdentity(); - exception.expect(IllegalStateException.class); - exception.expectMessage("KAC hash error"); - ident.getHash(); + try { + ident.getHash(); + fail("no exception thrown"); + } catch (IllegalStateException expected) { + assertEquals("KAC hash error", expected.getMessage()); + } } }