MAILET-115 Move set methods from AbstractRedirect to MailModifier
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/fe3a35e8 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/fe3a35e8 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/fe3a35e8 Branch: refs/heads/master Commit: fe3a35e88c90f3f747a5f59218b3a8e75877d099 Parents: 03b2659 Author: Antoine Duprat <[email protected]> Authored: Tue Nov 15 15:58:29 2016 +0100 Committer: Benoit Tellier <[email protected]> Committed: Wed Jan 11 10:03:30 2017 +0700 ---------------------------------------------------------------------- .../org/apache/mailet/base/GenericMailet.java | 2 +- .../james/transport/mailets/DSNBounce.java | 22 +- .../mailets/redirect/AbstractRedirect.java | 174 ++------------- .../mailets/redirect/MailModifier.java | 218 +++++++++++++++++++ .../mailets/redirect/MailModifierTest.java | 68 ++++++ 5 files changed, 320 insertions(+), 164 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/fe3a35e8/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java ---------------------------------------------------------------------- diff --git a/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java b/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java index 741f3f7..20f8ca1 100644 --- a/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java +++ b/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java @@ -291,7 +291,7 @@ public abstract class GenericMailet implements Mailet, MailetConfig { /** * Utility method for obtaining a string representation of an array of Objects. */ - protected final String arrayToString(Object[] array) { + public final String arrayToString(Object[] array) { if (array == null) { return "null"; } http://git-wip-us.apache.org/repos/asf/james-project/blob/fe3a35e8/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java ---------------------------------------------------------------------- diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java index d505874..617af79 100755 --- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java +++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java @@ -34,6 +34,7 @@ import javax.mail.internet.MimeMessage; import org.apache.james.core.MailImpl; import org.apache.james.transport.mailets.redirect.AbstractRedirect; import org.apache.james.transport.mailets.redirect.InitParameters; +import org.apache.james.transport.mailets.redirect.MailModifier; import org.apache.james.transport.mailets.redirect.NotifyMailetInitParameters; import org.apache.james.transport.mailets.redirect.NotifyMailetsMessage; import org.apache.james.transport.mailets.redirect.SpecialAddress; @@ -201,14 +202,21 @@ public class DSNBounce extends AbstractRedirect { newMail.setMessage(createBounceMessage(originalMail)); // Set additional headers - setRecipients(newMail, getRecipients(originalMail), originalMail); - setTo(newMail, getTo(originalMail), originalMail); - getMimeMessageModifier(newMail, originalMail).replaceSubject(getSubjectPrefix(newMail, getInitParameters().getSubjectPrefix(), originalMail)); + MailModifier mailModifier = MailModifier.builder() + .mailet(this) + .mail(newMail) + .dns(dns) + .build(); + mailModifier.setRecipients(getRecipients(originalMail)); + mailModifier.setTo(getTo(originalMail)); + mailModifier.setSubjectPrefix(originalMail); + mailModifier.setReplyTo(getReplyTo(originalMail), originalMail); + mailModifier.setReversePath(getReversePath(originalMail), originalMail); + mailModifier.setIsReply(getInitParameters().isReply(), originalMail); + mailModifier.setSender(getSender(originalMail), originalMail); + newMail = mailModifier.getMail(); + newMail.getMessage().setHeader(RFC2822Headers.DATE, getDateHeader(originalMail)); - setReplyTo(newMail, getReplyTo(originalMail), originalMail); - setReversePath(newMail, getReversePath(originalMail), originalMail); - setSender(newMail, getSender(originalMail), originalMail); - setIsReply(newMail, getInitParameters().isReply(), originalMail); newMail.getMessage().saveChanges(); getMailetContext().sendMail(newMail); http://git-wip-us.apache.org/repos/asf/james-project/blob/fe3a35e8/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AbstractRedirect.java ---------------------------------------------------------------------- diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AbstractRedirect.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AbstractRedirect.java index eb44d13..8583685 100644 --- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AbstractRedirect.java +++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AbstractRedirect.java @@ -20,14 +20,11 @@ package org.apache.james.transport.mailets.redirect; import java.io.ByteArrayOutputStream; -import java.net.UnknownHostException; -import java.util.Date; import java.util.Enumeration; import java.util.List; import javax.inject.Inject; import javax.mail.BodyPart; -import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.internet.InternetAddress; @@ -40,11 +37,9 @@ import org.apache.james.core.MimeMessageUtil; import org.apache.james.dnsservice.api.DNSService; import org.apache.james.transport.mailets.Redirect; import org.apache.james.transport.mailets.utils.MimeMessageModifier; -import org.apache.james.transport.util.MailAddressUtils; import org.apache.james.transport.util.SpecialAddressesUtils; import org.apache.mailet.Mail; import org.apache.mailet.MailAddress; -import org.apache.mailet.base.DateFormats; import org.apache.mailet.base.GenericMailet; import org.apache.mailet.base.RFC2822Headers; @@ -200,19 +195,6 @@ public abstract class AbstractRedirect extends GenericMailet { protected abstract List<MailAddress> getRecipients(Mail originalMail) throws MessagingException; /** - * Sets the recipients of <i>newMail</i> to <i>recipients</i>. If the - * requested value is null does nothing. Is a "setX(Mail, Tx, Mail)" method. - */ - protected void setRecipients(Mail newMail, List<MailAddress> recipients, Mail originalMail) { - if (!recipients.isEmpty()) { - newMail.setRecipients(recipients); - if (getInitParameters().isDebug()) { - log("recipients set to: " + arrayToString(recipients.toArray())); - } - } - } - - /** * Gets the <code>to</code> property. Returns the "To:" recipients of the * new message. or null if no change is requested. Is a "getX()" method. * @@ -253,20 +235,6 @@ public abstract class AbstractRedirect extends GenericMailet { } /** - * Sets the "To:" header of <i>newMail</i> to <i>to</i>. If the requested - * value is null does nothing. Is a "setX(Mail, Tx, Mail)" method. - */ - protected void setTo(Mail newMail, List<MailAddress> mailAddresses, Mail originalMail) throws MessagingException { - if (mailAddresses != null) { - InternetAddress[] internetAddresses = MailAddressUtils.toInternetAddressArray(mailAddresses); - newMail.getMessage().setRecipients(Message.RecipientType.TO, internetAddresses); - if (getInitParameters().isDebug()) { - log("apparentlyTo set to: " + internetAddresses); - } - } - } - - /** * Gets the <code>replyto</code> property. Returns the Reply-To address of * the new message, or null if no change is requested. Is a "getX()" method. * @@ -297,30 +265,6 @@ public abstract class AbstractRedirect extends GenericMailet { } /** - * <p> - * Sets the "Reply-To:" header of <i>newMail</i> to <i>replyTo</i>. - * </p> - * If the requested value is <code>SpecialAddress.NULL</code> will remove - * the "Reply-To:" header. If the requested value is null does nothing.</p> - * Is a "setX(Mail, Tx, Mail)" method. - */ - protected void setReplyTo(Mail newMail, MailAddress replyTo, Mail originalMail) throws MessagingException { - if (replyTo != null) { - if (replyTo.equals(SpecialAddress.NULL)) { - newMail.getMessage().setReplyTo(null); - if (getInitParameters().isDebug()) { - log("replyTo set to: null"); - } - } else { - newMail.getMessage().setReplyTo(new InternetAddress[] { replyTo.toInternetAddress() }); - if (getInitParameters().isDebug()) { - log("replyTo set to: " + replyTo); - } - } - } - } - - /** * Gets the <code>reversePath</code> property. Returns the reverse-path of * the new message, or null if no change is requested. Is a "getX()" method. * @@ -346,28 +290,6 @@ public abstract class AbstractRedirect extends GenericMailet { protected abstract MailAddress getReversePath(Mail originalMail) throws MessagingException; /** - * Sets the "reverse-path" of <i>newMail</i> to <i>reversePath</i>. If the - * requested value is <code>SpecialAddress.NULL</code> sets it to "<>". If - * the requested value is null does nothing. Is a "setX(Mail, Tx, Mail)" - * method. - */ - protected void setReversePath(MailImpl newMail, MailAddress reversePath, Mail originalMail) { - if (reversePath != null) { - if (reversePath.equals(SpecialAddress.NULL)) { - newMail.setSender(null); - if (getInitParameters().isDebug()) { - log("reversePath set to: null"); - } - } else { - newMail.setSender(reversePath); - if (getInitParameters().isDebug()) { - log("reversePath set to: " + reversePath); - } - } - } - } - - /** * Gets the <code>sender</code> property. Returns the new sender as a * MailAddress, or null if no change is requested. Is a "getX()" method. * @@ -401,20 +323,6 @@ public abstract class AbstractRedirect extends GenericMailet { } /** - * Sets the "From:" header of <i>newMail</i> to <i>sender</i>. If the - * requested value is null does nothing. Is a "setX(Mail, Tx, Mail)" method. - */ - protected void setSender(Mail newMail, MailAddress sender, Mail originalMail) throws MessagingException { - if (sender != null) { - newMail.getMessage().setFrom(sender.toInternetAddress()); - - if (getInitParameters().isDebug()) { - log("sender set to: " + sender); - } - } - } - - /** * Builds the subject of <i>newMail</i> appending the subject of * <i>originalMail</i> to <i>subjectPrefix</i>. Is a "setX(Mail, Tx, Mail)" * method. @@ -422,22 +330,6 @@ public abstract class AbstractRedirect extends GenericMailet { protected abstract Optional<String> getSubjectPrefix(Mail newMail, String subjectPrefix, Mail originalMail) throws MessagingException; /** - * Sets the "In-Reply-To:" header of <i>newMail</i> to the "Message-Id:" of - * <i>originalMail</i>, if <i>isReply</i> is true. - */ - protected void setIsReply(Mail newMail, boolean isReply, Mail originalMail) throws MessagingException { - if (isReply) { - String messageId = originalMail.getMessage().getMessageID(); - if (messageId != null) { - newMail.getMessage().setHeader(RFC2822Headers.IN_REPLY_TO, messageId); - if (getInitParameters().isDebug()) { - log("IN_REPLY_TO set to: " + messageId); - } - } - } - } - - /** * Mailet initialization routine. Will setup static values for each "x" * initialization parameter in config.xml, using getX(), if * {@link #isStatic()} returns true. @@ -475,8 +367,13 @@ public abstract class AbstractRedirect extends GenericMailet { // the original untouched MailImpl newMail = new MailImpl(originalMail); try { - setRemoteAddr(newMail); - setRemoteHost(newMail); + MailModifier mailModifier = MailModifier.builder() + .mailet(this) + .mail(newMail) + .dns(dns) + .build(); + mailModifier.setRemoteAddr(); + mailModifier.setRemoteHost(); if (getInitParameters().isDebug()) { log("New mail - sender: " + newMail.getSender() + ", recipients: " + arrayToString(newMail.getRecipients().toArray()) + ", name: " + newMail.getName() + ", remoteHost: " + newMail.getRemoteHost() + ", remoteAddr: " + newMail.getRemoteAddr() + ", state: " + newMail.getState() @@ -515,31 +412,22 @@ public abstract class AbstractRedirect extends GenericMailet { // Set additional headers - setRecipients(newMail, getRecipients(originalMail), originalMail); - - setTo(newMail, getTo(originalMail), originalMail); - - getMimeMessageModifier(newMail, originalMail).replaceSubject(getSubjectPrefix(newMail, getInitParameters().getSubjectPrefix(), originalMail)); - - if (newMail.getMessage().getHeader(RFC2822Headers.DATE) == null) { - newMail.getMessage().setHeader(RFC2822Headers.DATE, DateFormats.RFC822_DATE_FORMAT.format(new Date())); + mailModifier.setRecipients(getRecipients(originalMail)); + mailModifier.setTo(getTo(originalMail)); + mailModifier.setSubjectPrefix(originalMail); + mailModifier.setReplyTo(getReplyTo(originalMail), originalMail); + mailModifier.setReversePath(getReversePath(originalMail), originalMail); + mailModifier.setIsReply(getInitParameters().isReply(), originalMail); + mailModifier.setSender(getSender(originalMail), originalMail); + mailModifier.initializeDateIfNotPresent(); + if (keepMessageId) { + mailModifier.setMessageId(originalMail); } - - setReplyTo(newMail, getReplyTo(originalMail), originalMail); - - setReversePath(newMail, getReversePath(originalMail), originalMail); - - setSender(newMail, getSender(originalMail), originalMail); - - setIsReply(newMail, getInitParameters().isReply(), originalMail); + newMail = mailModifier.getMail(); newMail.getMessage().saveChanges(); newMail.removeAllAttributes(); - if (keepMessageId) { - setMessageId(newMail, originalMail); - } - if (senderDomainIsValid(newMail)) { // Send it off... getMailetContext().sendMail(newMail); @@ -559,22 +447,6 @@ public abstract class AbstractRedirect extends GenericMailet { protected abstract MimeMessageModifier getMimeMessageModifier(Mail newMail, Mail originalMail) throws MessagingException; - private void setRemoteAddr(MailImpl newMail) { - try { - newMail.setRemoteAddr(dns.getLocalHost().getHostAddress()); - } catch (UnknownHostException e) { - newMail.setRemoteAddr("127.0.0.1"); - } - } - - private void setRemoteHost(MailImpl newMail) { - try { - newMail.setRemoteHost(dns.getLocalHost().getHostName()); - } catch (UnknownHostException e) { - newMail.setRemoteHost("localhost"); - } - } - /** * Utility method for obtaining a string representation of a Message's * headers @@ -752,16 +624,6 @@ public abstract class AbstractRedirect extends GenericMailet { } } - private void setMessageId(Mail newMail, Mail originalMail) throws MessagingException { - String messageId = originalMail.getMessage().getMessageID(); - if (messageId != null) { - newMail.getMessage().setHeader(RFC2822Headers.MESSAGE_ID, messageId); - if (getInitParameters().isDebug()) { - log("MESSAGE_ID restored to: " + messageId); - } - } - } - /** * <p> * Checks if a sender domain of <i>mail</i> is valid. http://git-wip-us.apache.org/repos/asf/james-project/blob/fe3a35e8/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java ---------------------------------------------------------------------- diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java new file mode 100644 index 0000000..407836c --- /dev/null +++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java @@ -0,0 +1,218 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.transport.mailets.redirect; + +import java.net.UnknownHostException; +import java.util.Date; +import java.util.List; + +import javax.mail.Message; +import javax.mail.MessagingException; +import javax.mail.internet.InternetAddress; + +import org.apache.james.core.MailImpl; +import org.apache.james.dnsservice.api.DNSService; +import org.apache.james.transport.util.MailAddressUtils; +import org.apache.mailet.Mail; +import org.apache.mailet.MailAddress; +import org.apache.mailet.base.DateFormats; +import org.apache.mailet.base.RFC2822Headers; + +import com.google.common.base.Preconditions; + +public class MailModifier { + + private static final String LOCAHOST = "127.0.0.1"; + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + private AbstractRedirect mailet; + private MailImpl mail; + private DNSService dns; + + private Builder() { + } + + public Builder mailet(AbstractRedirect mailet) { + this.mailet = mailet; + return this; + } + + public Builder mail(MailImpl mail) { + this.mail = mail; + return this; + } + + public Builder dns(DNSService dns) { + this.dns = dns; + return this; + } + + public MailModifier build() { + Preconditions.checkNotNull(mailet, "'mailet' is mandatory"); + Preconditions.checkNotNull(mail, "'mail' is mandatory"); + Preconditions.checkNotNull(dns, "'dns' is mandatory"); + return new MailModifier(mailet, mail, dns); + } + } + + private final AbstractRedirect mailet; + private final MailImpl mail; + private final DNSService dns; + + private MailModifier(AbstractRedirect mailet, MailImpl mail, DNSService dns) { + this.mailet = mailet; + this.mail = mail; + this.dns = dns; + } + + public void setRemoteAddr() { + try { + mail.setRemoteAddr(dns.getLocalHost().getHostAddress()); + } catch (UnknownHostException e) { + mail.setRemoteAddr(LOCAHOST); + } + } + + public void setRemoteHost() { + try { + mail.setRemoteHost(dns.getLocalHost().getHostName()); + } catch (UnknownHostException e) { + mail.setRemoteHost("localhost"); + } + } + + public void setRecipients(List<MailAddress> recipients) { + if (!recipients.isEmpty()) { + mail.setRecipients(recipients); + if (mailet.getInitParameters().isDebug()) { + mailet.log("recipients set to: " + mailet.arrayToString(recipients.toArray())); + } + } + } + + public void setTo(List<MailAddress> mailAddresses) throws MessagingException { + if (mailAddresses != null) { + InternetAddress[] internetAddresses = MailAddressUtils.toInternetAddressArray(mailAddresses); + mail.getMessage().setRecipients(Message.RecipientType.TO, internetAddresses); + if (mailet.getInitParameters().isDebug()) { + mailet.log("apparentlyTo set to: " + internetAddresses); + } + } + } + + public void setSubjectPrefix(Mail originalMail) throws MessagingException { + mailet.getMimeMessageModifier(mail, originalMail) + .replaceSubject(mailet.getSubjectPrefix(mail, mailet.getInitParameters().getSubjectPrefix(), originalMail)); + } + + /** + * <p> + * Sets the "Reply-To:" header of <i>newMail</i> to <i>replyTo</i>. + * </p> + * If the requested value is <code>SpecialAddress.NULL</code> will remove + * the "Reply-To:" header. If the requested value is null does nothing.</p> + */ + public void setReplyTo(MailAddress replyTo, Mail originalMail) throws MessagingException { + if (replyTo != null) { + if (replyTo.equals(SpecialAddress.NULL)) { + mail.getMessage().setReplyTo(null); + if (mailet.getInitParameters().isDebug()) { + mailet.log("replyTo set to: null"); + } + } else { + mail.getMessage().setReplyTo(new InternetAddress[] { replyTo.toInternetAddress() }); + if (mailet.getInitParameters().isDebug()) { + mailet.log("replyTo set to: " + replyTo); + } + } + } + } + + /** + * Sets the "reverse-path" of <i>newMail</i> to <i>reversePath</i>. If the + * requested value is <code>SpecialAddress.NULL</code> sets it to "<>". If + * the requested value is null does nothing. + */ + public void setReversePath(MailAddress reversePath, Mail originalMail) { + if (reversePath != null) { + if (reversePath.equals(SpecialAddress.NULL)) { + mail.setSender(null); + if (mailet.getInitParameters().isDebug()) { + mailet.log("reversePath set to: null"); + } + } else { + mail.setSender(reversePath); + if (mailet.getInitParameters().isDebug()) { + mailet.log("reversePath set to: " + reversePath); + } + } + } + } + + /** + * Sets the "In-Reply-To:" header of <i>newMail</i> to the "Message-Id:" of + * <i>originalMail</i>, if <i>isReply</i> is true. + */ + public void setIsReply(boolean isReply, Mail originalMail) throws MessagingException { + if (isReply) { + String messageId = originalMail.getMessage().getMessageID(); + if (messageId != null) { + mail.getMessage().setHeader(RFC2822Headers.IN_REPLY_TO, messageId); + if (mailet.getInitParameters().isDebug()) { + mailet.log("IN_REPLY_TO set to: " + messageId); + } + } + } + } + + public void setSender(MailAddress sender, Mail originalMail) throws MessagingException { + if (sender != null) { + mail.getMessage().setFrom(sender.toInternetAddress()); + + if (mailet.getInitParameters().isDebug()) { + mailet.log("sender set to: " + sender); + } + } + } + + public void initializeDateIfNotPresent() throws MessagingException { + if (mail.getMessage().getHeader(RFC2822Headers.DATE) == null) { + mail.getMessage().setHeader(RFC2822Headers.DATE, DateFormats.RFC822_DATE_FORMAT.format(new Date())); + } + } + + public void setMessageId(Mail originalMail) throws MessagingException { + String messageId = originalMail.getMessage().getMessageID(); + if (messageId != null) { + mail.getMessage().setHeader(RFC2822Headers.MESSAGE_ID, messageId); + if (mailet.getInitParameters().isDebug()) { + mailet.log("MESSAGE_ID restored to: " + messageId); + } + } + } + + public MailImpl getMail() { + return mail; + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/fe3a35e8/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/MailModifierTest.java ---------------------------------------------------------------------- diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/MailModifierTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/MailModifierTest.java new file mode 100644 index 0000000..335e968 --- /dev/null +++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/MailModifierTest.java @@ -0,0 +1,68 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.transport.mailets.redirect; + +import static org.mockito.Mockito.mock; + +import org.apache.james.core.MailImpl; +import org.apache.james.dnsservice.api.DNSService; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class MailModifierTest { + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Test + public void buildShouldThrowWhenMailetIsNull() { + expectedException.expect(NullPointerException.class); + expectedException.expectMessage("'mailet' is mandatory"); + MailModifier.builder().build(); + } + + @Test + public void buildShouldThrowWhenMailIsNull() { + expectedException.expect(NullPointerException.class); + expectedException.expectMessage("'mail' is mandatory"); + MailModifier.builder() + .mailet(mock(AbstractRedirect.class)) + .build(); + } + + @Test + public void buildShouldThrowWhenDNSIsNull() { + expectedException.expect(NullPointerException.class); + expectedException.expectMessage("'dns' is mandatory"); + MailModifier.builder() + .mailet(mock(AbstractRedirect.class)) + .mail(mock(MailImpl.class)) + .build(); + } + + @Test + public void buildShouldWorkWhenEverythingProvided() { + MailModifier.builder() + .mailet(mock(AbstractRedirect.class)) + .mail(mock(MailImpl.class)) + .dns(mock(DNSService.class)) + .build(); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
