true to simulate old behavior.
+ *
+ * see JENKINS-5695.
+ */
+ private Boolean perModuleEmail = Boolean.TRUE;
/**
* If true, do not automatically schedule a build when one of the project dependencies is built.
@@ -436,6 +444,10 @@ public class MavenModuleSet extends AbstractMavenProject
+
+ If checked, Jenkins will send an e-mail notifications for each module (e.g. failed, unstable).
+
\ No newline at end of file
diff --git a/test/src/test/java/hudson/maven/reporters/MavenMailerTest.java b/test/src/test/java/hudson/maven/reporters/MavenMailerTest.java
new file mode 100644
index 0000000000..e41dd37f78
--- /dev/null
+++ b/test/src/test/java/hudson/maven/reporters/MavenMailerTest.java
@@ -0,0 +1,67 @@
+package hudson.maven.reporters;
+
+import hudson.maven.MavenModuleSet;
+import hudson.model.Result;
+import hudson.tasks.Mailer;
+import hudson.tasks.Mailer.DescriptorImpl;
+
+import javax.mail.Address;
+import javax.mail.internet.InternetAddress;
+
+import jenkins.model.Jenkins;
+
+import org.jvnet.hudson.test.Bug;
+import org.jvnet.hudson.test.ExtractResourceSCM;
+import org.jvnet.hudson.test.HudsonTestCase;
+import org.jvnet.mock_javamail.Mailbox;
+
+public class MavenMailerTest extends HudsonTestCase {
+
+ @Bug(5695)
+ public void testMulipleMails() throws Exception {
+
+ final Mailbox inbox = runMailTest(true);
+ assertEquals(2, inbox.size());
+
+ }
+
+ @Bug(5695)
+ public void testSingleMails() throws Exception {
+
+ final Mailbox inbox = runMailTest(false);
+ assertEquals(1, inbox.size());
+
+ }
+
+ public Mailbox runMailTest(boolean perModuleEamil) throws Exception {
+
+ final DescriptorImpl mailDesc = Jenkins.getInstance().getDescriptorByType(Mailer.DescriptorImpl.class);
+
+ // intentionally give the whole thin in a double quote
+ Mailer.descriptor().setAdminAddress("\"me \"");
+
+ String recipient = "you ";
+ Mailbox yourInbox = Mailbox.get(new InternetAddress(recipient));
+ yourInbox.clear();
+
+ configureDefaultMaven();
+ MavenModuleSet mms = createMavenProject();
+ mms.setGoals("test");
+ mms.setScm(new ExtractResourceSCM(getClass().getResource("/hudson/maven/maven-multimodule-unit-failure.zip")));
+ assertBuildStatus(Result.UNSTABLE, mms.scheduleBuild2(0).get());
+
+ MavenMailer m = new MavenMailer();
+ m.recipients = recipient;
+ m.perModuleEmail = perModuleEamil;
+ mms.getReporters().add(m);
+
+ mms.scheduleBuild2(0).get();
+
+ Address[] senders = yourInbox.get(0).getFrom();
+ assertEquals(1, senders.length);
+ assertEquals("me ", senders[0].toString());
+
+ return yourInbox;
+ }
+
+}