MailToUri { @Nonnull public static MailToUri get(final String input) throws IllegalArgumentException { return get(input, true); }  @Nullable static MailToUri parse(final String input); @Nonnull static MailToUri get(final String input); @Nonnull static MailToUri get(final String input, final boolean stripNames);  }
@Test public void standaloneEmail() { Assert.assertEquals( MailToUri.builder() .to(EmailAddress.builder().email(EXAMPLE_ADDRESS_ALPHA).build()) .build(), MailToUri.get(String.format("mailto:%s", EXAMPLE_ADDRESS_ALPHA)) ); }
@Test public void emailAndSubject() { Assert.assertEquals( MailToUri.builder() .to(EmailAddress.builder().email(EXAMPLE_ADDRESS_ALPHA).build()) .subject(EXAMPLE_SUBJECT) .build(), MailToUri.get(String.format("mailto:%s?subject=%s", EXAMPLE_ADDRESS_ALPHA, EXAMPLE_SUBJECT)) ); }
@Test public void emptyToAndSubject() { Assert.assertEquals( MailToUri.builder() .subject(EXAMPLE_SUBJECT) .build(), MailToUri.get(String.format("mailto:?subject=%s", EXAMPLE_SUBJECT)) ); }
@Test public void withCcAndBcc() { Assert.assertEquals( MailToUri.builder() .to(EmailAddress.builder().email(EXAMPLE_ADDRESS_ALPHA).build()) .cc(EmailAddress.builder().email(EXAMPLE_ADDRESS_BETA).build()) .cc(EmailAddress.builder().email(EXAMPLE_ADDRESS_GAMMA).build()) .bcc((EmailAddress.builder().email(EXAMPLE_ADDRESS_DELTA).build())) .subject(EXAMPLE_SUBJECT) .build(), MailToUri.get(String.format( "mailto:%s?cc=%s,%s&bcc=%s&subject=%s", EXAMPLE_ADDRESS_ALPHA, EXAMPLE_ADDRESS_BETA, EXAMPLE_ADDRESS_GAMMA, EXAMPLE_ADDRESS_DELTA, EXAMPLE_SUBJECT) ) ); }
@Test public void withInReplyTo() { Assert.assertEquals( MailToUri.builder() .to(EmailAddress.builder().email("list@example.com").build()) .inReplyTo("<3469A91.D10AF4C@example.com>") .build(), MailToUri.get("mailto:list@example.com?In-Reply-To=%3C3469A91.D10AF4C@example.com%3E") ); }
@Test public void specialCharacterEmailAddress() { Assert.assertEquals( MailToUri.builder() .to(EmailAddress.builder().email("\",\"@example.com").build()) .build(), MailToUri.get("mailto:\",\"@example.com") ); }
@Test(expected = IllegalArgumentException.class) public void unknownScheme() { MailToUri.get("xmpp:test@example.com"); }
@Test(expected = IllegalArgumentException.class) public void noScheme() { MailToUri.get("mailto"); }
@Test public void emptyQuery() { Assert.assertEquals( MailToUri.builder() .to(EmailAddress.builder().email(EXAMPLE_ADDRESS_ALPHA).build()) .build(), MailToUri.get(String.format("mailto:%s?", EXAMPLE_ADDRESS_ALPHA)) ); }
@Test public void emptyMailto() { Assert.assertEquals( MailToUri.builder() .build(), MailToUri.get("mailto:") ); }
@Test public void emptyMailtoEmptyQuery() { Assert.assertEquals( MailToUri.builder() .build(), MailToUri.get("mailto:?") ); }
@Test(expected = IllegalArgumentException.class) public void namedEmailAddressInMailto() throws UnsupportedEncodingException { MailToUri.get( String.format( "mailto:%s", URLEncoder.encode( EmailAddressUtil.toString( EmailAddress.builder().name("Alpha").email(EXAMPLE_ADDRESS_ALPHA).build() ), "UTF-8" ) ) ); }