This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 52bf917a846521a41e8c515b4063808039a489f3 Author: Rene Cordier <[email protected]> AuthorDate: Thu Nov 7 14:54:26 2019 +0700 [Refactoring] Simplify MailAddressTest by fully using the power of assertj --- .../org/apache/james/core/MailAddressTest.java | 124 +++++++-------------- 1 file changed, 39 insertions(+), 85 deletions(-) diff --git a/core/src/test/java/org/apache/james/core/MailAddressTest.java b/core/src/test/java/org/apache/james/core/MailAddressTest.java index e2ed131..fb27066 100644 --- a/core/src/test/java/org/apache/james/core/MailAddressTest.java +++ b/core/src/test/java/org/apache/james/core/MailAddressTest.java @@ -102,100 +102,54 @@ class MailAddressTest { .isInstanceOf(AddressException.class); } - /** - * Test method for {@link MailAddress#MailAddress(java.lang.String, java.lang.String)}. - */ @Test - void testMailAddressStringString() { - try { - new MailAddress("local-part", "domain"); - } catch (AddressException e) { - assertThat(false).describedAs(e.getMessage()).isTrue(); - } - try { - MailAddress a = new MailAddress("local-part", "-domain"); - assertThat(true).describedAs(a.toString()).isFalse(); - } catch (AddressException e) { - assertThat(true).isTrue(); - } - } - - /** - * Test method for {@link MailAddress#MailAddress(javax.mail.internet.InternetAddress)}. - */ + void testGoodMailAddressWithLocalPartAndDomain() { + assertThatCode(() -> new MailAddress("local-part", "domain")) + .doesNotThrowAnyException(); + } + + @Test + void testBadMailAddressWithLocalPartAndDomain() { + Assertions.assertThatThrownBy(() -> new MailAddress("local-part", "-domain")) + .isInstanceOf(AddressException.class); + } + @Test void testMailAddressInternetAddress() { - try { - new MailAddress(new InternetAddress(GOOD_QUOTED_LOCAL_PART)); - } catch (AddressException e) { - System.out.println("AddressException" + e.getMessage()); - assertThat(false).describedAs(e.getMessage()).isTrue(); - } + assertThatCode(() -> new MailAddress(new InternetAddress(GOOD_QUOTED_LOCAL_PART))) + .doesNotThrowAnyException(); } - /** - * Test method for {@link MailAddress#getDomain()}. - */ @Test - void testGetDomain() { - try { - MailAddress a = new MailAddress(new InternetAddress(GOOD_ADDRESS)); - assertThat(a.getDomain()).isEqualTo(GOOD_DOMAIN); - } catch (AddressException e) { - System.out.println("AddressException" + e.getMessage()); - assertThat(false).describedAs(e.getMessage()).isTrue(); - } - } - - /** - * Test method for {@link MailAddress#getLocalPart()}. - */ + void testGetDomain() throws AddressException { + MailAddress a = new MailAddress(new InternetAddress(GOOD_ADDRESS)); + + assertThat(a.getDomain()).isEqualTo(GOOD_DOMAIN); + } + @Test - void testGetLocalPart() { - try { - MailAddress a = new MailAddress(new InternetAddress(GOOD_QUOTED_LOCAL_PART)); - assertThat(a.getLocalPart()).isEqualTo(GOOD_LOCAL_PART); - } catch (AddressException e) { - System.out.println("AddressException" + e.getMessage()); - assertThat(false).describedAs(e.getMessage()).isTrue(); - } - } - - /** - * Test method for {@link MailAddress#toString()}. - */ + void testGetLocalPart() throws AddressException { + MailAddress a = new MailAddress(new InternetAddress(GOOD_QUOTED_LOCAL_PART)); + + assertThat(a.getLocalPart()).isEqualTo(GOOD_LOCAL_PART); + } + @Test - void testToString() { - try { - MailAddress a = new MailAddress(new InternetAddress(GOOD_ADDRESS)); - assertThat(a.toString()).isEqualTo(GOOD_ADDRESS); - } catch (AddressException e) { - System.out.println("AddressException" + e.getMessage()); - assertThat(false).describedAs(e.getMessage()).isTrue(); - } - } - - /** - * Test method for {@link MailAddress#toInternetAddress()}. - */ + void testToString() throws AddressException { + MailAddress a = new MailAddress(new InternetAddress(GOOD_ADDRESS)); + + assertThat(a.toString()).isEqualTo(GOOD_ADDRESS); + } + @Test - void testToInternetAddress() { - try { - InternetAddress b = new InternetAddress(GOOD_ADDRESS); - MailAddress a = new MailAddress(b); - assertThat(a.toInternetAddress()).isEqualTo(b); - assertThat(a.toString()).isEqualTo(GOOD_ADDRESS); - } catch (AddressException e) { - System.out.println("AddressException" + e.getMessage()); - assertThat(false).describedAs(e.getMessage()).isTrue(); - } - } - - /** - * Test method for {@link MailAddress#equals(java.lang.Object)}. - * - * @throws AddressException - */ + void testToInternetAddress() throws AddressException { + InternetAddress b = new InternetAddress(GOOD_ADDRESS); + MailAddress a = new MailAddress(b); + + assertThat(a.toInternetAddress()).isEqualTo(b); + assertThat(a.toString()).isEqualTo(GOOD_ADDRESS); + } + @Test void testEqualsObject() throws AddressException { MailAddress a = new MailAddress(GOOD_ADDRESS); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
