Skip to content

Commit

Permalink
Fix: Maven plugin sends email notification to null address
Browse files Browse the repository at this point in the history
[FIXED JENKINS-20209]
  • Loading branch information
mrebasti committed Oct 23, 2013
1 parent 2033129 commit be12460
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/main/java/hudson/maven/reporters/MavenMailer.java
Expand Up @@ -31,6 +31,7 @@
import hudson.model.BuildListener;
import hudson.tasks.MailSender;
import hudson.tasks.Mailer;

import org.kohsuke.stapler.StaplerRequest;

import java.io.IOException;
Expand Down Expand Up @@ -59,9 +60,17 @@ public boolean end(MavenBuild build, Launcher launcher, BuildListener listener)
}

public String getAllRecipients() {
return this.recipients == null ?
this.mavenRecipients :
this.recipients + " " + this.mavenRecipients;
StringBuilder sb = new StringBuilder();

if (this.recipients != null) {
sb.append(this.recipients);
}
if (this.mavenRecipients != null) {
sb.append(" ");
sb.append(this.mavenRecipients);
}

return sb.toString().trim();
}

@Extension
Expand Down
30 changes: 30 additions & 0 deletions src/test/java/hudson/maven/reporters/MavenMailerTest.java
Expand Up @@ -215,6 +215,36 @@ public void testCiManagementNotificationModule() throws Exception {
assertEquals(2, message.getAllRecipients().length);
assertContainsRecipient(EMAIL_JENKINS_CONFIGURED, message);

}

@Test
@Bug(20209)
public void testRecipientsNotNullAndMavenRecipientsNull () {
MavenMailer fixture = new MavenMailer();
fixture.recipients = "your-mail@gmail.com";
fixture.mavenRecipients = null;

assertEquals("your-mail@gmail.com", fixture.getAllRecipients());
}

@Test
@Bug(20209)
public void testMavenRecipientsNotNullAndRecipientsNull () {
MavenMailer fixture = new MavenMailer();
fixture.recipients = null;
fixture.mavenRecipients = "your-mail@gmail.com";

assertEquals("your-mail@gmail.com", fixture.getAllRecipients());
}

@Test
@Bug(20209)
public void testMavenRecipientsAndRecipientsNotNull () {
MavenMailer fixture = new MavenMailer();
fixture.recipients = "your-mail@gmail.com";
fixture.mavenRecipients = "your-other-mail@gmail.com";

assertEquals("your-mail@gmail.com your-other-mail@gmail.com", fixture.getAllRecipients());
}

private void assertContainsRecipient(String email, Message message) throws Exception {
Expand Down

0 comments on commit be12460

Please sign in to comment.