http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMailAttributeTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMailAttributeTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMailAttributeTest.java index d5a7b98..e5614a1 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMailAttributeTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMailAttributeTest.java @@ -29,24 +29,20 @@ import org.apache.mailet.Mail; import org.apache.mailet.Mailet; import org.apache.mailet.base.test.FakeMailetConfig; import org.apache.mailet.base.test.MailUtil; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class SetMailAttributeTest { +class SetMailAttributeTest { - @Rule public ExpectedException expectedException = ExpectedException.none(); - private Mailet mailet; - @Before - public void setupMailet() throws MessagingException { + @BeforeEach + void setupMailet() { mailet = new SetMailAttribute(); } @Test - public void shouldAddConfiguredAttributes() throws MessagingException { + void shouldAddConfiguredAttributes() throws MessagingException { FakeMailetConfig mailetConfig = FakeMailetConfig.builder() .mailetName("Test") .setProperty("org.apache.james.junit1", "true") @@ -64,7 +60,7 @@ public class SetMailAttributeTest { } @Test - public void shouldAddNothingWhenNoConfiguredAttribute() throws MessagingException { + void shouldAddNothingWhenNoConfiguredAttribute() throws MessagingException { FakeMailetConfig mailetConfig = FakeMailetConfig.builder() .mailetName("Test") .build(); @@ -79,7 +75,7 @@ public class SetMailAttributeTest { } @Test - public void shouldOverwriteAttributeWhenAttributeAlreadyPresent() throws MessagingException { + void shouldOverwriteAttributeWhenAttributeAlreadyPresent() throws MessagingException { FakeMailetConfig mailetConfig = FakeMailetConfig.builder() .mailetName("Test") .setProperty("org.apache.james.junit1", "bar")
http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMimeHeaderTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMimeHeaderTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMimeHeaderTest.java index 8d122e4..6154897 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMimeHeaderTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/SetMimeHeaderTest.java @@ -32,24 +32,20 @@ import org.apache.mailet.Mail; import org.apache.mailet.Mailet; import org.apache.mailet.base.test.FakeMailetConfig; import org.apache.mailet.base.test.MailUtil; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class SetMimeHeaderTest { +class SetMimeHeaderTest { - @Rule public ExpectedException expectedException = ExpectedException.none(); - private Mailet mailet; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() { mailet = new SetMimeHeader(); } @Test - public void shouldAddHeaderToMime() throws MessagingException { + void shouldAddHeaderToMime() throws MessagingException { FakeMailetConfig mailetConfig = FakeMailetConfig.builder() .mailetName("Test") .setProperty("name", "header-name") @@ -66,7 +62,7 @@ public class SetMimeHeaderTest { } @Test - public void shouldAddHeaderWhenAlreadyPresent() throws MessagingException { + void shouldAddHeaderWhenAlreadyPresent() throws MessagingException { FakeMailetConfig mailetConfig = FakeMailetConfig.builder() .mailetName("Test") .setProperty("name", "header-name") @@ -84,7 +80,7 @@ public class SetMimeHeaderTest { } @Test - public void shouldThrowOnMessagingException() throws MessagingException { + void shouldThrowOnMessagingException() throws MessagingException { FakeMailetConfig mailetConfig = FakeMailetConfig.builder() .mailetName("Test") .setProperty("name", "header-name") @@ -100,53 +96,48 @@ public class SetMimeHeaderTest { } @Test - public void shouldThrowWhenNoConfiguration() throws MessagingException { + void shouldThrowWhenNoConfiguration() { FakeMailetConfig mailetConfig = FakeMailetConfig.builder() .mailetName("Test") .build(); - expectedException.expect(MessagingException.class); - mailet.init(mailetConfig); + assertThatThrownBy(() -> mailet.init(mailetConfig)).isInstanceOf(MessagingException.class); } @Test - public void shouldThrowWhenNoValue() throws MessagingException { + void shouldThrowWhenNoValue() { FakeMailetConfig mailetConfig = FakeMailetConfig.builder() .mailetName("Test") .setProperty("name", "correct") .build(); - expectedException.expect(MessagingException.class); - mailet.init(mailetConfig); + assertThatThrownBy(() -> mailet.init(mailetConfig)).isInstanceOf(MessagingException.class); } @Test - public void shouldThrowWhenNoHeader() throws MessagingException { + void shouldThrowWhenNoHeader() { FakeMailetConfig mailetConfig = FakeMailetConfig.builder() .mailetName("Test") .setProperty("value", "correct") .build(); - expectedException.expect(MessagingException.class); - mailet.init(mailetConfig); + assertThatThrownBy(() -> mailet.init(mailetConfig)).isInstanceOf(MessagingException.class); } @Test - public void shouldThrowWhenEmptyValue() throws MessagingException { + void shouldThrowWhenEmptyValue() { FakeMailetConfig mailetConfig = FakeMailetConfig.builder() .mailetName("Test") .setProperty("value", "") .setProperty("name", "correct") .build(); - expectedException.expect(MessagingException.class); - mailet.init(mailetConfig); + assertThatThrownBy(() -> mailet.init(mailetConfig)).isInstanceOf(MessagingException.class); } @Test - public void shouldThrowWhenEmptyHeader() throws MessagingException { + void shouldThrowWhenEmptyHeader() { FakeMailetConfig mailetConfig = FakeMailetConfig.builder() .mailetName("Test") .setProperty("name", "") .setProperty("value", "correct") .build(); - expectedException.expect(MessagingException.class); - mailet.init(mailetConfig); + assertThatThrownBy(() -> mailet.init(mailetConfig)).isInstanceOf(MessagingException.class); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/mailet/standard/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java index 537a1d3..afeb363 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/StripAttachmentTest.java @@ -20,6 +20,7 @@ package org.apache.james.transport.mailets; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -38,6 +39,7 @@ import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; +import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.james.core.builder.MimeMessageBuilder; import org.apache.james.transport.mailets.StripAttachment.OutputFileName; @@ -46,59 +48,55 @@ import org.apache.mailet.Mailet; import org.apache.mailet.MailetException; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMailetConfig; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class StripAttachmentTest { +import com.google.common.io.Files; + +class StripAttachmentTest { private static final String EXPECTED_ATTACHMENT_CONTENT = "#¤ãà é"; private static final Optional<String> ABSENT_MIME_TYPE = Optional.empty(); private static final String CONTENT_TRANSFER_ENCODING_VALUE = "8bit"; - public static final String CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding"; - public static final String CONTENT_TYPE = "Content-Type"; - public static final String CONTENT_TYPE_DEFAULT = "application/octet-stream; charset=utf-8"; - public static final String TEXT_CALENDAR_CHARSET_UTF_8 = "text/calendar; charset=utf-8"; - public static final String TEXT_HTML_CHARSET_UTF_8 = "text/html; charset=utf-8"; + private static final String CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding"; + private static final String CONTENT_TYPE = "Content-Type"; + private static final String CONTENT_TYPE_DEFAULT = "application/octet-stream; charset=utf-8"; + private static final String TEXT_CALENDAR_CHARSET_UTF_8 = "text/calendar; charset=utf-8"; + private static final String TEXT_HTML_CHARSET_UTF_8 = "text/html; charset=utf-8"; - private static MimeMessageBuilder.Header[] TEXT_HEADERS = { + private static final MimeMessageBuilder.Header[] TEXT_HEADERS = { new MimeMessageBuilder.Header(CONTENT_TRANSFER_ENCODING, CONTENT_TRANSFER_ENCODING_VALUE), new MimeMessageBuilder.Header(CONTENT_TYPE, CONTENT_TYPE_DEFAULT) }; - private static MimeMessageBuilder.Header[] HTML_HEADERS = { + private static final MimeMessageBuilder.Header[] HTML_HEADERS = { new MimeMessageBuilder.Header(CONTENT_TRANSFER_ENCODING, CONTENT_TRANSFER_ENCODING_VALUE), new MimeMessageBuilder.Header(CONTENT_TYPE, TEXT_HTML_CHARSET_UTF_8) }; - private static MimeMessageBuilder.Header[] CALENDAR_HEADERS = { + private static final MimeMessageBuilder.Header[] CALENDAR_HEADERS = { new MimeMessageBuilder.Header(CONTENT_TRANSFER_ENCODING, CONTENT_TRANSFER_ENCODING_VALUE), new MimeMessageBuilder.Header(CONTENT_TYPE, TEXT_CALENDAR_CHARSET_UTF_8) }; - @Rule - public ExpectedException expectedException = ExpectedException.none(); - @Rule - public TemporaryFolder folder = new TemporaryFolder(); - private String folderPath; + private File tempDir; - @Before - public void setUp() throws IOException { - folderPath = folder.getRoot().getPath() + "/"; + @BeforeEach + void setUp() { + tempDir = Files.createTempDir(); + folderPath = tempDir.getPath() + "/"; } - @After - public void tearDown() throws IOException { - folder.delete(); + @AfterEach + void tearDown() throws IOException { + FileUtils.deleteDirectory(tempDir); } @Test - public void serviceShouldNotModifyMailWhenNotMultipart() throws MessagingException, IOException { + void serviceShouldNotModifyMailWhenNotMultipart() throws MessagingException, IOException { Mailet mailet = initMailet(); MimeMessageBuilder message = MimeMessageBuilder.mimeMessageBuilder() .setSubject("test") @@ -118,7 +116,7 @@ public class StripAttachmentTest { } @Test - public void serviceShouldSaveAttachmentInAFolderWhenPatternMatch() throws MessagingException, IOException { + void serviceShouldSaveAttachmentInAFolderWhenPatternMatch() throws MessagingException { Mailet mailet = initMailet(); String expectedAttachmentContent = EXPECTED_ATTACHMENT_CONTENT; @@ -144,7 +142,7 @@ public class StripAttachmentTest { } @Test - public void serviceShouldRemoveWhenMimeTypeMatches() throws MessagingException, IOException { + void serviceShouldRemoveWhenMimeTypeMatches() throws MessagingException { FakeMailetConfig mci = FakeMailetConfig.builder() .mailetName("Test") .setProperty("mimeType", "text/calendar") @@ -172,7 +170,7 @@ public class StripAttachmentTest { assertThat(removedAttachments).containsOnly(expectedFileName); } - private MimeMessageBuilder.BodyPartBuilder createAttachmentBodyPart(String body, String fileName, MimeMessageBuilder.Header... headers) throws MessagingException, IOException { + private MimeMessageBuilder.BodyPartBuilder createAttachmentBodyPart(String body, String fileName, MimeMessageBuilder.Header... headers) { return MimeMessageBuilder.bodyPartBuilder() .data(body) .addHeaders(headers) @@ -181,7 +179,7 @@ public class StripAttachmentTest { } @Test - public void serviceShouldSaveAttachmentInAFolderWhenNotPatternDoesntMatch() throws MessagingException, IOException { + void serviceShouldSaveAttachmentInAFolderWhenNotPatternDoesntMatch() throws MessagingException { Mailet mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() @@ -214,7 +212,7 @@ public class StripAttachmentTest { assertThat(new File(folderPath + attachmentFilename)).hasContent(expectedAttachmentContent); } - private String retrieveFilenameStartingWith(Collection<String> savedAttachments, final String filename) { + private String retrieveFilenameStartingWith(Collection<String> savedAttachments, String filename) { return savedAttachments.stream() .filter(attachmentFilename -> attachmentFilename.startsWith(filename)) .findFirst() @@ -222,7 +220,7 @@ public class StripAttachmentTest { } @Test - public void serviceShouldDecodeFilenameAndSaveAttachmentInAFolderWhenPatternMatchAndDecodeFilenameTrue() throws MessagingException, IOException { + void serviceShouldDecodeFilenameAndSaveAttachmentInAFolderWhenPatternMatchAndDecodeFilenameTrue() throws MessagingException { Mailet mailet = initMailet(); String expectedAttachmentContent = EXPECTED_ATTACHMENT_CONTENT; @@ -251,7 +249,7 @@ public class StripAttachmentTest { } @Test - public void serviceShouldSaveFilenameAttachmentAndFileContentInCustomAttribute() throws MessagingException, IOException { + void serviceShouldSaveFilenameAttachmentAndFileContentInCustomAttribute() throws MessagingException, IOException { StripAttachment mailet = new StripAttachment(); String customAttribute = "my.custom.attribute"; @@ -286,7 +284,7 @@ public class StripAttachmentTest { } @Test - public void serviceShouldDecodeHeaderFilenames() throws MessagingException, IOException { + void serviceShouldDecodeHeaderFilenames() throws MessagingException, IOException { StripAttachment mailet = new StripAttachment(); String customAttribute = "my.custom.attribute"; @@ -318,20 +316,20 @@ public class StripAttachmentTest { } @Test - public void initShouldThrowWhenPatternAndNotPatternAndMimeTypeAreNull() throws MessagingException { + void initShouldThrowWhenPatternAndNotPatternAndMimeTypeAreNull() { Mailet mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() .mailetName("Test") .build(); - expectedException.expect(MailetException.class); - expectedException.expectMessage("At least one of 'pattern', 'notpattern' or 'mimeType' parameter should be provided."); - mailet.init(mci); + assertThatThrownBy(() -> mailet.init(mci)) + .isInstanceOf(MailetException.class) + .hasMessage("At least one of 'pattern', 'notpattern' or 'mimeType' parameter should be provided."); } @Test - public void initShouldThrowWhenMimeTypeIsEmpty() throws MessagingException { + void initShouldThrowWhenMimeTypeIsEmpty() { Mailet mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() @@ -339,13 +337,13 @@ public class StripAttachmentTest { .setProperty("mimeType", "") .build(); - expectedException.expect(MailetException.class); - expectedException.expectMessage("At least one of 'pattern', 'notpattern' or 'mimeType' parameter should be provided."); - mailet.init(mci); + assertThatThrownBy(() -> mailet.init(mci)) + .isInstanceOf(MailetException.class) + .hasMessage("At least one of 'pattern', 'notpattern' or 'mimeType' parameter should be provided."); } @Test - public void initShouldWorkWhenPatternIsDefinedAndValid() throws MessagingException { + void initShouldWorkWhenPatternIsDefinedAndValid() throws MessagingException { Mailet mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() @@ -357,7 +355,7 @@ public class StripAttachmentTest { } @Test - public void initShouldWorkWhenNotPatternIsDefinedAndValid() throws MessagingException { + void initShouldWorkWhenNotPatternIsDefinedAndValid() throws MessagingException { Mailet mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() @@ -369,7 +367,7 @@ public class StripAttachmentTest { } @Test - public void initShouldWorkWhenMimeTypeIsDefined() throws MessagingException { + void initShouldWorkWhenMimeTypeIsDefined() throws MessagingException { Mailet mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() @@ -381,7 +379,7 @@ public class StripAttachmentTest { } @Test - public void initShouldThrowWhenWrongPattern() throws MessagingException { + void initShouldThrowWhenWrongPattern() { Mailet mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() @@ -389,13 +387,13 @@ public class StripAttachmentTest { .setProperty("pattern", ".****\\.tmp") .build(); - expectedException.expect(MailetException.class); - expectedException.expectMessage("Could not compile regex [.****\\.tmp]"); - mailet.init(mci); + assertThatThrownBy(() -> mailet.init(mci)) + .isInstanceOf(MailetException.class) + .hasMessage("Could not compile regex [.****\\.tmp]."); } @Test - public void initShouldThrowWhenWrongNotPattern() throws MessagingException { + void initShouldThrowWhenWrongNotPattern() { Mailet mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() @@ -403,13 +401,13 @@ public class StripAttachmentTest { .setProperty("notpattern", ".****\\.tmp") .build(); - expectedException.expect(MailetException.class); - expectedException.expectMessage("Could not compile regex [.****\\.tmp]"); - mailet.init(mci); + assertThatThrownBy(() -> mailet.init(mci)) + .isInstanceOf(MailetException.class) + .hasMessage("Could not compile regex [.****\\.tmp]."); } @Test - public void initShouldThrowWhenRemoveParameterIsUnknown() throws MessagingException { + void initShouldThrowWhenRemoveParameterIsUnknown() { StripAttachment mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() @@ -418,13 +416,13 @@ public class StripAttachmentTest { .setProperty("pattern", ".*\\.tmp") .build(); - expectedException.expect(MailetException.class); - expectedException.expectMessage("Unknown remove parameter value 'unknown' waiting for 'matched', 'all' or 'no'."); - mailet.init(mci); + assertThatThrownBy(() -> mailet.init(mci)) + .isInstanceOf(MailetException.class) + .hasMessage("Unknown remove parameter value 'unknown' waiting for 'matched', 'all' or 'no'."); } @Test - public void initShouldSetRemoveParameterWhenEqualsMatched() throws MessagingException { + void initShouldSetRemoveParameterWhenEqualsMatched() throws MessagingException { StripAttachment mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() @@ -438,7 +436,7 @@ public class StripAttachmentTest { } @Test - public void initShouldSetRemoveParameterWhenEqualsAll() throws MessagingException { + void initShouldSetRemoveParameterWhenEqualsAll() throws MessagingException { StripAttachment mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() @@ -452,7 +450,7 @@ public class StripAttachmentTest { } @Test - public void initShouldSetRemoveParameterWhenEqualsNo() throws MessagingException { + void initShouldSetRemoveParameterWhenEqualsNo() throws MessagingException { StripAttachment mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() @@ -466,7 +464,7 @@ public class StripAttachmentTest { } @Test - public void initShouldSetRemoveParameterDefaultValueWhenNotGiven() throws MessagingException { + void initShouldSetRemoveParameterDefaultValueWhenNotGiven() throws MessagingException { StripAttachment mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() @@ -479,21 +477,20 @@ public class StripAttachmentTest { } @Test - public void serviceShouldThrowWhenUnretrievableMessage() throws MessagingException { + void serviceShouldThrowWhenUnretrievableMessage() throws MessagingException { Mailet mailet = initMailet(); Mail mail = mock(Mail.class); when(mail.getMessage()) .thenThrow(new MessagingException("Test exception")); - expectedException.expect(MailetException.class); - expectedException.expectMessage("Could not retrieve message from Mail object"); - - mailet.service(mail); + assertThatThrownBy(() -> mailet.service(mail)) + .isInstanceOf(MailetException.class) + .hasMessage("Could not retrieve message from Mail object"); } @Test - public void serviceShouldThrowWhenUnretrievableContentTypeMessage() throws MessagingException { + void serviceShouldThrowWhenUnretrievableContentTypeMessage() throws MessagingException { Mailet mailet = initMailet(); MimeMessage message = mock(MimeMessage.class); @@ -503,21 +500,20 @@ public class StripAttachmentTest { when(message.isMimeType("multipart/*")) .thenThrow(new MessagingException("Test exception")); - expectedException.expect(MailetException.class); - expectedException.expectMessage("Could not retrieve contenttype of MimePart."); - - mailet.service(mail); + assertThatThrownBy(() -> mailet.service(mail)) + .isInstanceOf(MailetException.class) + .hasMessage("Could not retrieve contenttype of MimePart."); } @Test - public void getMailetInfoShouldReturn() throws MessagingException { + void getMailetInfoShouldReturn() { StripAttachment mailet = new StripAttachment(); assertThat(mailet.getMailetInfo()).isEqualTo("StripAttachment"); } @Test - public void processMultipartPartMessageShouldReturnFalseWhenPartIsNotMultipart() throws Exception { + void processMultipartPartMessageShouldReturnFalseWhenPartIsNotMultipart() throws Exception { //Given StripAttachment mailet = new StripAttachment(); Part part = new MimeBodyPart(new ByteArrayInputStream(new byte[0])); @@ -529,7 +525,7 @@ public class StripAttachmentTest { } @Test - public void processMultipartPartMessageShouldReturnTrueWhenAtLeastOneMultipartShouldHaveBeenRemoved() throws Exception { + void processMultipartPartMessageShouldReturnTrueWhenAtLeastOneMultipartShouldHaveBeenRemoved() throws Exception { //Given StripAttachment mailet = new StripAttachment(); @@ -552,7 +548,7 @@ public class StripAttachmentTest { } @Test - public void processMultipartPartMessageShouldReturnTrueWhenAtLeastOneMultipartShouldHaveBeenRemovedAndPartialRemove() throws Exception { + void processMultipartPartMessageShouldReturnTrueWhenAtLeastOneMultipartShouldHaveBeenRemovedAndPartialRemove() throws Exception { //Given StripAttachment mailet = new StripAttachment(); @@ -576,7 +572,7 @@ public class StripAttachmentTest { } @Test - public void processMultipartPartMessageShouldPutTwoPartsInDefaultAttributeWhenTwoPartsMatch() throws Exception { + void processMultipartPartMessageShouldPutTwoPartsInDefaultAttributeWhenTwoPartsMatch() throws Exception { //Given StripAttachment mailet = new StripAttachment(); @@ -607,7 +603,7 @@ public class StripAttachmentTest { } @Test - public void processMultipartPartMessageShouldPutTwoPartsInCustomAttributeWhenTwoPartsMatch() throws Exception { + void processMultipartPartMessageShouldPutTwoPartsInCustomAttributeWhenTwoPartsMatch() throws Exception { //Given StripAttachment mailet = new StripAttachment(); @@ -642,7 +638,7 @@ public class StripAttachmentTest { } @Test - public void processMultipartPartMessageShouldReturnTrueWhenAtLeastOneSubMultipartShouldHaveBeenRemoved() throws Exception { + void processMultipartPartMessageShouldReturnTrueWhenAtLeastOneSubMultipartShouldHaveBeenRemoved() throws Exception { //Given StripAttachment mailet = new StripAttachment(); @@ -668,7 +664,7 @@ public class StripAttachmentTest { } @Test - public void processMultipartPartMessageShouldReturnFalseWhenNoPartHasBeenRemovedInSubMultipart() throws Exception { + void processMultipartPartMessageShouldReturnFalseWhenNoPartHasBeenRemovedInSubMultipart() throws Exception { //Given StripAttachment mailet = new StripAttachment(); @@ -694,7 +690,7 @@ public class StripAttachmentTest { } @Test - public void processMultipartPartMessageShouldRemovePartWhenOnePartShouldHaveBeenRemoved() throws Exception { + void processMultipartPartMessageShouldRemovePartWhenOnePartShouldHaveBeenRemoved() throws Exception { //Given StripAttachment mailet = new StripAttachment(); @@ -721,7 +717,7 @@ public class StripAttachmentTest { } @Test - public void processMultipartPartMessageShouldSetFilenameToMatchingAttachmentsWhenAttachmentWithoutFilename() throws Exception { + void processMultipartPartMessageShouldSetFilenameToMatchingAttachmentsWhenAttachmentWithoutFilename() throws Exception { //Given StripAttachment mailet = new StripAttachment(); @@ -750,7 +746,7 @@ public class StripAttachmentTest { } @Test - public void saveAttachmentShouldUsePartNameIfNoFilename() throws Exception { + void saveAttachmentShouldUsePartNameIfNoFilename() throws Exception { //Given StripAttachment mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() @@ -772,7 +768,7 @@ public class StripAttachmentTest { } @Test - public void saveAttachmentShouldReturnAbsentWhenNoFilenameAtAll() throws Exception { + void saveAttachmentShouldReturnAbsentWhenNoFilenameAtAll() throws Exception { StripAttachment mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() .setProperty("directory", folderPath) @@ -786,7 +782,7 @@ public class StripAttachmentTest { } @Test - public void saveAttachmentShouldAddBinExtensionWhenNoFileNameExtension() throws Exception { + void saveAttachmentShouldAddBinExtensionWhenNoFileNameExtension() throws Exception { //Given StripAttachment mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() @@ -836,19 +832,18 @@ public class StripAttachmentTest { } @Test - public void fileNameMatchesShouldThrowWhenPatternIsNull() throws Exception { + void fileNameMatchesShouldThrowWhenPatternIsNull() throws Exception { StripAttachment mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() .setProperty("pattern", ".*pattern.*") .build(); mailet.init(mci); - - expectedException.expect(NullPointerException.class); - mailet.fileNameMatches(null); + + assertThatThrownBy(() -> mailet.fileNameMatches(null)).isInstanceOf(NullPointerException.class); } @Test - public void fileNameMatchesShouldReturnFalseWhenPatternDoesntMatch() throws Exception { + void fileNameMatchesShouldReturnFalseWhenPatternDoesntMatch() throws Exception { StripAttachment mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() .setProperty("pattern", ".*pattern.*") @@ -859,7 +854,7 @@ public class StripAttachmentTest { } @Test - public void fileNameMatchesShouldReturnTrueWhenPatternMatches() throws Exception { + void fileNameMatchesShouldReturnTrueWhenPatternMatches() throws Exception { StripAttachment mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() .setProperty("pattern", ".*pattern.*") @@ -870,7 +865,7 @@ public class StripAttachmentTest { } @Test - public void fileNameMatchesShouldReturnFalseWhenNotPatternMatches() throws Exception { + void fileNameMatchesShouldReturnFalseWhenNotPatternMatches() throws Exception { StripAttachment mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() .setProperty("notpattern", ".*pattern.*") @@ -881,7 +876,7 @@ public class StripAttachmentTest { } @Test - public void fileNameMatchesShouldReturnTrueWhenNotPatternDoesntMatch() throws Exception { + void fileNameMatchesShouldReturnTrueWhenNotPatternDoesntMatch() throws Exception { StripAttachment mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() .setProperty("notpattern", ".*pattern.*") @@ -892,7 +887,7 @@ public class StripAttachmentTest { } @Test - public void fileNameMatchesShouldReturnFalseWhenPatternAndNotPatternAreTheSame() throws Exception { + void fileNameMatchesShouldReturnFalseWhenPatternAndNotPatternAreTheSame() throws Exception { StripAttachment mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() .setProperty("pattern", ".*pattern.*") @@ -905,7 +900,7 @@ public class StripAttachmentTest { } @Test - public void fileNameMatchesShouldReturnTrueWhenPatternMatchesAndNotPatternDoesntMatch() throws Exception { + void fileNameMatchesShouldReturnTrueWhenPatternMatchesAndNotPatternDoesntMatch() throws Exception { StripAttachment mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() .setProperty("pattern", ".*pattern.*") @@ -917,7 +912,7 @@ public class StripAttachmentTest { } @Test - public void fileNameMatchesShouldReturnTrueWhenPatternDoesntMatchesAndNotPatternDoesntMatch() throws Exception { + void fileNameMatchesShouldReturnTrueWhenPatternDoesntMatchesAndNotPatternDoesntMatch() throws Exception { StripAttachment mailet = new StripAttachment(); FakeMailetConfig mci = FakeMailetConfig.builder() .setProperty("pattern", ".*pattern.*") @@ -929,13 +924,13 @@ public class StripAttachmentTest { } @Test - public void prependedPrefixShouldAddUnderscoreWhenPrefixIsLessThanThreeCharacters() { + void prependedPrefixShouldAddUnderscoreWhenPrefixIsLessThanThreeCharacters() { String prefix = OutputFileName.prependedPrefix("a"); assertThat(prefix).isEqualTo("__a"); } @Test - public void prependedPrefixShouldReturnPrefixWhenPrefixIsGreaterThanThreeCharacters() { + void prependedPrefixShouldReturnPrefixWhenPrefixIsGreaterThanThreeCharacters() { String expectedPrefix = "abcd"; String prefix = OutputFileName.prependedPrefix(expectedPrefix); assertThat(prefix).isEqualTo(expectedPrefix); http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/mailet/standard/src/test/java/org/apache/james/transport/mailets/ToProcessorTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/ToProcessorTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/ToProcessorTest.java index 6fe84e3..0ef692d 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/ToProcessorTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/ToProcessorTest.java @@ -21,6 +21,7 @@ package org.apache.james.transport.mailets; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; import javax.mail.MessagingException; @@ -32,47 +33,40 @@ import org.apache.mailet.MailetException; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMailContext; import org.apache.mailet.base.test.FakeMailetConfig; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; -public class ToProcessorTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); +class ToProcessorTest { private Mailet mailet; - private Logger logger; private FakeMailContext mailContext; - @Before - public void setup() { + @BeforeEach + void setup() { mailet = new ToProcessor(); - logger = mock(Logger.class); + Logger logger = mock(Logger.class); mailContext = FakeMailContext.builder().logger(logger).build(); } @Test - public void getMailetInfoShouldReturnValue() { + void getMailetInfoShouldReturnValue() { assertThat(mailet.getMailetInfo()).isEqualTo("ToProcessor Mailet"); } @Test - public void initShouldThrowWhenProcessorIsNotGiven() throws MessagingException { + void initShouldThrowWhenProcessorIsNotGiven() { FakeMailetConfig mailetConfig = FakeMailetConfig.builder() .mailetName("Test") .mailetContext(mailContext) .setProperty("notice", "error in message") .build(); - expectedException.expect(MailetException.class); - - mailet.init(mailetConfig); + assertThatThrownBy(() -> mailet.init(mailetConfig)) + .isInstanceOf(MailetException.class); } @Test - public void serviceShouldSetTheStateOfTheMail() throws MessagingException { + void serviceShouldSetTheStateOfTheMail() throws MessagingException { String processor = "error"; FakeMailetConfig mailetConfig = FakeMailetConfig.builder() .mailetName("Test") @@ -90,7 +84,7 @@ public class ToProcessorTest { } @Test - public void serviceShouldSetTheErrorMessageOfTheMailWhenNotAlreadySet() throws MessagingException { + void serviceShouldSetTheErrorMessageOfTheMailWhenNotAlreadySet() throws MessagingException { String processor = "error"; String notice = "error in message"; FakeMailetConfig mailetConfig = FakeMailetConfig.builder() @@ -110,7 +104,7 @@ public class ToProcessorTest { } @Test - public void serviceShouldAppendTheErrorMessageOfTheMailWhenSomeErrorMessageOnMail() throws MessagingException { + void serviceShouldAppendTheErrorMessageOfTheMailWhenSomeErrorMessageOnMail() throws MessagingException { String processor = "error"; String notice = "error in message"; FakeMailetConfig mailetConfig = FakeMailetConfig.builder() http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/mailet/standard/src/test/java/org/apache/james/transport/mailets/UnwrapTextTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/UnwrapTextTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/UnwrapTextTest.java index 7014e41..3fd47c5 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/UnwrapTextTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/UnwrapTextTest.java @@ -19,8 +19,8 @@ package org.apache.james.transport.mailets; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class UnwrapTextTest { @@ -32,8 +32,8 @@ public class UnwrapTextTest { String input; String output; - Assert.assertEquals("", UnwrapText.unwrap("")); - Assert.assertEquals("a", UnwrapText.unwrap("a")); + Assertions.assertEquals("", UnwrapText.unwrap("")); + Assertions.assertEquals("a", UnwrapText.unwrap("a")); input = "Prova per vedere se effettivamente il testo viene wrappato\r\n" + @@ -46,7 +46,7 @@ public class UnwrapTextTest { "Chissà se funziona davvero\r\n" + "o se va solo come gli pare"; - Assert.assertEquals(output, UnwrapText.unwrap(input)); + Assertions.assertEquals(output, UnwrapText.unwrap(input)); input = "> Prova per vedere se effettivamente il testo viene wrappato\r\n" + @@ -59,7 +59,7 @@ public class UnwrapTextTest { "> Chissà se funziona davvero\r\n" + "> o se va solo come gli pare"; - Assert.assertEquals(output, UnwrapText.unwrap(input)); + Assertions.assertEquals(output, UnwrapText.unwrap(input)); input = "> Prova per vedere se effettivamente il testo viene wrappato\r\n" + @@ -75,7 +75,7 @@ public class UnwrapTextTest { "> o se va solo come gli pare\r\n" + "> Prova per vedere se effettivamente il testo viene wrappato come dovrebbe.\r\n"; - Assert.assertEquals(output, UnwrapText.unwrap(input)); + Assertions.assertEquals(output, UnwrapText.unwrap(input)); input = "> volevo chiedervi un piccolo aiutino. Una signora con un circolare ha un\r\n" + @@ -91,7 +91,7 @@ public class UnwrapTextTest { "trucco da suggerirmi per rimuovere il ponte? Il ponte è in ceramica, per " + "cui l'utilizzo degli ultrasuoni puo' essere rischioso (?).\r\n"; - Assert.assertEquals(output, UnwrapText.unwrap(input)); + Assertions.assertEquals(output, UnwrapText.unwrap(input)); input = "> Prova per vedere se effettivamente il testo viene wrappato\r\n" + @@ -104,7 +104,7 @@ public class UnwrapTextTest { "> Prova per vedere se effettivamente il testo viene wrappato com dovrebbe.\r\n" + "> Prova per vedere se effettivamente il testo viene wrappato come dovrebbe.\r\n"; - Assert.assertEquals(output, UnwrapText.unwrap(input)); + Assertions.assertEquals(output, UnwrapText.unwrap(input)); input = "> Prova per vedere se effettivamente il testo viene wrappato\r\n" + @@ -118,7 +118,7 @@ public class UnwrapTextTest { "> Prova per vedere se effettivamente il testo viene wrappato come\r\n" + ">> dovrebbe.\r\n"; - Assert.assertEquals(output, UnwrapText.unwrap(input)); + Assertions.assertEquals(output, UnwrapText.unwrap(input)); input = "> Prova per vedere se effettivamente il testo viene wrappato\r\n" + @@ -131,7 +131,7 @@ public class UnwrapTextTest { "> Prova per vedere se effettivamente il testo viene wrappato\r\n" + "come dovrebbe.\r\n"; - Assert.assertEquals(output, UnwrapText.unwrap(input)); + Assertions.assertEquals(output, UnwrapText.unwrap(input)); input = "...pero' devo dire che ai congressi vedo moltissimi casi di carico\r\n" + @@ -147,7 +147,7 @@ public class UnwrapTextTest { "\"parodontosici\" che io terrei li per altri 15 anni...\r\n" + "Non voglio polemizzare ne tantomento accusare nessuno, ma credo che spesso a accada quello che Alessio suggerisce...\r\n"; - Assert.assertEquals(output, UnwrapText.unwrap(input)); + Assertions.assertEquals(output, UnwrapText.unwrap(input)); input = "> mi trovo in difficolta,ho eseguito un lavoro di protesizzazione in\r\n" + @@ -175,7 +175,7 @@ public class UnwrapTextTest { "a tirar giu il lavoro anche con tutte le cautele del caso rischio la " + "rottura\r\n"; - Assert.assertEquals(output, UnwrapText.unwrap(input, 79)); + Assertions.assertEquals(output, UnwrapText.unwrap(input, 79)); // Controllo spazi input = @@ -193,7 +193,7 @@ public class UnwrapTextTest { "o se va solo come gli pare \r\n" + "> Prova per vedere se effettivamente il testo viene wrappato come dovrebbe. \r\n"; - Assert.assertEquals(output, UnwrapText.unwrap(input, 79)); + Assertions.assertEquals(output, UnwrapText.unwrap(input, 79)); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/mailet/standard/src/test/java/org/apache/james/transport/mailets/UseHeaderRecipientsTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/UseHeaderRecipientsTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/UseHeaderRecipientsTest.java index f77d57a..d5b294c 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/UseHeaderRecipientsTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/UseHeaderRecipientsTest.java @@ -20,6 +20,7 @@ package org.apache.james.transport.mailets; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.apache.james.core.MailAddress; import org.apache.james.core.builder.MimeMessageBuilder; @@ -29,27 +30,22 @@ import org.apache.mailet.base.MailAddressFixture; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMailContext; import org.apache.mailet.base.test.FakeMailetConfig; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class UseHeaderRecipientsTest { +class UseHeaderRecipientsTest { - public static final String RECIPIENT1 = "a...@apache1.org"; - public static final String RECIPIENT2 = "a...@apache2.org"; - public static final String RECIPIENT3 = "a...@apache3.org"; + private static final String RECIPIENT1 = "a...@apache1.org"; + private static final String RECIPIENT2 = "a...@apache2.org"; + private static final String RECIPIENT3 = "a...@apache3.org"; private UseHeaderRecipients testee; private FakeMailContext mailetContext; private MailAddress mailAddress1; private MailAddress mailAddress2; private MailAddress mailAddress3; - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { testee = new UseHeaderRecipients(); mailetContext = FakeMailContext.defaultContext(); testee.init(FakeMailetConfig.builder().mailetContext(mailetContext).build()); @@ -60,7 +56,7 @@ public class UseHeaderRecipientsTest { } @Test - public void serviceShouldSetMimeMessageRecipients() throws Exception { + void serviceShouldSetMimeMessageRecipients() throws Exception { FakeMail fakeMail = FakeMail.builder() .recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.ANY_AT_JAMES2) .mimeMessage(MimeMessageBuilder.mimeMessageBuilder() @@ -74,7 +70,7 @@ public class UseHeaderRecipientsTest { } @Test - public void serviceShouldSetToCcAndBccSpecifiedInTheMimeMessage() throws Exception { + void serviceShouldSetToCcAndBccSpecifiedInTheMimeMessage() throws Exception { FakeMail fakeMail = FakeMail.builder() .recipients(MailAddressFixture.ANY_AT_JAMES) .mimeMessage(MimeMessageBuilder.mimeMessageBuilder() @@ -90,7 +86,7 @@ public class UseHeaderRecipientsTest { } @Test - public void serviceShouldSetEmptyRecipientWhenNoRecipientsInTheMimeMessage() throws Exception { + void serviceShouldSetEmptyRecipientWhenNoRecipientsInTheMimeMessage() throws Exception { FakeMail fakeMail = FakeMail.builder() .recipients(MailAddressFixture.ANY_AT_JAMES) @@ -104,7 +100,7 @@ public class UseHeaderRecipientsTest { } @Test - public void serviceShouldGhostEmail() throws Exception { + void serviceShouldGhostEmail() throws Exception { FakeMail fakeMail = FakeMail.builder() .recipients(MailAddressFixture.ANY_AT_JAMES) .mimeMessage(MimeMessageUtil.defaultMimeMessage()) @@ -117,7 +113,7 @@ public class UseHeaderRecipientsTest { } @Test - public void serviceShouldResendTheEmail() throws Exception { + void serviceShouldResendTheEmail() throws Exception { FakeMail fakeMail = FakeMail.builder() .recipients(MailAddressFixture.ANY_AT_JAMES) .mimeMessage(MimeMessageBuilder.mimeMessageBuilder() @@ -136,20 +132,18 @@ public class UseHeaderRecipientsTest { } @Test - public void serviceShouldThrowOnInvalidMailAddress() throws Exception { - expectedException.expect(RuntimeException.class); - + void serviceShouldThrowOnInvalidMailAddress() throws Exception { FakeMail fakeMail = FakeMail.builder() .recipients(mailAddress1) .mimeMessage(MimeMessageBuilder.mimeMessageBuilder() .addToRecipient("invalid")) .build(); - testee.service(fakeMail); + assertThatThrownBy(() -> testee.service(fakeMail)).isInstanceOf(RuntimeException.class); } @Test - public void serviceShouldSupportAddressList() throws Exception { + void serviceShouldSupportAddressList() throws Exception { FakeMail fakeMail = FakeMail.builder() .recipients() .mimeMessage(MimeMessageBuilder.mimeMessageBuilder() @@ -163,7 +157,7 @@ public class UseHeaderRecipientsTest { } @Test - public void serviceShouldSupportMailboxes() throws Exception { + void serviceShouldSupportMailboxes() throws Exception { FakeMail fakeMail = FakeMail.builder() .recipients() .mimeMessage(MimeMessageBuilder.mimeMessageBuilder() http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/mailet/standard/src/test/java/org/apache/james/transport/mailets/utils/MimeMessageModifierTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/utils/MimeMessageModifierTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/utils/MimeMessageModifierTest.java index 081d10f..9b897e1 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/utils/MimeMessageModifierTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/utils/MimeMessageModifierTest.java @@ -26,7 +26,7 @@ import java.util.Optional; import javax.mail.internet.MimeMessage; import org.apache.james.core.builder.MimeMessageBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MimeMessageModifierTest { http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/mailet/standard/src/test/java/org/apache/james/transport/mailets/utils/MimeMessageUtilsTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/utils/MimeMessageUtilsTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/utils/MimeMessageUtilsTest.java index de3f003..8d5daa3 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/utils/MimeMessageUtilsTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/utils/MimeMessageUtilsTest.java @@ -29,7 +29,7 @@ import javax.mail.internet.MimeMessage; import org.apache.james.core.builder.MimeMessageBuilder; import org.apache.mailet.base.test.FakeMail; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MimeMessageUtilsTest { http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/mailet/standard/src/test/java/org/apache/james/transport/matchers/AbstractHasMailAttributeTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/AbstractHasMailAttributeTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/AbstractHasMailAttributeTest.java index 0bcff15..d6eb21e 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/AbstractHasMailAttributeTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/AbstractHasMailAttributeTest.java @@ -20,6 +20,10 @@ package org.apache.james.transport.matchers; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + import java.util.Collection; import javax.mail.MessagingException; @@ -30,42 +34,38 @@ import org.apache.mailet.base.GenericMatcher; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMatcherConfig; import org.apache.mailet.base.test.MailUtil; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; -public abstract class AbstractHasMailAttributeTest extends TestCase { +public abstract class AbstractHasMailAttributeTest { - protected FakeMail mockedMail; + FakeMail mockedMail; protected Matcher matcher; - protected static final String MAIL_ATTRIBUTE_NAME = "org.apache.james.test.junit"; - - protected static final String MAIL_ATTRIBUTE_VALUE = "true"; + static final String MAIL_ATTRIBUTE_NAME = "org.apache.james.test.junit"; - protected String mailAttributeName = "org.apache.james"; + static final String MAIL_ATTRIBUTE_VALUE = "true"; - protected String mailAttributeValue = "false"; + private String mailAttributeName = "org.apache.james"; - public AbstractHasMailAttributeTest() { - super(null); - } + private String mailAttributeValue = "false"; - protected void setMailAttributeName(String mailAttributeName) { + void setMailAttributeName(String mailAttributeName) { this.mailAttributeName = mailAttributeName; } - protected void setMailAttributeValue(String mailAttributeValue) { + void setMailAttributeValue(String mailAttributeValue) { this.mailAttributeValue = mailAttributeValue; } - protected void setupMockedMail() throws MessagingException { + void setupMockedMail() throws MessagingException { mockedMail = MailUtil.createMockMail2Recipients(); mockedMail.setAttribute(mailAttributeName, mailAttributeValue); } - protected void setupMatcher() throws MessagingException { + void setupMatcher() throws MessagingException { matcher = createMatcher(); FakeMatcherConfig mci = FakeMatcherConfig.builder() .matcherName(getMatcherName()) @@ -76,7 +76,7 @@ public abstract class AbstractHasMailAttributeTest extends TestCase { } - // test if the mail attribute was matched + @Test public void testAttributeIsMatched() throws MessagingException { init(); @@ -94,12 +94,12 @@ public abstract class AbstractHasMailAttributeTest extends TestCase { setMailAttributeValue(MAIL_ATTRIBUTE_VALUE); } - protected void setupAll() throws MessagingException { + void setupAll() throws MessagingException { setupMockedMail(); setupMatcher(); } - // test if the mail attribute was not matched + @Test public void testAttributeIsNotMatched() throws MessagingException { setupAll(); http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/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 a699073..63572b8 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 @@ -30,14 +30,14 @@ import org.apache.mailet.Mail; import org.apache.mailet.Matcher; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMatcherConfig; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class AllTest { private Matcher matcher; - @Before + @BeforeEach public void setupMatcher() throws MessagingException { matcher = new All(); FakeMatcherConfig mci = FakeMatcherConfig.builder() http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/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 d24bcf5..1103040 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 @@ -29,8 +29,8 @@ import org.apache.mailet.Matcher; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMatcherConfig; import org.apache.mailet.base.test.MailUtil; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class FetchedFromTest { private static final String EXPECTED_HEADER_VALUE = "james-user"; @@ -38,7 +38,7 @@ public class FetchedFromTest { private Matcher matcher; - @Before + @BeforeEach public void setUp() throws MessagingException { matcher = new FetchedFrom(); FakeMatcherConfig matcherConfig = FakeMatcherConfig.builder() http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/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 d758b22..56f9fc6 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 @@ -31,8 +31,8 @@ import javax.mail.internet.MimeMultipart; import org.apache.james.util.MimeMessageUtil; import org.apache.mailet.Mail; import org.apache.mailet.base.test.FakeMail; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class HasAttachmentTest { @@ -40,7 +40,7 @@ public class HasAttachmentTest { private MimeMessage mimeMessage; private Mail mail; - @Before + @BeforeEach public void setUp() throws Exception { testee = new HasAttachment(); http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasExceptionTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasExceptionTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasExceptionTest.java index e6e34de..3392e65 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasExceptionTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasExceptionTest.java @@ -30,15 +30,15 @@ import org.apache.mailet.Matcher; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMatcherConfig; import org.apache.mailet.base.test.MailUtil; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class HasExceptionTest { private FakeMail mockedMail; private Matcher testee; - @Before + @BeforeEach public void setUp() throws Exception { MimeMessage mimeMessage = MailUtil.createMimeMessage(); mockedMail = MailUtil.createMockMail2Recipients(mimeMessage); http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java index 3afb961..785c266 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java @@ -32,8 +32,8 @@ import org.apache.mailet.Matcher; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMatcherConfig; import org.apache.mailet.base.test.MailUtil; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class HasHeaderTest { @@ -45,7 +45,7 @@ public class HasHeaderTest { private FakeMail mockedMail; private Matcher matcher; - @Before + @BeforeEach public void setUp() throws Exception { MimeMessage mimeMessage = MailUtil.createMimeMessage(HEADER_NAME_1, HEADER_VALUE_1); mockedMail = MailUtil.createMockMail2Recipients(mimeMessage); http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderWithPrefixTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderWithPrefixTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderWithPrefixTest.java index b3843fa..1e85bfc 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderWithPrefixTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderWithPrefixTest.java @@ -21,6 +21,7 @@ package org.apache.james.transport.matchers; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import javax.mail.MessagingException; @@ -30,28 +31,23 @@ import org.apache.mailet.Matcher; import org.apache.mailet.base.MailAddressFixture; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMatcherConfig; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class HasHeaderWithPrefixTest { +class HasHeaderWithPrefixTest { private static final String PREFIX = "X-OPENPAAS-"; private static final String HEADER_NAME_PREFIX_1 = "X-OPENPAAS-FEATURE-A"; private static final String HEADER_NAME_NO_PREFIX = "X-OTHER-BUSINESS"; private Matcher matcher; - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() { matcher = new HasHeaderWithPrefix(); } @Test - public void matchShouldReturnAddressesWhenPrefixedHeaderName() throws MessagingException { + void matchShouldReturnAddressesWhenPrefixedHeaderName() throws MessagingException { FakeMatcherConfig matcherConfig = FakeMatcherConfig.builder() .matcherName("HasHeader") .condition(PREFIX) @@ -69,7 +65,7 @@ public class HasHeaderWithPrefixTest { } @Test - public void matchShouldReturnAddressesWhenExactlyPrefix() throws MessagingException { + void matchShouldReturnAddressesWhenExactlyPrefix() throws MessagingException { FakeMatcherConfig matcherConfig = FakeMatcherConfig.builder() .matcherName("HasHeader") .condition(PREFIX) @@ -87,7 +83,7 @@ public class HasHeaderWithPrefixTest { } @Test - public void matchShouldReturnEmptyWhenNoPrefixedHeader() throws MessagingException { + void matchShouldReturnEmptyWhenNoPrefixedHeader() throws MessagingException { FakeMatcherConfig matcherConfig = FakeMatcherConfig.builder() .matcherName("HasHeader") .condition(PREFIX) @@ -105,7 +101,7 @@ public class HasHeaderWithPrefixTest { } @Test - public void matchShouldReturnAddressesWhenAtLeastOneHeaderPrefixed() throws MessagingException { + void matchShouldReturnAddressesWhenAtLeastOneHeaderPrefixed() throws MessagingException { FakeMatcherConfig matcherConfig = FakeMatcherConfig.builder() .matcherName("HasHeader") .condition(PREFIX) @@ -124,22 +120,22 @@ public class HasHeaderWithPrefixTest { } @Test - public void initShouldRejectEmptyPrefix() throws MessagingException { - expectedException.expect(MessagingException.class); - - matcher.init(FakeMatcherConfig.builder() - .matcherName("HasHeader") - .condition("") - .build()); + void initShouldRejectEmptyPrefix() { + assertThatThrownBy(() -> + matcher.init(FakeMatcherConfig.builder() + .matcherName("HasHeader") + .condition("") + .build())) + .isInstanceOf(MessagingException.class); } @Test - public void initShouldRejectNoCondition() throws MessagingException { - expectedException.expect(MessagingException.class); - - matcher.init(FakeMatcherConfig.builder() - .matcherName("HasHeader") - .build()); + void initShouldRejectNoCondition() { + assertThatThrownBy(() -> + matcher.init(FakeMatcherConfig.builder() + .matcherName("HasHeader") + .build())) + .isInstanceOf(MessagingException.class); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasMailAttributeTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasMailAttributeTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasMailAttributeTest.java index 5d02173..e3d1c87 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasMailAttributeTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasMailAttributeTest.java @@ -24,10 +24,6 @@ import org.apache.mailet.base.GenericMatcher; public class HasMailAttributeTest extends AbstractHasMailAttributeTest { - public HasMailAttributeTest() { - super(); - } - @Override protected GenericMatcher createMatcher() { return new HasMailAttribute(); http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasMailAttributeWithValueRegexTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasMailAttributeWithValueRegexTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasMailAttributeWithValueRegexTest.java index cfa7b02..201929e 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasMailAttributeWithValueRegexTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasMailAttributeWithValueRegexTest.java @@ -20,24 +20,23 @@ package org.apache.james.transport.matchers; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + import java.util.Collection; import javax.mail.MessagingException; import org.apache.james.core.MailAddress; import org.apache.mailet.base.GenericMatcher; +import org.junit.jupiter.api.Test; +import org.opentest4j.AssertionFailedError; -import junit.framework.AssertionFailedError; - -public class HasMailAttributeWithValueRegexTest extends - AbstractHasMailAttributeTest { +public class HasMailAttributeWithValueRegexTest extends AbstractHasMailAttributeTest { private String regex = ".*"; - public HasMailAttributeWithValueRegexTest() { - super(); - } - private void setRegex(String regex) { this.regex = regex; } @@ -52,8 +51,8 @@ public class HasMailAttributeWithValueRegexTest extends return new HasMailAttributeWithValueRegex(); } - // test if the mail attribute was matched @Override + @Test public void testAttributeIsMatched() throws MessagingException { init(); setRegex(".*"); @@ -66,8 +65,8 @@ public class HasMailAttributeWithValueRegexTest extends .size()); } - // test if the mail attribute was not matched - public void testHeaderIsNotMatched() throws MessagingException { + @Test + void testHeaderIsNotMatched() throws MessagingException { setRegex("\\d"); setupAll(); @@ -76,8 +75,8 @@ public class HasMailAttributeWithValueRegexTest extends assertNull(matchedRecipients); } - // test if an exception was thrown cause the regex was invalid - public void testHeaderIsNotMatchedCauseValue() throws MessagingException { + @Test + void testHeaderIsNotMatchedCauseValue() throws MessagingException { String invalidRegex = "(!("; String regexException = null; http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasMailAttributeWithValueTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasMailAttributeWithValueTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasMailAttributeWithValueTest.java index 1aa1130..9412d88 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasMailAttributeWithValueTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasMailAttributeWithValueTest.java @@ -20,19 +20,18 @@ package org.apache.james.transport.matchers; +import static org.junit.jupiter.api.Assertions.assertNull; + import java.util.Collection; import javax.mail.MessagingException; import org.apache.james.core.MailAddress; import org.apache.mailet.base.GenericMatcher; +import org.junit.jupiter.api.Test; public class HasMailAttributeWithValueTest extends AbstractHasMailAttributeTest { - public HasMailAttributeWithValueTest() { - super(); - } - @Override protected String getHasMailAttribute() { return MAIL_ATTRIBUTE_NAME + ", " + MAIL_ATTRIBUTE_VALUE; @@ -43,8 +42,8 @@ public class HasMailAttributeWithValueTest extends AbstractHasMailAttributeTest return new HasMailAttributeWithValue(); } - // test if the mail attribute was not matched cause diffrent value - public void testAttributeIsNotMatchedCauseValue() throws MessagingException { + @Test + void testAttributeIsNotMatchedCauseValue() throws MessagingException { setMailAttributeName(MAIL_ATTRIBUTE_NAME); setupMockedMail(); setupMatcher(); http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasMimeTypeTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasMimeTypeTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasMimeTypeTest.java index fbdff6c..a12f187 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasMimeTypeTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasMimeTypeTest.java @@ -25,8 +25,8 @@ import org.apache.james.core.builder.MimeMessageBuilder; import org.apache.mailet.Mail; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMatcherConfig; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class HasMimeTypeTest { @@ -37,7 +37,7 @@ public class HasMimeTypeTest { private HasMimeType matcher; - @Before + @BeforeEach public void setUp() throws Exception { matcher = new HasMimeType(); } http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/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 1c0b7aa..5d6c41a 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 @@ -37,14 +37,14 @@ import org.apache.mailet.MailetContext; import org.apache.mailet.Matcher; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMatcherConfig; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class HostIsLocalTest { private Matcher matcher; - @Before + @BeforeEach public void setUp() throws Exception { MailetContext mailContext = mock(MailetContext.class); when(mailContext.isLocalServer(JAMES_APACHE_ORG)).thenReturn(true); http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/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 81a5eaf..af342e8 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 @@ -32,14 +32,14 @@ import org.apache.mailet.Mail; import org.apache.mailet.Matcher; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMatcherConfig; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class HostIsTest { private Matcher matcher; - @Before + @BeforeEach public void setUp() throws Exception { matcher = new HostIs(); FakeMatcherConfig mci = FakeMatcherConfig.builder() http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/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 32f342d..87cebd5 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 @@ -29,14 +29,14 @@ import javax.mail.MessagingException; import org.apache.mailet.Matcher; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMatcherConfig; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class IsSingleRecipientTest { private Matcher matcher; - @Before + @BeforeEach public void setUp() throws MessagingException { matcher = new IsSingleRecipient(); FakeMatcherConfig matcherConfig = FakeMatcherConfig.builder() http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/mailet/standard/src/test/java/org/apache/james/transport/matchers/NESSpamCheckTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/NESSpamCheckTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/NESSpamCheckTest.java index da0be46..6186cba 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/NESSpamCheckTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/NESSpamCheckTest.java @@ -27,14 +27,14 @@ import org.apache.mailet.Mail; import org.apache.mailet.base.RFC2822Headers; import org.apache.mailet.base.test.FakeMatcherConfig; import org.apache.mailet.base.test.MailUtil; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class NESSpamCheckTest { private NESSpamCheck matcher; - @Before + @BeforeEach public void setUp() throws Exception { matcher = new NESSpamCheck(); FakeMatcherConfig mci = FakeMatcherConfig.builder() http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsLocalTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsLocalTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsLocalTest.java index 1825e39..b45ac0a 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsLocalTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsLocalTest.java @@ -28,8 +28,8 @@ import org.apache.mailet.Mail; import org.apache.mailet.MailetContext; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMatcherConfig; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class RecipientIsLocalTest { @@ -40,7 +40,7 @@ public class RecipientIsLocalTest { private MailAddress mailAddress2; private Mail mail; - @Before + @BeforeEach public void setUp() throws Exception { mailetContext = mock(MailetContext.class); testee = new RecipientIsLocal(); http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsRegexTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsRegexTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsRegexTest.java index 89d460e..e0710d9 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsRegexTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsRegexTest.java @@ -23,30 +23,26 @@ 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 static org.assertj.core.api.Assertions.assertThatThrownBy; import javax.mail.MessagingException; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMatcherConfig; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class RecipientIsRegexTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); +class RecipientIsRegexTest { private RecipientIsRegex matcher; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() { matcher = new RecipientIsRegex(); } @Test - public void shouldMatchOneAddress() throws MessagingException { + void shouldMatchOneAddress() throws MessagingException { matcher.init(FakeMatcherConfig.builder() .matcherName("RecipientIsRegex") .condition(".*@.*") @@ -60,7 +56,7 @@ public class RecipientIsRegexTest { } @Test - public void shouldNotMatchPartially() throws MessagingException { + void shouldNotMatchPartially() throws MessagingException { matcher.init(FakeMatcherConfig.builder() .matcherName("RecipientIsRegex") .condition("any") @@ -74,7 +70,7 @@ public class RecipientIsRegexTest { } @Test - public void shouldMatchOnlyMatchingPatterns() throws MessagingException { + void shouldMatchOnlyMatchingPatterns() throws MessagingException { matcher.init(FakeMatcherConfig.builder() .matcherName("RecipientIsRegex") .condition("^any@.*") @@ -88,7 +84,7 @@ public class RecipientIsRegexTest { } @Test - public void shouldNotMatchNonMatchingPatterns() throws MessagingException { + void shouldNotMatchNonMatchingPatterns() throws MessagingException { matcher.init(FakeMatcherConfig.builder() .matcherName("RecipientIsRegex") .condition(".*\\+") @@ -102,27 +98,30 @@ public class RecipientIsRegexTest { } @Test - public void testRegexIsNotMatchedCauseError() throws MessagingException { - expectedException.expect(MessagingException.class); - matcher.init(FakeMatcherConfig.builder() + void testRegexIsNotMatchedCauseError() { + assertThatThrownBy(() -> + matcher.init(FakeMatcherConfig.builder() .matcherName("RecipientIsRegex") .condition("(.") - .build()); + .build())) + .isInstanceOf(MessagingException.class); } @Test - public void testThrowExceptionWithEmptyPattern() throws MessagingException { - expectedException.expect(MessagingException.class); - matcher.init(FakeMatcherConfig.builder() + void testThrowExceptionWithEmptyPattern() { + assertThatThrownBy(() -> + matcher.init(FakeMatcherConfig.builder() .matcherName("RecipientIsRegex") - .build()); + .build())) + .isInstanceOf(MessagingException.class); } @Test - public void testThrowExceptionWithNoCondition() throws MessagingException { - expectedException.expect(MessagingException.class); - matcher.init(FakeMatcherConfig.builder() + void testThrowExceptionWithNoCondition() { + assertThatThrownBy(() -> + matcher.init(FakeMatcherConfig.builder() .matcherName("RecipientIsRegex") - .build()); + .build())) + .isInstanceOf(MessagingException.class); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/1e365b3e/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsTest.java ---------------------------------------------------------------------- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsTest.java index b7e2e04..95f4781 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsTest.java @@ -24,30 +24,26 @@ import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES; import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES2; import static org.apache.mailet.base.MailAddressFixture.OTHER_AT_JAMES; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import javax.mail.MessagingException; import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMatcherConfig; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class RecipientIsTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); +class RecipientIsTest { private RecipientIs matcher; - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() { matcher = new RecipientIs(); } @Test - public void shouldMatchCorrespondingAddres() throws Exception { + void shouldMatchCorrespondingAddres() throws Exception { matcher.init(FakeMatcherConfig.builder() .matcherName("RecipientIs") .condition(ANY_AT_JAMES.toString()) @@ -61,7 +57,7 @@ public class RecipientIsTest { } @Test - public void shouldOnlyMatchCorrespondingAddress() throws Exception { + void shouldOnlyMatchCorrespondingAddress() throws Exception { matcher.init(FakeMatcherConfig.builder() .matcherName("RecipientIs") .condition(ANY_AT_JAMES.toString()) @@ -75,7 +71,7 @@ public class RecipientIsTest { } @Test - public void shouldNotMatchUnrelatedAddresses() throws Exception { + void shouldNotMatchUnrelatedAddresses() throws Exception { matcher.init(FakeMatcherConfig.builder() .matcherName("RecipientIs") .condition(ANY_AT_JAMES.toString()) @@ -89,23 +85,25 @@ public class RecipientIsTest { } @Test - public void initShouldThrowOnMissingCondition() throws Exception { - expectedException.expect(MessagingException.class); - matcher.init(FakeMatcherConfig.builder() + void initShouldThrowOnMissingCondition() { + assertThatThrownBy(() -> + matcher.init(FakeMatcherConfig.builder() .matcherName("RecipientIs") - .build()); + .build())) + .isInstanceOf(MessagingException.class); } @Test - public void initShouldThrowOnEmptyCondition() throws Exception { - expectedException.expect(MessagingException.class); - matcher.init(FakeMatcherConfig.builder() + void initShouldThrowOnEmptyCondition() { + assertThatThrownBy(() -> + matcher.init(FakeMatcherConfig.builder() .matcherName("RecipientIs") - .build()); + .build())) + .isInstanceOf(MessagingException.class); } @Test - public void shouldBeAbleToMatchSeveralAddresses() throws Exception { + void shouldBeAbleToMatchSeveralAddresses() throws Exception { matcher.init(FakeMatcherConfig.builder() .matcherName("RecipientIs") .condition(ANY_AT_JAMES + ", " + ANY_AT_JAMES2) --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org