Skip to content
Permalink
Browse files

Merge pull request #35 from varyvol/JENKINS-41881

[JENKINS-41881] Automated test to cover fix for JENKINS-40224
  • Loading branch information
jglick committed Feb 14, 2017
2 parents 5962552 + 90afad3 commit d54f8d8ed32227c66a9a24a1a31986a19838ce26
Showing with 27 additions and 1 deletion.
  1. +0 −1 src/main/java/hudson/tasks/MailSender.java
  2. +27 −0 src/test/java/hudson/tasks/MailerTest.java
@@ -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 {
@@ -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;
@@ -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;


/**
@@ -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;
@@ -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 {
@@ -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.
You can’t perform that action at this time.