JAMES-2267 MimeMessageBuilder improvment: rely on Throwing rather than manual Preconditions.propagate
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/c53a7b92 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/c53a7b92 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/c53a7b92 Branch: refs/heads/improve-mailet-testing-experience-v1 Commit: c53a7b9236d5a638a00b2cf4b9b2d230f7ff69eb Parents: b860c64 Author: benwa <[email protected]> Authored: Tue Dec 19 10:20:02 2017 +0700 Committer: benwa <[email protected]> Committed: Fri Jan 5 09:13:50 2018 +0700 ---------------------------------------------------------------------- .../apache/mailet/base/test/MimeMessageBuilder.java | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/c53a7b92/mailet/base/src/test/java/org/apache/mailet/base/test/MimeMessageBuilder.java ---------------------------------------------------------------------- diff --git a/mailet/base/src/test/java/org/apache/mailet/base/test/MimeMessageBuilder.java b/mailet/base/src/test/java/org/apache/mailet/base/test/MimeMessageBuilder.java index b2b0794..31ef6f1 100644 --- a/mailet/base/src/test/java/org/apache/mailet/base/test/MimeMessageBuilder.java +++ b/mailet/base/src/test/java/org/apache/mailet/base/test/MimeMessageBuilder.java @@ -28,7 +28,6 @@ import java.util.Collection; import java.util.List; import java.util.Optional; import java.util.Properties; -import java.util.function.Function; import javax.activation.DataHandler; import javax.mail.BodyPart; @@ -48,7 +47,6 @@ import org.apache.commons.io.IOUtils; import com.github.fge.lambdas.Throwing; import com.github.steveash.guavate.Guavate; import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; public class MimeMessageBuilder { @@ -189,14 +187,6 @@ public class MimeMessageBuilder { } } - public static final Function<String, InternetAddress> TO_INTERNET_ADDRESS = value -> { - try { - return new InternetAddress(value); - } catch (AddressException e) { - throw Throwables.propagate(e); - } - }; - public static MimeMessage defaultMimeMessage() { return new MimeMessage(Session.getDefaultInstance(new Properties())); } @@ -284,21 +274,21 @@ public class MimeMessageBuilder { public MimeMessageBuilder addToRecipient(String... tos) throws AddressException { this.to.addAll(Arrays.stream(tos) - .map(TO_INTERNET_ADDRESS) + .map(Throwing.function(InternetAddress::new)) .collect(Guavate.toImmutableList())); return this; } public MimeMessageBuilder addCcRecipient(String... ccs) throws AddressException { this.cc.addAll(Arrays.stream(ccs) - .map(TO_INTERNET_ADDRESS) + .map(Throwing.function(InternetAddress::new)) .collect(Guavate.toImmutableList())); return this; } public MimeMessageBuilder addBccRecipient(String... bccs) throws AddressException { this.bcc.addAll(Arrays.stream(bccs) - .map(TO_INTERNET_ADDRESS) + .map(Throwing.function(InternetAddress::new)) .collect(Guavate.toImmutableList())); return this; } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
