Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Switch to mock-javamail instead of using outdated and buggy dumbster.

  • Loading branch information...
commit d483c62c08377f2275d56a16b593938112c1d5d8 1 parent c77ea3b
@mmichaelis authored
View
6 pom.xml
@@ -89,9 +89,9 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>dumbster</groupId>
- <artifactId>dumbster</artifactId>
- <version>1.6</version>
+ <groupId>org.jvnet.mock-javamail</groupId>
+ <artifactId>mock-javamail</artifactId>
+ <version>1.7</version>
<scope>test</scope>
</dependency>
<dependency>
View
71 src/test/java/de/mmichaelis/maven/mojo/AbstractMailMojoTestBase.java
@@ -1,71 +0,0 @@
-/******************************************************************************
- * Copyright 2011 Mark Michaelis *
- * *
- * Licensed 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 de.mmichaelis.maven.mojo;
-
-import com.dumbster.smtp.SimpleSmtpServer;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-
-/**
- * @since 5/28/11 9:01 PM
- */
-public abstract class AbstractMailMojoTestBase {
- /**
- * Logger Instance.
- */
- private static final Logger LOG = LoggerFactory.getLogger(AbstractMailMojoTestBase.class);
-
-
- protected SimpleSmtpServer smtpServer;
- protected static int smtpPort;
-
- private static int findFreePort() throws IOException {
- final ServerSocket server = new ServerSocket(0);
- final int port;
- try {
- port = server.getLocalPort();
- } finally {
- server.close();
- }
- return port;
- }
-
- @BeforeClass
- public static void setUpClass() throws Exception {
- smtpPort = findFreePort();
- System.setProperty("mail.mime.foldtext", "false");
- }
-
- @Before
- public void setUp() throws Exception {
- LOG.info("Starting SMTP Server at port " + smtpPort);
- smtpServer = SimpleSmtpServer.start(smtpPort);
- }
-
- @After
- public void tearDown() throws Exception {
- smtpServer.stop();
- LOG.info("Stopped SMTP Server.");
- }
-}
View
62 src/test/java/de/mmichaelis/maven/mojo/MailDevelopersMojoTest.java
@@ -16,20 +16,19 @@
package de.mmichaelis.maven.mojo;
-import com.dumbster.smtp.SmtpMessage;
import org.apache.maven.model.Developer;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.jvnet.mock_javamail.Mailbox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.mail.Message;
import java.util.Arrays;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;
@@ -38,7 +37,7 @@
*
* @since 5/27/11 11:26 PM
*/
-public class MailDevelopersMojoTest extends AbstractMailMojoTestBase {
+public class MailDevelopersMojoTest {
/**
* Logger Instance.
*/
@@ -46,16 +45,13 @@
// Actually we cannot have more than 2 developers as the third one will be wrapped and dumpster seems to be
// unable to handle wrapped headers.
- private static final int MAX_DEVELOPERS = 2;
+ private static final int MAX_DEVELOPERS = 4;
private MailDevelopersMojoWrapper mojoWrapper;
private Developer[] developers;
- @Override
@Before
public void setUp() throws Exception {
- super.setUp();
-
developers = new Developer[MAX_DEVELOPERS];
for (int i = 0; i < MAX_DEVELOPERS; i++) {
final Developer developer = new Developer();
@@ -66,8 +62,11 @@ public void setUp() throws Exception {
}
mojoWrapper = new MailDevelopersMojoWrapper(new MailDevelopersMojo());
+ }
- mojoWrapper.setSmtpPort(String.valueOf(smtpPort));
+ @After
+ public void tearDown() throws Exception {
+ Mailbox.clearAll();
}
@Test
@@ -80,40 +79,29 @@ public void testMailToTwoDevelopers() throws Exception {
doTestMailToDevelopers(2);
}
- private void doTestMailToDevelopers(final int numDevelopers) throws IllegalAccessException, MojoExecutionException, MojoFailureException {
+ @Test
+ public void testMailToThreeDevelopers() throws Exception {
+ doTestMailToDevelopers(3);
+ }
+
+ @Test
+ public void testMailToFourDevelopers() throws Exception {
+ doTestMailToDevelopers(4);
+ }
+
+ private void doTestMailToDevelopers(final int numDevelopers) throws Exception {
final MavenProject project = mock(MavenProject.class);
when(project.getDevelopers()).thenReturn(Arrays.asList(Arrays.copyOf(developers, numDevelopers)));
mojoWrapper.setProject(project);
final MailDevelopersMojo mojo = mojoWrapper.getMojo();
mojo.execute();
- assertEquals("Should have received one email.", 1, smtpServer.getReceivedEmailSize());
- final SmtpMessage mail = (SmtpMessage) smtpServer.getReceivedEmail().next();
- LOG.debug("Mail for one developer:\n" + mail);
- final String tos = Arrays.toString(mail.getHeaderValues("To"));
- LOG.debug("Header(To): " + tos);
for (int i = 0; i < numDevelopers; i++) {
- assertTrue("Mail of developer no. " + i + " should be contained in header.", tos.contains(developers[i].getEmail()));
- }
- }
-
- /**
- * Simple test to send an email.
- *
- * @throws Exception in case of an error
- */
-/*
- @Test
- public void testSimple() throws Exception {
- mojoWrapper.execute();
- assertTrue(smtpServer.getReceivedEmailSize() == 1);
- final SmtpMessage next = (SmtpMessage) smtpServer.getReceivedEmail().next();
- System.out.println(next);
- final String[] tos = next.getHeaderValues("To");
- for (int i = 0; i < tos.length; i++) {
- String to = tos[i];
- System.out.println(to);
+ final Developer developer = developers[i];
+ final Mailbox inbox = Mailbox.get(developer.getEmail());
+ assertEquals("Should have received one email.", 1, inbox.size());
+ final Message message = inbox.get(0);
+ LOG.debug("Mail for one developer:\n" + message);
}
}
-*/
}
Please sign in to comment.
Something went wrong with that request. Please try again.