CoinURI implements Serializable { public String getMessage() { return (String) parameterMap.get(FIELD_MESSAGE); } CoinURI(String uri);  CoinURI(@Nullable CoinType uriType, String input); CoinType getTypeRequired(); @Nullable CoinType getType(); boolean hasType(); @Nullable AbstractAddress getAddress(); Value getAmount(); String getLabel(); String getMessage(); String getPublicKey(); String getPaymentRequestUrl(); URI getAddressRequestUri(); boolean isAddressRequest(); URI getAddressRequestUriResponse(AbstractAddress address); URI getAddressRequestUriResponse(String address); Object getParameterByName(String name); @Override String toString(); static String convertToCoinURI(AbstractAddress address); static String convertToCoinURI(AbstractAddress address, @Nullable Value amount,
                                          @Nullable String label, @Nullable String message); static String convertToCoinURI(AbstractAddress address, @Nullable Value amount,
                                          @Nullable String label, @Nullable String message,
                                          @Nullable String pubkey); String toUriString(); static final String FIELD_MESSAGE; static final String FIELD_LABEL; static final String FIELD_AMOUNT; static final String FIELD_ADDRESS; static final String FIELD_PAYMENT_REQUEST_URL; static final String FIELD_ADDRESS_REQUEST_URI; static final String FIELD_NETWORK; static final String FIELD_PUBKEY; }
@Test public void testBad_BadSyntax() { try { testObject = new CoinURI(BitcoinMain.get(), BitcoinMain.get().getUriScheme() + "|" + MAINNET_GOOD_ADDRESS); fail("Expecting CoinURIParseException"); } catch (CoinURIParseException e) { assertTrue(e.getMessage().contains("Bad URI syntax")); } try { testObject = new CoinURI(BitcoinMain.get(), BitcoinMain.get().getUriScheme() + ":" + MAINNET_GOOD_ADDRESS + "\\"); fail("Expecting CoinURIParseException"); } catch (CoinURIParseException e) { assertTrue(e.getMessage().contains("Bad URI syntax")); } try { testObject = new CoinURI(BitcoinMain.get(), BitcoinMain.get().getUriScheme() + ":"); fail("Expecting CoinURIParseException"); } catch (CoinURIParseException e) { assertTrue(e.getMessage().contains("Bad URI syntax")); } }
@Test public void testBad_IncorrectAddressType() { try { testObject = new CoinURI(BitcoinTest.get(), BitcoinTest.get().getUriScheme() + ":" + MAINNET_GOOD_ADDRESS); fail("Expecting CoinURIParseException"); } catch (CoinURIParseException e) { assertTrue(e.getMessage().contains("Bad address")); } }
@Test public void testGood_Message() throws CoinURIParseException { testObject = new CoinURI(BitcoinMain.get(), BitcoinMain.get().getUriScheme() + ":" + MAINNET_GOOD_ADDRESS + "?message=Hello%20World"); assertEquals("Hello World", testObject.getMessage()); }
@Test public void testBad_Amount() throws CoinURIParseException { try { testObject = new CoinURI(BitcoinMain.get(), BitcoinMain.get().getUriScheme() + ":" + MAINNET_GOOD_ADDRESS + "?amount="); fail("Expecting CoinURIParseException"); } catch (CoinURIParseException e) { assertTrue(e.getMessage().contains("amount")); } try { testObject = new CoinURI(BitcoinMain.get(), BitcoinMain.get().getUriScheme() + ":" + MAINNET_GOOD_ADDRESS + "?amount=12X4"); fail("Expecting CoinURIParseException"); } catch (CoinURIParseException e) { assertTrue(e.getMessage().contains("amount")); } }
@Test public void testEmpty_Message() throws CoinURIParseException { assertNull(new CoinURI(BitcoinMain.get(), BitcoinMain.get().getUriScheme() + ":" + MAINNET_GOOD_ADDRESS + "?message=").getMessage()); }
@Test public void testBad_Duplicated() throws CoinURIParseException { try { testObject = new CoinURI(BitcoinMain.get(), BitcoinMain.get().getUriScheme() + ":" + MAINNET_GOOD_ADDRESS + "?address=aardvark"); fail("Expecting CoinURIParseException"); } catch (CoinURIParseException e) { assertTrue(e.getMessage().contains("address")); } }
@Test public void testBad_TooManyQuestionMarks() throws CoinURIParseException { try { testObject = new CoinURI(BitcoinMain.get(), BitcoinMain.get().getUriScheme() + ":" + MAINNET_GOOD_ADDRESS + "?label=aardvark?message=zebra"); fail("Expecting CoinURIParseException"); } catch (CoinURIParseException e) { assertTrue(e.getMessage().contains("Too many question marks")); } }