InternetAddressTest.java 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Password Management Servlets (PWM)
  3. * http://www.pwm-project.org
  4. *
  5. * Copyright (c) 2006-2009 Novell, Inc.
  6. * Copyright (c) 2009-2018 The PWM Project
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. package javax.mail.internet;
  23. import org.junit.Assert;
  24. import org.junit.Test;
  25. /**
  26. * Tests to ensure the email address parsing from javax.mail.internet.InternetAddress is what we
  27. * expect.
  28. */
  29. public class InternetAddressTest {
  30. @Test(expected = Exception.class)
  31. public void testParse_null() throws AddressException {
  32. InternetAddress.parse(null, true);
  33. }
  34. @Test
  35. public void testParse_empty() throws AddressException {
  36. InternetAddress[] addresses = InternetAddress.parse("", true);
  37. Assert.assertEquals(0, addresses.length);
  38. }
  39. @Test
  40. public void testParse_single() throws AddressException {
  41. InternetAddress[] addresses = InternetAddress.parse("fred@flintstones.tv");
  42. Assert.assertEquals(1, addresses.length);
  43. Assert.assertEquals("fred@flintstones.tv", addresses[0].getAddress());
  44. }
  45. @Test
  46. public void testParse_multiple() throws AddressException {
  47. InternetAddress[] addresses = InternetAddress.parse("fred@flintstones.tv,wilma@flinstones.tv, barney@flintstones.tv, betty@flinstones.tv");
  48. Assert.assertEquals(4, addresses.length);
  49. Assert.assertEquals("fred@flintstones.tv", addresses[0].getAddress());
  50. Assert.assertEquals("wilma@flinstones.tv", addresses[1].getAddress());
  51. Assert.assertEquals("barney@flintstones.tv", addresses[2].getAddress());
  52. Assert.assertEquals("betty@flinstones.tv", addresses[3].getAddress());
  53. }
  54. @Test
  55. public void testParse_multipleWithCommasInName() throws AddressException {
  56. InternetAddress[] addresses = InternetAddress.parse("fred@flintstones.tv,wilma@flinstones.tv, \"Rubble, Barney\"@flintstones.tv, Betty Rubble <betty@flinstones.tv>");
  57. Assert.assertEquals(4, addresses.length);
  58. Assert.assertEquals("fred@flintstones.tv", addresses[0].getAddress());
  59. Assert.assertEquals("wilma@flinstones.tv", addresses[1].getAddress());
  60. Assert.assertEquals("\"Rubble, Barney\"@flintstones.tv", addresses[2].getAddress());
  61. Assert.assertEquals("betty@flinstones.tv", addresses[3].getAddress());
  62. }
  63. }