@Test
  public void testCC() throws Exception {
    envVars.put("EMAIL_LIST", "[email protected], cc:[email protected], [email protected]");

    Set<InternetAddress> internetAddresses =
        emailRecipientUtils.convertRecipientString("$EMAIL_LIST", envVars);

    assertEquals(2, internetAddresses.size());
    assertTrue(internetAddresses.contains(new InternetAddress("*****@*****.**")));
    assertTrue(internetAddresses.contains(new InternetAddress("*****@*****.**")));

    internetAddresses =
        emailRecipientUtils.convertRecipientString("$EMAIL_LIST", envVars, EmailRecipientUtils.CC);

    assertEquals(1, internetAddresses.size());
    assertTrue(internetAddresses.contains(new InternetAddress("*****@*****.**")));
  }
  @Test
  public void testConvertRecipientList_emptyRecipientStringShouldResultInEmptyEmailList()
      throws AddressException, UnsupportedEncodingException {
    Set<InternetAddress> internetAddresses =
        emailRecipientUtils.convertRecipientString("", envVars);

    assertTrue(internetAddresses.isEmpty());
  }
  @Test
  public void testConvertRecipientList_singleRecipientShouldResultInOneEmailAddressInList()
      throws AddressException, UnsupportedEncodingException {
    Set<InternetAddress> internetAddresses =
        emailRecipientUtils.convertRecipientString("*****@*****.**", envVars);

    assertEquals(1, internetAddresses.size());
    assertTrue(internetAddresses.contains(new InternetAddress("*****@*****.**")));
  }
  @Test
  public void testUTF8() throws Exception {
    envVars.put("EMAIL_LIST", "[email protected], cc:[email protected], 愛嬋 <*****@*****.**>");

    Set<InternetAddress> internetAddresses =
        emailRecipientUtils.convertRecipientString("$EMAIL_LIST", envVars);
    assertEquals(2, internetAddresses.size());

    assertTrue(internetAddresses.contains(new InternetAddress("*****@*****.**")));
    InternetAddress addr = new InternetAddress("*****@*****.**");
    addr.setPersonal(MimeUtility.encodeWord("愛嬋", "UTF-8", "B"));
    assertTrue(internetAddresses.contains(addr));

    internetAddresses =
        emailRecipientUtils.convertRecipientString("$EMAIL_LIST", envVars, EmailRecipientUtils.CC);

    assertEquals(1, internetAddresses.size());
    assertTrue(internetAddresses.contains(new InternetAddress("*****@*****.**")));
  }
  @Test
  public void testConvertRecipientList_recipientStringShouldBeExpanded()
      throws AddressException, UnsupportedEncodingException {
    envVars.put("EMAIL_LIST", "*****@*****.**");

    Set<InternetAddress> internetAddresses =
        emailRecipientUtils.convertRecipientString("$EMAIL_LIST", envVars);

    assertEquals(1, internetAddresses.size());
    assertTrue(internetAddresses.contains(new InternetAddress("*****@*****.**")));
  }
  @Test
  public void testConvertRecipientList_emailAddressesShouldBeUnique()
      throws AddressException, UnsupportedEncodingException {
    Set<InternetAddress> internetAddresses =
        emailRecipientUtils.convertRecipientString(
            "[email protected], [email protected], [email protected]", envVars);

    assertEquals(2, internetAddresses.size());
    assertTrue(internetAddresses.contains(new InternetAddress("*****@*****.**")));
    assertTrue(internetAddresses.contains(new InternetAddress("*****@*****.**")));
  }
  @Test
  public void
      testConvertRecipientList_spaceSeparatedRecipientStringShouldResultInMultipleEmailAddressesInList()
          throws AddressException, UnsupportedEncodingException {
    Set<InternetAddress> internetAddresses =
        emailRecipientUtils.convertRecipientString(
            "[email protected] [email protected]", envVars);

    assertEquals(2, internetAddresses.size());
    assertTrue(internetAddresses.contains(new InternetAddress("*****@*****.**")));
    assertTrue(internetAddresses.contains(new InternetAddress("*****@*****.**")));
  }
  @Test
  public void testConvertRecipientList_defaultSuffix()
      throws AddressException, UnsupportedEncodingException {
    Mailer.descriptor().setDefaultSuffix("@gmail.com");
    InternetAddress[] internetAddresses =
        emailRecipientUtils
            .convertRecipientString("ashlux", envVars)
            .toArray(new InternetAddress[0]);

    assertEquals(1, internetAddresses.length);
    assertEquals("*****@*****.**", internetAddresses[0].getAddress());
  }
  @Test
  public void testConvertRecipientList_userName()
      throws AddressException, IOException, UnsupportedEncodingException {
    Mailer.descriptor().setDefaultSuffix("@gmail.com");
    User u = User.get("advantiss");
    u.setFullName("Peter Samoshkin");
    Mailer.UserProperty prop = new Mailer.UserProperty("*****@*****.**");
    u.addProperty(prop);

    InternetAddress[] internetAddresses =
        emailRecipientUtils
            .convertRecipientString("advantiss", envVars)
            .toArray(new InternetAddress[0]);

    assertEquals(1, internetAddresses.length);
    assertEquals("*****@*****.**", internetAddresses[0].getAddress());
  }