MAILET-124 Adding a MailAddress fixture, to ease tests with matchers
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/5636d897 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/5636d897 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/5636d897 Branch: refs/heads/master Commit: 5636d8974229e21654ba2924b8ab8f63a3dcb40d Parents: 3a5c2af Author: Benoit Tellier <btell...@linagora.com> Authored: Thu Sep 15 11:55:11 2016 +0200 Committer: Benoit Tellier <btell...@linagora.com> Committed: Thu Sep 15 12:05:20 2016 +0200 ---------------------------------------------------------------------- .../apache/mailet/base/MailAddressFixture.java | 46 +++++++++++++++ .../org/apache/mailet/base/test/FakeMail.java | 9 +++ .../james/transport/matchers/AllTest.java | 15 ++--- .../transport/matchers/FetchedFromTest.java | 18 +++--- .../transport/matchers/HasAttachmentTest.java | 11 ++-- .../transport/matchers/HostIsLocalTest.java | 52 ++++++++--------- .../james/transport/matchers/HostIsTest.java | 52 ++++++++--------- .../matchers/IsSingleRecipientTest.java | 14 ++--- .../transport/matchers/RelayLimitTest.java | 17 +++--- .../transport/matchers/SenderIsNullTest.java | 9 ++- .../transport/matchers/SizeGreaterThanTest.java | 59 +++++++++++++------- 11 files changed, 171 insertions(+), 131 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/5636d897/mailet/base/src/test/java/org/apache/mailet/base/MailAddressFixture.java ---------------------------------------------------------------------- diff --git a/mailet/base/src/test/java/org/apache/mailet/base/MailAddressFixture.java b/mailet/base/src/test/java/org/apache/mailet/base/MailAddressFixture.java new file mode 100644 index 0000000..f98a160 --- /dev/null +++ b/mailet/base/src/test/java/org/apache/mailet/base/MailAddressFixture.java @@ -0,0 +1,46 @@ +/**************************************************************** + * 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.mailet.base; + +import javax.mail.internet.AddressException; + +import org.apache.mailet.MailAddress; + +import com.google.common.base.Throwables; + +public class MailAddressFixture { + + + public static final String JAMES_APACHE_ORG = "james.apache.org"; + public static final String JAMES2_APACHE_ORG = "james2.apache.org"; + + public static final MailAddress ANY_AT_JAMES = createMailAddress("any@" + JAMES_APACHE_ORG); + public static final MailAddress OTHER_AT_JAMES = createMailAddress("other@" + JAMES_APACHE_ORG); + public static final MailAddress ANY_AT_JAMES2 = createMailAddress("any@" + JAMES2_APACHE_ORG); + public static final MailAddress OTHER_AT_JAMES2 = createMailAddress("other@" + JAMES2_APACHE_ORG); + + private static MailAddress createMailAddress(String mailAddress) { + try { + return new MailAddress(mailAddress); + } catch (AddressException e) { + throw Throwables.propagate(e); + } + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/5636d897/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java ---------------------------------------------------------------------- diff --git a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java index 77a1288..7e42940 100644 --- a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java +++ b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java @@ -63,11 +63,17 @@ public class FakeMail implements Mail { public static class Builder { private Optional<String> fileName = Optional.absent(); + private Optional<Long> size = Optional.absent(); private Optional<MimeMessage> mimeMessage = Optional.absent(); private List<MailAddress> recipients = new ArrayList<MailAddress>(); private MailAddress sender; private String remoteAddr; + public Builder size(long size) { + this.size = Optional.of(size); + return this; + } + public Builder fileName(String fileName) { this.fileName = Optional.of(fileName); return this; @@ -112,6 +118,9 @@ public class FakeMail implements Mail { if (mimeMessage.isPresent()) { mail.setMessage(mimeMessage.get()); } + if (size.isPresent()) { + mail.setMessageSize(size.get()); + } mail.setSender(sender); mail.setRecipients(recipients); mail.setRemoteAddr(remoteAddr); http://git-wip-us.apache.org/repos/asf/james-project/blob/5636d897/mailet/standard/src/test/java/org/apache/james/transport/matchers/AllTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/AllTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/AllTest.java index b3c207f..f46f1b2 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/AllTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/AllTest.java @@ -20,11 +20,13 @@ package org.apache.james.transport.matchers; +import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES; +import static org.apache.mailet.base.MailAddressFixture.OTHER_AT_JAMES; import static org.assertj.core.api.Assertions.assertThat; import javax.mail.MessagingException; -import org.apache.mailet.MailAddress; +import org.apache.mailet.Mail; import org.apache.mailet.Matcher; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMailContext; @@ -35,8 +37,6 @@ import org.junit.Test; public class AllTest { private Matcher matcher; - private MailAddress mailAddress1; - private MailAddress mailAddress2; @Before public void setupMatcher() throws MessagingException { @@ -44,18 +44,15 @@ public class AllTest { FakeMatcherConfig mci = new FakeMatcherConfig("All", FakeMailContext.defaultContext()); matcher.init(mci); - - mailAddress1 = new MailAddress("m...@apache.org"); - mailAddress2 = new MailAddress("y...@apache.org"); } @Test public void testAllRecipientsReturned() throws MessagingException { - FakeMail mockedMail = FakeMail.builder() - .recipients(mailAddress1, mailAddress2) + Mail mail = FakeMail.builder() + .recipients(ANY_AT_JAMES, OTHER_AT_JAMES) .build(); - assertThat(matcher.match(mockedMail)).containsExactly(mailAddress1, mailAddress2); + assertThat(matcher.match(mail)).containsExactly(OTHER_AT_JAMES, OTHER_AT_JAMES); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/5636d897/mailet/standard/src/test/java/org/apache/james/transport/matchers/FetchedFromTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/FetchedFromTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/FetchedFromTest.java index 6250162..2f8f0e1 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/FetchedFromTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/FetchedFromTest.java @@ -19,11 +19,12 @@ package org.apache.james.transport.matchers; +import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES; +import static org.apache.mailet.base.MailAddressFixture.OTHER_AT_JAMES; import static org.assertj.core.api.Assertions.assertThat; import javax.mail.MessagingException; -import org.apache.mailet.MailAddress; import org.apache.mailet.Matcher; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMailContext; @@ -37,33 +38,28 @@ public class FetchedFromTest { private static final String WRONG_HEADER_VALUE = "defaultHeaderValue"; private Matcher matcher; - private MailAddress mailAddress1; - private MailAddress mailAddress2; @Before public void setUp() throws MessagingException { matcher = new FetchedFrom(); FakeMatcherConfig matcherConfig = new FakeMatcherConfig("FetchedFrom=" + EXPECTED_HEADER_VALUE, FakeMailContext.defaultContext()); matcher.init(matcherConfig); - - mailAddress1 = new MailAddress("m...@apache.org"); - mailAddress2 = new MailAddress("y...@apache.org"); } @Test public void matchShouldReturnMatchWhenFetchFromHeaderHoldsRightValue() throws MessagingException { FakeMail fakeMail = FakeMail.builder() - .recipients(mailAddress1, mailAddress2) + .recipients(ANY_AT_JAMES, OTHER_AT_JAMES) .mimeMessage(MailUtil.createMimeMessage(FetchedFrom.X_FETCHED_FROM, EXPECTED_HEADER_VALUE)) .build(); - assertThat(matcher.match(fakeMail)).containsExactly(mailAddress1, mailAddress2); + assertThat(matcher.match(fakeMail)).containsExactly(ANY_AT_JAMES, OTHER_AT_JAMES); } @Test public void matchShouldReturnNotMatchWhenFetchFromHeaderHoldsWrongValue() throws MessagingException { FakeMail fakeMail = FakeMail.builder() - .recipients(mailAddress1, mailAddress2) + .recipients(ANY_AT_JAMES, OTHER_AT_JAMES) .mimeMessage(MailUtil.createMimeMessage(FetchedFrom.X_FETCHED_FROM, WRONG_HEADER_VALUE)) .build(); @@ -73,7 +69,7 @@ public class FetchedFromTest { @Test public void matchShouldRemoveMatchingHeaders() throws MessagingException { FakeMail fakeMail = FakeMail.builder() - .recipients(mailAddress1, mailAddress2) + .recipients(ANY_AT_JAMES, OTHER_AT_JAMES) .mimeMessage(MailUtil.createMimeMessage(FetchedFrom.X_FETCHED_FROM, EXPECTED_HEADER_VALUE)) .build(); @@ -85,7 +81,7 @@ public class FetchedFromTest { @Test public void matchShouldNotRemoveNonMatchingHeaders() throws MessagingException { FakeMail fakeMail = FakeMail.builder() - .recipients(mailAddress1, mailAddress2) + .recipients(ANY_AT_JAMES, OTHER_AT_JAMES) .mimeMessage(MailUtil.createMimeMessage(FetchedFrom.X_FETCHED_FROM, WRONG_HEADER_VALUE)) .build(); http://git-wip-us.apache.org/repos/asf/james-project/blob/5636d897/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasAttachmentTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasAttachmentTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasAttachmentTest.java index 0d47689..cc4b698 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasAttachmentTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasAttachmentTest.java @@ -19,6 +19,7 @@ package org.apache.james.transport.matchers; +import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -31,13 +32,10 @@ import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; import org.apache.mailet.Mail; -import org.apache.mailet.MailAddress; import org.apache.mailet.base.test.FakeMail; import org.junit.Before; import org.junit.Test; -import com.google.common.collect.ImmutableList; - public class HasAttachmentTest { private HasAttachment testee; @@ -49,9 +47,10 @@ public class HasAttachmentTest { testee = new HasAttachment(); mimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties())); - mail = new FakeMail(); - mail.setRecipients(ImmutableList.of(new MailAddress("m...@james.apache.org"))); - mail.setMessage(mimeMessage); + mail = FakeMail.builder() + .recipient(ANY_AT_JAMES) + .mimeMessage(mimeMessage) + .build(); } @Test http://git-wip-us.apache.org/repos/asf/james-project/blob/5636d897/mailet/standard/src/test/java/org/apache/james/transport/matchers/HostIsLocalTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HostIsLocalTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HostIsLocalTest.java index 7ead911..c8905dc 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HostIsLocalTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HostIsLocalTest.java @@ -20,13 +20,19 @@ package org.apache.james.transport.matchers; +import static org.apache.mailet.base.MailAddressFixture.JAMES2_APACHE_ORG; +import static org.apache.mailet.base.MailAddressFixture.JAMES_APACHE_ORG; +import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES; +import static org.apache.mailet.base.MailAddressFixture.OTHER_AT_JAMES; +import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES2; +import static org.apache.mailet.base.MailAddressFixture.OTHER_AT_JAMES2; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import javax.mail.MessagingException; -import org.apache.mailet.MailAddress; +import org.apache.mailet.Mail; import org.apache.mailet.MailetContext; import org.apache.mailet.Matcher; import org.apache.mailet.base.test.FakeMail; @@ -34,20 +40,12 @@ import org.apache.mailet.base.test.FakeMatcherConfig; import org.junit.Before; import org.junit.Test; -import com.google.common.collect.ImmutableList; - public class HostIsLocalTest { - public static final String JAMES_APACHE_ORG = "james.apache.org"; - public static final String JAMES2_APACHE_ORG = "james2.apache.org"; - - private FakeMail mockedMail; private Matcher matcher; @Before public void setUp() throws Exception { - mockedMail = new FakeMail(); - MailetContext mailContext = mock(MailetContext.class); when(mailContext.isLocalServer(JAMES_APACHE_ORG)).thenReturn(true); when(mailContext.isLocalServer(JAMES2_APACHE_ORG)).thenReturn(false); @@ -57,36 +55,30 @@ public class HostIsLocalTest { matcher.init(mci); } - // test if all recipients get returned as matched @Test - public void testHostIsMatchedAllRecipients() throws MessagingException { - MailAddress mailAddress1 = new MailAddress("test@" + JAMES_APACHE_ORG); - MailAddress mailAddress2 = new MailAddress("test2@" + JAMES_APACHE_ORG); - mockedMail.setRecipients(ImmutableList.of( - mailAddress1, - mailAddress2)); + public void shouldMatchAddressesFromLocalDomain() throws MessagingException { + Mail mail = FakeMail.builder() + .recipients(ANY_AT_JAMES, OTHER_AT_JAMES) + .build(); - assertThat( matcher.match(mockedMail)).containsExactly(mailAddress1, mailAddress2); + assertThat( matcher.match(mail)).containsExactly(ANY_AT_JAMES, OTHER_AT_JAMES); } - // test if one recipients get returned as matched @Test - public void testHostIsMatchedOneRecipient() throws MessagingException { - MailAddress matchingAddress = new MailAddress("test2@" +JAMES_APACHE_ORG); - mockedMail.setRecipients(ImmutableList.of( - new MailAddress("test@" + JAMES2_APACHE_ORG), - matchingAddress)); + public void shouldMatchOnlyAddressesFromLocalDomain() throws MessagingException { + Mail mail = FakeMail.builder() + .recipients(ANY_AT_JAMES, ANY_AT_JAMES2) + .build(); - assertThat( matcher.match(mockedMail)).containsExactly(matchingAddress); + assertThat( matcher.match(mail)).containsExactly(ANY_AT_JAMES); } - // test if no recipient get returned cause it not match @Test - public void testHostIsNotMatch() throws MessagingException { - mockedMail.setRecipients( - ImmutableList.of(new MailAddress("test@" + JAMES2_APACHE_ORG), - new MailAddress("test2@" + JAMES2_APACHE_ORG))); + public void shouldNotMatchAddressesFromDistantDomains() throws MessagingException { + Mail mail = FakeMail.builder() + .recipients(ANY_AT_JAMES2, OTHER_AT_JAMES2) + .build(); - assertThat(matcher.match(mockedMail)).isEmpty(); + assertThat(matcher.match(mail)).isEmpty(); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/5636d897/mailet/standard/src/test/java/org/apache/james/transport/matchers/HostIsTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HostIsTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HostIsTest.java index 8f85885..af352f9 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HostIsTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HostIsTest.java @@ -19,11 +19,16 @@ package org.apache.james.transport.matchers; +import static org.apache.mailet.base.MailAddressFixture.JAMES_APACHE_ORG; +import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES; +import static org.apache.mailet.base.MailAddressFixture.OTHER_AT_JAMES; +import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES2; +import static org.apache.mailet.base.MailAddressFixture.OTHER_AT_JAMES2; import static org.assertj.core.api.Assertions.assertThat; import javax.mail.MessagingException; -import org.apache.mailet.MailAddress; +import org.apache.mailet.Mail; import org.apache.mailet.Matcher; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMailContext; @@ -31,54 +36,41 @@ import org.apache.mailet.base.test.FakeMatcherConfig; import org.junit.Before; import org.junit.Test; -import com.google.common.collect.ImmutableList; - public class HostIsTest { - public static final String JAMES_APACHE_ORG = "james.apache.org"; - public static final String JAMES2_APACHE_ORG = "james2.apache.org"; - private FakeMail fakeMail; - private Matcher matcher; + private Matcher matcher; @Before public void setUp() throws Exception { - fakeMail = new FakeMail(); - matcher = new HostIs(); FakeMatcherConfig mci = new FakeMatcherConfig("HostIs=" + JAMES_APACHE_ORG, FakeMailContext.defaultContext()); matcher.init(mci); } - // test if all recipients get returned as matched @Test - public void testHostIsMatchedAllRecipients() throws MessagingException { - MailAddress mailAddress1 = new MailAddress("test@" + JAMES_APACHE_ORG); - MailAddress mailAddress2 = new MailAddress("test2@" + JAMES_APACHE_ORG); - fakeMail.setRecipients(ImmutableList.of( - mailAddress1, - mailAddress2)); + public void shouldMatchWhenRightDomain() throws MessagingException { + Mail mail = FakeMail.builder() + .recipients(ANY_AT_JAMES, OTHER_AT_JAMES) + .build(); - assertThat(matcher.match(fakeMail)).containsExactly(mailAddress1, mailAddress2); + assertThat(matcher.match(mail)).containsExactly(ANY_AT_JAMES, OTHER_AT_JAMES); } - // test if one recipients get returned as matched @Test - public void testHostIsMatchedOneRecipient() throws MessagingException { - MailAddress matchingAddress = new MailAddress("test2@" + JAMES_APACHE_ORG); - fakeMail.setRecipients(ImmutableList.of( - new MailAddress("test@" + JAMES2_APACHE_ORG), - matchingAddress)); + public void shouldMatchOnlyWhenRightDomain() throws MessagingException { + Mail mail = FakeMail.builder() + .recipients(ANY_AT_JAMES, ANY_AT_JAMES2) + .build(); - assertThat(matcher.match(fakeMail)).containsExactly(matchingAddress); + assertThat(matcher.match(mail)).containsExactly(ANY_AT_JAMES); } - // test if no recipient get returned cause it not match @Test - public void testHostIsNotMatch() throws MessagingException { - fakeMail.setRecipients(ImmutableList.of( - new MailAddress("test@" + JAMES2_APACHE_ORG), - new MailAddress("test2@" + JAMES2_APACHE_ORG))); + public void shouldNotMatchWhenWrongDomain() throws MessagingException { + Mail mail = FakeMail.builder() + .recipients(ANY_AT_JAMES2, OTHER_AT_JAMES2) + .build(); - assertThat(matcher.match(fakeMail)).isEmpty(); + assertThat(matcher.match(mail)).isEmpty(); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/5636d897/mailet/standard/src/test/java/org/apache/james/transport/matchers/IsSingleRecipientTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/IsSingleRecipientTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/IsSingleRecipientTest.java index 9fc7f83..bd22a8b 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/IsSingleRecipientTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/IsSingleRecipientTest.java @@ -20,11 +20,12 @@ package org.apache.james.transport.matchers; +import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES; +import static org.apache.mailet.base.MailAddressFixture.OTHER_AT_JAMES; import static org.assertj.core.api.Assertions.assertThat; import javax.mail.MessagingException; -import org.apache.mailet.MailAddress; import org.apache.mailet.Matcher; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMailContext; @@ -35,29 +36,24 @@ import org.junit.Test; public class IsSingleRecipientTest { private Matcher matcher; - private MailAddress mailAddress1; - private MailAddress mailAddress2; @Before public void setUp() throws MessagingException { matcher = new IsSingleRecipient(); FakeMatcherConfig matcherConfig = new FakeMatcherConfig("IsSingleRecipient", FakeMailContext.defaultContext()); matcher.init(matcherConfig); - - mailAddress1 = new MailAddress("t...@james.apache.org"); - mailAddress2 = new MailAddress("te...@james.apache.org"); } @Test public void matchShouldMatchOneRecipientsEmails() throws MessagingException { - FakeMail fakeMail = FakeMail.builder().recipient(mailAddress1).build(); + FakeMail fakeMail = FakeMail.builder().recipient(ANY_AT_JAMES).build(); - assertThat(matcher.match(fakeMail)).containsExactly(mailAddress1); + assertThat(matcher.match(fakeMail)).containsExactly(ANY_AT_JAMES); } @Test public void matchShouldNotMatchMultiRecipientsEMail() throws MessagingException { - FakeMail fakeMail = FakeMail.builder().recipients(mailAddress1, mailAddress2).build(); + FakeMail fakeMail = FakeMail.builder().recipients(ANY_AT_JAMES, OTHER_AT_JAMES).build(); assertThat(matcher.match(fakeMail)).isNull(); } http://git-wip-us.apache.org/repos/asf/james-project/blob/5636d897/mailet/standard/src/test/java/org/apache/james/transport/matchers/RelayLimitTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/RelayLimitTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/RelayLimitTest.java index cb73a0a..42bb762 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/RelayLimitTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/RelayLimitTest.java @@ -19,6 +19,7 @@ package org.apache.james.transport.matchers; +import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES; import static org.assertj.core.api.Assertions.assertThat; import java.util.Properties; @@ -28,7 +29,6 @@ import javax.mail.Session; import javax.mail.internet.MimeMessage; import org.apache.mailet.Mail; -import org.apache.mailet.MailAddress; import org.apache.mailet.base.RFC2822Headers; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMailContext; @@ -36,23 +36,20 @@ import org.apache.mailet.base.test.FakeMatcherConfig; import org.junit.Before; import org.junit.Test; -import com.google.common.collect.ImmutableList; - public class RelayLimitTest { private RelayLimit testee; - private MailAddress mailAddress; private Mail mail; private MimeMessage mimeMessage; @Before public void setUp() throws Exception { testee = new RelayLimit(); - mailAddress = new MailAddress("m...@domain.com"); - mail = new FakeMail(); - mail.setRecipients(ImmutableList.of(mailAddress)); mimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties())); - mail.setMessage(mimeMessage); + mail = FakeMail.builder() + .recipient(ANY_AT_JAMES) + .mimeMessage(mimeMessage) + .build(); } @Test(expected = MessagingException.class) @@ -98,7 +95,7 @@ public class RelayLimitTest { mimeMessage.addHeader(RFC2822Headers.RECEIVED, "any"); mimeMessage.addHeader(RFC2822Headers.RECEIVED, "any"); - assertThat(testee.match(mail)).containsExactly(mailAddress); + assertThat(testee.match(mail)).containsExactly(ANY_AT_JAMES); } @Test @@ -109,7 +106,7 @@ public class RelayLimitTest { mimeMessage.addHeader(RFC2822Headers.RECEIVED, "any"); mimeMessage.addHeader(RFC2822Headers.RECEIVED, "any"); - assertThat(testee.match(mail)).containsExactly(mailAddress); + assertThat(testee.match(mail)).containsExactly(ANY_AT_JAMES); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/5636d897/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsNullTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsNullTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsNullTest.java index 1337792..0c3845b 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsNullTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsNullTest.java @@ -20,6 +20,7 @@ package org.apache.james.transport.matchers; +import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES; import static org.assertj.core.api.Assertions.assertThat; import org.apache.mailet.MailAddress; @@ -37,28 +38,26 @@ public class SenderIsNullTest { public ExpectedException expectedException = ExpectedException.none(); private SenderIsNull matcher; - private MailAddress recipient; @Before public void setUp() throws Exception { matcher = new SenderIsNull(); matcher.init(new FakeMatcherConfig("SenderIsNull", FakeMailContext.defaultContext())); - recipient = new MailAddress("recipi...@james.apache.org"); } @Test public void shouldMatchWhenNullSender() throws Exception { FakeMail fakeMail = FakeMail.builder() - .recipient(recipient) + .recipient(ANY_AT_JAMES) .build(); - assertThat(matcher.match(fakeMail)).containsExactly(recipient); + assertThat(matcher.match(fakeMail)).containsExactly(ANY_AT_JAMES); } @Test public void shouldNotMatchWhenSenderIsPresent() throws Exception { FakeMail fakeMail = FakeMail.builder() - .recipient(recipient) + .recipient(ANY_AT_JAMES) .sender(new MailAddress("ot...@james.apache.org")) .build(); http://git-wip-us.apache.org/repos/asf/james-project/blob/5636d897/mailet/standard/src/test/java/org/apache/james/transport/matchers/SizeGreaterThanTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/SizeGreaterThanTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SizeGreaterThanTest.java index 22ac107..655112c 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/SizeGreaterThanTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SizeGreaterThanTest.java @@ -19,11 +19,12 @@ package org.apache.james.transport.matchers; +import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES; import static org.assertj.core.api.Assertions.assertThat; import javax.mail.MessagingException; -import org.apache.mailet.MailAddress; +import org.apache.mailet.Mail; import org.apache.mailet.Matcher; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMailContext; @@ -33,78 +34,94 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import com.google.common.collect.ImmutableList; - public class SizeGreaterThanTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - private FakeMail fakeMail; private Matcher matcher; - private MailAddress mailAddress; @Before public void setUp() throws Exception { matcher = new SizeGreaterThan(); - - fakeMail = new FakeMail(); - mailAddress = new MailAddress("test@email"); - fakeMail.setRecipients(ImmutableList.of(mailAddress)); } @Test public void matchShouldMatchWhenMailAboveSize() throws MessagingException { - fakeMail.setMessageSize(2000000); + Mail mail = FakeMail.builder() + .size(2000000) + .recipient(ANY_AT_JAMES) + .build(); + FakeMatcherConfig matcherConfiguration = new FakeMatcherConfig("SizeGreaterThan=1m", FakeMailContext.defaultContext()); matcher.init(matcherConfiguration); - assertThat(matcher.match(fakeMail)).containsExactly(mailAddress); + assertThat(matcher.match(mail)).containsExactly(ANY_AT_JAMES); } @Test public void matchShouldNotMatchWhenMailUnderSize() throws MessagingException { - fakeMail.setMessageSize(200000); + Mail mail = FakeMail.builder() + .size(200000) + .recipient(ANY_AT_JAMES) + .build(); + FakeMatcherConfig matcherConfiguration = new FakeMatcherConfig("SizeGreaterThan=1m", FakeMailContext.defaultContext()); matcher.init(matcherConfiguration); - assertThat(matcher.match(fakeMail)).isNull(); + assertThat(matcher.match(mail)).isNull(); } @Test public void matchShouldNotMatchMailsWithSpecifiedSize() throws MessagingException { - fakeMail.setMessageSize(1024); + Mail mail = FakeMail.builder() + .size(1024) + .recipient(ANY_AT_JAMES) + .build(); + FakeMatcherConfig matcherConfiguration = new FakeMatcherConfig("SizeGreaterThan=1k", FakeMailContext.defaultContext()); matcher.init(matcherConfiguration); - assertThat(matcher.match(fakeMail)).isNull(); + assertThat(matcher.match(mail)).isNull(); } @Test public void matchShouldMatchMailsWithSizeSuperiorToSpecifiedSize() throws MessagingException { - fakeMail.setMessageSize(1025); + Mail mail = FakeMail.builder() + .size(1025) + .recipient(ANY_AT_JAMES) + .build(); + FakeMatcherConfig matcherConfiguration = new FakeMatcherConfig("SizeGreaterThan=1k", FakeMailContext.defaultContext()); matcher.init(matcherConfiguration); - assertThat(matcher.match(fakeMail)).containsExactly(mailAddress); + assertThat(matcher.match(mail)).containsExactly(ANY_AT_JAMES); } @Test public void matchShouldReturnNullWhenUnderLimitNoUnit() throws MessagingException { - fakeMail.setMessageSize(4); + Mail mail = FakeMail.builder() + .size(4) + .recipient(ANY_AT_JAMES) + .build(); + FakeMatcherConfig matcherConfiguration = new FakeMatcherConfig("SizeGreaterThan=4", FakeMailContext.defaultContext()); matcher.init(matcherConfiguration); - assertThat(matcher.match(fakeMail)).isNull(); + assertThat(matcher.match(mail)).isNull(); } @Test public void matchShouldMatchOverLimitWhenNoUnit() throws MessagingException { - fakeMail.setMessageSize(5); + Mail mail = FakeMail.builder() + .size(5) + .recipient(ANY_AT_JAMES) + .build(); + FakeMatcherConfig matcherConfiguration = new FakeMatcherConfig("SizeGreaterThan=4", FakeMailContext.defaultContext()); matcher.init(matcherConfiguration); - assertThat(matcher.match(fakeMail)).containsExactly(mailAddress); + assertThat(matcher.match(mail)).containsExactly(ANY_AT_JAMES); } @Test --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org