Skip to content

Commit

Permalink
Rewriting ExtendedEmailPublisherMatrixTest to use ClassRule (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Oct 23, 2020
1 parent 9e251cd commit 22f1e78
Showing 1 changed file with 42 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
import hudson.plugins.emailext.plugins.trigger.AlwaysTrigger;
import hudson.plugins.emailext.plugins.trigger.PreBuildTrigger;
import hudson.slaves.DumbSlave;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.mock_javamail.Mailbox;

Expand All @@ -35,41 +40,43 @@ public class ExtendedEmailPublisherMatrixTest {

private ExtendedEmailPublisher publisher;
private MatrixProject project;
private List<DumbSlave> agents;

@Rule
public JenkinsRule j = new JenkinsRule() {
@Override
public void before() throws Throwable {
super.before();

ExtendedEmailPublisherDescriptor descriptor = ExtendedEmailPublisher.descriptor();
descriptor.setMailAccount(new MailAccount() {
{
setSmtpHost("smtp.notreal.com");
}
});

publisher = new ExtendedEmailPublisher();
publisher.defaultSubject = "%DEFAULT_SUBJECT";
publisher.defaultContent = "%DEFAULT_CONTENT";
publisher.attachBuildLog = false;

project = j.jenkins.createProject(MatrixProject.class, "Foo");
project.getPublishersList().add( publisher );
agents = new ArrayList<>();
agents.add(createOnlineSlave(new LabelAtom("success-agent1")));
agents.add(createOnlineSlave(new LabelAtom("success-agent2")));
agents.add(createOnlineSlave(new LabelAtom("success-agent3")));
}

@Override
public void after() throws Exception {
super.after();
agents.clear();
Mailbox.clearAll();
}
};
private static List<DumbSlave> agents;

@ClassRule public static JenkinsRule j = new JenkinsRule();

@Rule public TestName testName = new TestName();

@BeforeClass
public static void beforeClass() throws Exception {
ExtendedEmailPublisherDescriptor descriptor = ExtendedEmailPublisher.descriptor();
descriptor.setMailAccount(
new MailAccount() {
{
setSmtpHost("smtp.notreal.com");
}
});

agents = new ArrayList<>();
agents.add(j.createOnlineSlave(new LabelAtom("success-agent1")));
agents.add(j.createOnlineSlave(new LabelAtom("success-agent2")));
agents.add(j.createOnlineSlave(new LabelAtom("success-agent3")));
}

@Before
public void before() throws Exception {
publisher = new ExtendedEmailPublisher();
publisher.defaultSubject = "%DEFAULT_SUBJECT";
publisher.defaultContent = "%DEFAULT_CONTENT";
publisher.attachBuildLog = false;

project = j.createProject(MatrixProject.class, testName.getMethodName());
project.getPublishersList().add(publisher);
}

@After
public void after() {
Mailbox.clearAll();
}

@Test
public void testPreBuildMatrixBuildSendParentOnly() throws Exception {
Expand Down

0 comments on commit 22f1e78

Please sign in to comment.