-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-25083] use MailAddressResolver for retrieving user email ins…
…tead of UserProperty
- Loading branch information
1 parent
2bf637d
commit a19c343
Showing
2 changed files
with
54 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
51 changes: 51 additions & 0 deletions
51
.../java/org/jenkinsci/plugins/builduser/varsetter/impl/UserIdCauseDeterminantEmailTest.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,51 @@ | ||
package org.jenkinsci.plugins.builduser.varsetter.impl; | ||
|
||
import hudson.model.Cause.UserIdCause; | ||
import hudson.model.User; | ||
import hudson.tasks.MailAddressResolver; | ||
import hudson.tasks.Mailer.UserProperty; | ||
import org.jenkinsci.plugins.builduser.utils.BuildUserVariable; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.TestExtension; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class UserIdCauseDeterminantEmailTest { | ||
public static final String TEST_USER = "test_user"; | ||
|
||
@Rule | ||
public JenkinsRule r = new JenkinsRule(); | ||
|
||
@Test | ||
public void testSetJenkinsUserBuildVarsEmailWithResolver() throws IOException { | ||
User user = User.getById(TEST_USER, true); | ||
assert user != null; | ||
user.addProperty(new UserProperty(null)); | ||
|
||
JenkinsRule.DummySecurityRealm realm = r.createDummySecurityRealm(); | ||
r.jenkins.setSecurityRealm(realm); | ||
|
||
Map<String, String> outputVars = new HashMap<>(); | ||
UserIdCause cause = new UserIdCause(TEST_USER); | ||
UserIdCauseDeterminant determinant = new UserIdCauseDeterminant(); | ||
determinant.setJenkinsUserBuildVars(cause, outputVars); | ||
|
||
assertThat(outputVars.get(BuildUserVariable.EMAIL), is(equalTo("[email protected]"))); | ||
} | ||
|
||
@TestExtension | ||
public static class TestMailAddressResolver extends MailAddressResolver { | ||
@Override | ||
public String findMailAddressFor(User user) { | ||
return "[email protected]"; | ||
} | ||
} | ||
} |