Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JENKINS-35365 EMail-Ext Extended Pipeline Support - Recipient Providers
unit tests
- Loading branch information
1 parent
e6ed1ee
commit 33bb4cd
Showing
4 changed files
with
104 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/test/java/hudson/plugins/emailext/plugins/recipients/RecipientProviderUtilitiesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package hudson.plugins.emailext.plugins.recipients; | ||
|
||
import hudson.model.Run; | ||
import hudson.model.User; | ||
import hudson.scm.ChangeLogSet; | ||
import hudson.tasks.Mailer; | ||
import org.hamcrest.CoreMatchers; | ||
import org.hamcrest.collection.IsCollectionWithSize; | ||
import org.jenkinsci.plugins.workflow.job.WorkflowRun; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import static org.junit.Assert.assertThat; | ||
import static org.powermock.api.mockito.PowerMockito.mock; | ||
import static org.powermock.api.mockito.PowerMockito.when; | ||
|
||
|
||
@RunWith(PowerMockRunner.class) | ||
@PrepareForTest({ | ||
WorkflowRun.class | ||
}) | ||
public class RecipientProviderUtilitiesTest { | ||
public class Debug implements RecipientProviderUtilities.IDebug { | ||
|
||
@Override | ||
public void send(String format, Object... args) { | ||
|
||
} | ||
} | ||
|
||
public static Set<String> usersToEMails(Set<User> users) { | ||
Set<String> emails = new HashSet<>(users.size()); | ||
for (User user : users) { | ||
emails.add(user.getProperty(Mailer.UserProperty.class).getAddress()); | ||
} | ||
return emails; | ||
} | ||
|
||
@Test | ||
public void getChangeSetAuthors() throws Exception { | ||
Debug debug = new Debug(); | ||
WorkflowRun run1 = mock(WorkflowRun.class); | ||
Set<User> authors = RecipientProviderUtilities.getChangeSetAuthors(Collections.<Run<?, ?>>singleton(run1), debug); | ||
assertThat(authors, IsCollectionWithSize.hasSize(0)); | ||
|
||
ChangeLogSet<? extends ChangeLogSet.Entry> changeSet1 = MockUtilities.makeChangeSet(run1, "A"); | ||
ChangeLogSet<? extends ChangeLogSet.Entry> changeSet2 = MockUtilities.makeChangeSet(run1, "B"); | ||
when(run1.getChangeSets()).thenReturn(Arrays.asList(changeSet1, changeSet2)); | ||
|
||
authors = RecipientProviderUtilities.getChangeSetAuthors(Collections.<Run<?, ?>>singleton(run1), debug); | ||
assertThat(usersToEMails(authors), CoreMatchers.<Set<String>>equalTo(new HashSet<>(Arrays.asList("A@DOMAIN", "B@DOMAIN")))); | ||
|
||
WorkflowRun run2 = mock(WorkflowRun.class); | ||
MockUtilities.addChangeSet(run2, "C"); | ||
|
||
authors = RecipientProviderUtilities.getChangeSetAuthors(Arrays.<Run<?, ?>>asList(run1, run2), debug); | ||
assertThat(usersToEMails(authors), CoreMatchers.<Set<String>>equalTo(new HashSet<>(Arrays.asList("A@DOMAIN", "B@DOMAIN", "C@DOMAIN")))); | ||
} | ||
|
||
@Test | ||
public void getUsersTriggeringTheBuilds() throws Exception { | ||
|
||
} | ||
|
||
@Test | ||
public void getUserTriggeringTheBuild() throws Exception { | ||
|
||
} | ||
|
||
@Test | ||
public void addUsers() throws Exception { | ||
|
||
} | ||
|
||
} |