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 fc19e0d333a38110a440a26c58bd561de0c8d6a1 Author: HoussemNasri <houssemnasri2...@gmail.com> AuthorDate: Fri Nov 15 14:53:50 2024 +0100 Use textblocks in ContactExtractorTest --- .../transport/mailets/ContactExtractorTest.java | 103 ++++++++++++++++----- 1 file changed, 80 insertions(+), 23 deletions(-) diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java index 57cd43eea9..d6880540b0 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/ContactExtractorTest.java @@ -121,7 +121,13 @@ public class ContactExtractorTest { .build(); mailet.init(mailetConfig); - String expectedMessage = "{\"userEmail\" : \"" + SENDER + "\", \"emails\" : [ \"" + TO + "\" ]}"; + String expectedMessage = + """ + { + "userEmail" : "%s", + "emails" : [ "%s" ] + } + """.formatted(SENDER, TO); mailet.service(mail); assertThat(mail.getAttribute(ATTRIBUTE_NAME)).hasValueSatisfying(json -> @@ -143,7 +149,13 @@ public class ContactExtractorTest { .build(); mailet.init(mailetConfig); - String expectedMessage = "{\"userEmail\" : \"" + SENDER + "\", \"emails\" : [ \"To <" + TO + ">\" ]}"; + String expectedMessage = + """ + { + "userEmail" : "%s", + "emails" : [ "To <%s>" ] + } + """.formatted(SENDER, TO); mailet.service(mail); assertThat(mail.getAttribute(ATTRIBUTE_NAME)).hasValueSatisfying(json -> @@ -165,7 +177,13 @@ public class ContactExtractorTest { .build(); mailet.init(mailetConfig); - String expectedMessage = "{\"userEmail\" : \"" + SENDER + "\", \"emails\" : [ \"Benoît TELLIER <tell...@linagora.com>\" ]}"; + String expectedMessage = + """ + { + "userEmail" : "%s", + "emails" : [ "Benoît TELLIER <tell...@linagora.com>" ] + } + """.formatted(SENDER); mailet.service(mail); assertThat(mail.getAttribute(ATTRIBUTE_NAME)).hasValueSatisfying(json -> @@ -174,11 +192,14 @@ public class ContactExtractorTest { @Test public void serviceShouldUnscrambleRecipientsWhenNameContainsSuperiors() throws Exception { - String rawMessage = "From: sen...@example.com\r\n" - + "To: =?UTF-8?Q?recip_>>_Fr=c3=a9d=c3=a9ric_RECIPIENT?= <frecipi...@example.com>\r\n" - + "Subject: extract this recipient please\r\n" - + "\r\n" - + "Please!"; + String rawMessage = + """ + From: sen...@example.com + To: =?UTF-8?Q?recip_>>_Fr=c3=a9d=c3=a9ric_RECIPIENT?= <frecipi...@example.com> + Subject: extract this recipient please + + Please! + """; MimeMessage message = MimeMessageUtil.mimeMessageFromString(rawMessage); FakeMail mail = FakeMail.builder() .name("mail") @@ -188,7 +209,13 @@ public class ContactExtractorTest { .build(); mailet.init(mailetConfig); - String expectedMessage = "{\"userEmail\" : \"" + SENDER + "\", \"emails\" : [ \"\\\"recip >> Frédéric RECIPIENT\\\" <frecipi...@example.com>\" ]}"; + String expectedMessage = + """ + { + "userEmail" : "%s", + "emails" : [ "\\"recip >> Frédéric RECIPIENT\\" <frecipi...@example.com>" ] + } + """.formatted(SENDER); mailet.service(mail); assertThat(mail.getAttribute(ATTRIBUTE_NAME)).hasValueSatisfying(json -> @@ -197,11 +224,14 @@ public class ContactExtractorTest { @Test public void serviceShouldParseMultipleRecipients() throws Exception { - String rawMessage = "From: sen...@example.com\r\n" - + "To: User 1 <us...@example.com>, =?UTF-8?Q?recip_>>_Fr=c3=a9d=c3=a9ric_RECIPIENT?= <frecipi...@example.com>\r\n" - + "Subject: extract this recipient please\r\n" - + "\r\n" - + "Please!"; + String rawMessage = + """ + From: sen...@example.com + To: User 1 <us...@example.com>, =?UTF-8?Q?recip_>>_Fr=c3=a9d=c3=a9ric_RECIPIENT?= <frecipi...@example.com> + Subject: extract this recipient please + + Please! + """; MimeMessage message = MimeMessageUtil.mimeMessageFromString(rawMessage); FakeMail mail = FakeMail.builder() .name("mail") @@ -211,7 +241,13 @@ public class ContactExtractorTest { .build(); mailet.init(mailetConfig); - String expectedMessage = "{\"userEmail\" : \"" + SENDER + "\", \"emails\" : [ \"User 1 <us...@example.com>\", \"\\\"recip >> Frédéric RECIPIENT\\\" <frecipi...@example.com>\" ]}"; + String expectedMessage = + """ + { + "userEmail" : "%s", + "emails" : [ "User 1 <us...@example.com>", "\\"recip >> Frédéric RECIPIENT\\" <frecipi...@example.com>" ] + } + """.formatted(SENDER); mailet.service(mail); assertThat(mail.getAttribute(ATTRIBUTE_NAME)).hasValueSatisfying(json -> @@ -220,11 +256,14 @@ public class ContactExtractorTest { @Test public void serviceShouldParseRecipientWithCommaInName() throws Exception { - String rawMessage = "From: sen...@example.com\r\n" - + "To: \"User, the first one\" <us...@example.com>\r\n" - + "Subject: extract this recipient please\r\n" - + "\r\n" - + "Please!"; + String rawMessage = + """ + From: sen...@example.com + To: "User, the first one" <us...@example.com> + Subject: extract this recipient please + + Please! + """; MimeMessage message = MimeMessageUtil.mimeMessageFromString(rawMessage); FakeMail mail = FakeMail.builder() .name("mail") @@ -234,7 +273,13 @@ public class ContactExtractorTest { .build(); mailet.init(mailetConfig); - String expectedMessage = "{\"userEmail\" : \"" + SENDER + "\", \"emails\" : [ \"\\\"User, the first one\\\" <us...@example.com>\" ]}"; + String expectedMessage = + """ + { + "userEmail" : "%s", + "emails" : [ "\\"User, the first one\\" <us...@example.com>" ] + } + """.formatted(SENDER); mailet.service(mail); assertThat(mail.getAttribute(ATTRIBUTE_NAME)).hasValueSatisfying(json -> @@ -255,7 +300,13 @@ public class ContactExtractorTest { .build(); mailet.init(mailetConfig); - String expectedMessage = "{\"userEmail\" : \"" + SENDER + "\", \"emails\" : [ \"To <" + TO + ">\" ]}"; + String expectedMessage = + """ + { + "userEmail" : "%s", + "emails" : [ "To <%s>" ] + } + """.formatted(SENDER, TO); mailet.service(mail); assertThat(mail.getAttribute(ATTRIBUTE_NAME)).hasValueSatisfying(json -> @@ -277,7 +328,13 @@ public class ContactExtractorTest { .build(); mailet.init(mailetConfig); - String expectedMessage = "{\"userEmail\" : \"" + SENDER + "\", \"emails\" : [ \"To <" + TO + ">\" ]}"; + String expectedMessage = + """ + { + "userEmail" : "%s", + "emails" : [ "To <%s>" ] + } + """.formatted(SENDER, TO); mailet.service(mail); assertThat(mail.getAttribute(ATTRIBUTE_NAME)).hasValueSatisfying(json -> --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org For additional commands, e-mail: notifications-h...@james.apache.org