From 1b1457449a75c0a737d18c0b356a95f76f06bfb3 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Mon, 14 May 2012 20:57:14 -0700 Subject: [PATCH] Add a BitcoinURI.convertToURI variant that takes a String instead of an Address. Remove test for null param -> IllegalArgumentException as that's not consistent with the rest of the library. Resolves issue 152. --- .../java/com/google/bitcoin/uri/BitcoinURI.java | 13 +++++++------ .../java/com/google/bitcoin/uri/BitcoinURITest.java | 8 -------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/com/google/bitcoin/uri/BitcoinURI.java b/core/src/main/java/com/google/bitcoin/uri/BitcoinURI.java index aa302b12..d158b789 100644 --- a/core/src/main/java/com/google/bitcoin/uri/BitcoinURI.java +++ b/core/src/main/java/com/google/bitcoin/uri/BitcoinURI.java @@ -291,6 +291,10 @@ public class BitcoinURI { return builder.toString(); } + public static String convertToBitcoinURI(Address address, BigInteger amount, String label, String message) { + return convertToBitcoinURI(address.toString(), amount, label, message); + } + /** * Simple Bitcoin URI builder using known good fields. * @@ -300,17 +304,14 @@ public class BitcoinURI { * @param message A message * @return A String containing the Bitcoin URI */ - public static String convertToBitcoinURI(Address address, BigInteger amount, String label, String message) { - if (address == null) { - throw new IllegalArgumentException("Missing address"); - } - + public static String convertToBitcoinURI(String address, BigInteger amount, String label, String message) { + Preconditions.checkNotNull(address); if (amount != null && amount.compareTo(BigInteger.ZERO) < 0) { throw new IllegalArgumentException("Amount must be positive"); } StringBuilder builder = new StringBuilder(); - builder.append(BITCOIN_SCHEME).append(COLON_SEPARATOR).append(address.toString()); + builder.append(BITCOIN_SCHEME).append(COLON_SEPARATOR).append(address); boolean questionMarkHasBeenOutput = false; diff --git a/core/src/test/java/com/google/bitcoin/uri/BitcoinURITest.java b/core/src/test/java/com/google/bitcoin/uri/BitcoinURITest.java index 7b859275..9653c5d8 100644 --- a/core/src/test/java/com/google/bitcoin/uri/BitcoinURITest.java +++ b/core/src/test/java/com/google/bitcoin/uri/BitcoinURITest.java @@ -51,14 +51,6 @@ public class BitcoinURITest { // example with spaces, ampersand and plus assertEquals("bitcoin:" + PRODNET_GOOD_ADDRESS + "?amount=12.34&label=Hello%20World&message=Mess%20%26%20age%20%2B%20hope", BitcoinURI.convertToBitcoinURI(goodAddress, Utils.toNanoCoins("12.34"), "Hello World", "Mess & age + hope")); - - // address null - try { - BitcoinURI.convertToBitcoinURI(null, Utils.toNanoCoins("0.1"), "hope", "glory"); - fail("Expecting IllegalArgumentException"); - } catch (IllegalArgumentException e) { - assertTrue(e.getMessage().contains("address")); - } // amount negative try {