Base58Test: Independent methods for tests that expect an exception.
@@ -19,7 +19,6 @@ package org.bitcoinj.core;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.math.BigInteger;
import java.util.Arrays;
@@ -54,37 +53,32 @@ public class Base58Test {
assertTrue("1", Arrays.equals(Base58.decode("1"), new byte[1]));
assertTrue("1111", Arrays.equals(Base58.decode("1111"), new byte[4]));
- try {
+ // Test decode of empty String.
+ assertEquals(0, Base58.decode("").length);
+ }
+
+ @Test(expected = AddressFormatException.class)
+ public void testDecode_invalidBase58() {
Base58.decode("This isn't valid base58");
- fail();
- } catch (AddressFormatException e) {
- // expected
}
+ @Test
+ public void testDecodeChecked() {
Base58.decodeChecked("4stwEBjT6FYyVV");
- // Checksum should fail.
- try {
- Base58.decodeChecked("4stwEBjT6FYyVW");
- fail();
- } catch (AddressFormatException e) {
- // expected
+ // Now check we can correctly decode the case where the high bit of the first byte is not zero, so BigInteger
+ // sign extends. Fix for a bug that stopped us parsing keys exported using sipas patch.
+ Base58.decodeChecked("93VYUMzRG9DdbRP72uQXjaWibbQwygnvaCu9DumcqDjGybD864T");
}
- // Input is too short.
- try {
- Base58.decodeChecked("4s");
- fail();
- } catch (AddressFormatException e) {
- // expected
+ @Test(expected = AddressFormatException.class)
+ public void testDecodeChecked_badChecksum() {
+ Base58.decodeChecked("4stwEBjT6FYyVW");
}
- // Test decode of empty String.
- assertEquals(0, Base58.decode("").length);
-
- // Now check we can correctly decode the case where the high bit of the first byte is not zero, so BigInteger
- // sign extends. Fix for a bug that stopped us parsing keys exported using sipas patch.
- Base58.decodeChecked("93VYUMzRG9DdbRP72uQXjaWibbQwygnvaCu9DumcqDjGybD864T");
+ @Test(expected = AddressFormatException.class)
+ public void testDecodeChecked_shortInput() {
+ Base58.decodeChecked("4s");
}
@Test
