Skip to content

Commit

Permalink
Merge pull request #35 from varyvol/JENKINS-41881
Browse files Browse the repository at this point in the history
[JENKINS-41881] Automated test to cover fix for JENKINS-40224
  • Loading branch information
jglick committed Feb 14, 2017
2 parents 5962552 + 90afad3 commit d54f8d8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/main/java/hudson/tasks/MailSender.java
Expand Up @@ -238,7 +238,6 @@ else if(prev.getResult()==Result.UNSTABLE) {
StringBuilder buf = new StringBuilder();
DisplayURLProvider displayURLProvider = DisplayURLProvider.get();
// Link to project changes summary for "still unstable" if this or last build has changes
String url;
if (still && !(getChangeSet(build).isEmptySet() && getChangeSet(prev).isEmptySet())) {
appendUrl(displayURLProvider.getChangesURL(build), buf);
} else {
Expand Down
27 changes: 27 additions & 0 deletions src/test/java/hudson/tasks/MailerTest.java
Expand Up @@ -32,6 +32,7 @@
import org.jvnet.hudson.test.FailureBuilder;
import org.jvnet.hudson.test.Email;
import org.jvnet.hudson.test.FakeChangeLogSCM;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.JenkinsRule.WebClient;
import org.jvnet.hudson.test.UnstableBuilder;
Expand All @@ -47,6 +48,8 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.containsString;


/**
Expand Down Expand Up @@ -229,6 +232,18 @@ public void testNotifyCulprits() throws Exception {
project.commit(AUTHOR2).failure().clearBuild().check(1, 0, 1);
}

@Issue("JENKINS-40224")
@Test
public void testMessageText() throws Exception {
create(true, false)
.failure()
.buildAndCheckContent()
.unstable()
.buildAndCheckContent()
.success()
.buildAndCheckContent();
}

private final class TestProject {
private final FakeChangeLogSCM scm = new FakeChangeLogSCM();
private final FreeStyleProject project;
Expand Down Expand Up @@ -283,6 +298,12 @@ TestProject buildAndCheck(int expectedSize, String recipient) throws Exception {
TestProject buildAndCheck(int expectedSize) throws Exception {
return buildAndCheck(expectedSize, RECIPIENT);
}

TestProject buildAndCheckContent() throws Exception {
build(RECIPIENT).checkContent();

return this;
}
}

private final class TestBuild {
Expand All @@ -303,6 +324,12 @@ TestBuild check(int expectedSize, String recipient) throws Exception {
TestBuild check(int expectedRecipient, int expectedAuthor1, int expectedAuthor2) throws Exception {
return check(expectedRecipient, RECIPIENT).check(expectedAuthor1, AUTHOR1).check(expectedAuthor2, AUTHOR2);
}

void checkContent() throws Exception {
String expectedInMessage = String.format("<%sjob/%s/%d/display/redirect>\n\n", rule.getURL(), this.build.getProject().getName(), this.build.getNumber());
String emailContent = getMailbox(RECIPIENT).get(0).getContent().toString();
assertThat(emailContent, containsString(expectedInMessage));
}
}

}

0 comments on commit d54f8d8

Please sign in to comment.