Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add removeNewlines parameter. Fix issue when job description is not set (null)
- Loading branch information
Showing
2 changed files
with
66 additions
and
1 deletion.
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
54 changes: 54 additions & 0 deletions
54
src/test/java/org/jenkinsci/plugins/tokenmacro/impl/JobDescriptionMacroTest.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,54 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
|
||
package org.jenkinsci.plugins.tokenmacro.impl; | ||
|
||
import hudson.model.FreeStyleBuild; | ||
import hudson.model.FreeStyleProject; | ||
import hudson.util.StreamTaskListener; | ||
import jenkins.model.JenkinsLocationConfiguration; | ||
import static junit.framework.TestCase.assertEquals; | ||
import org.jenkinsci.plugins.tokenmacro.TokenMacro; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.Issue; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
/** | ||
* | ||
* @author acearl | ||
*/ | ||
public class JobDescriptionMacroTest { | ||
@Rule | ||
public final JenkinsRule j = new JenkinsRule(); | ||
|
||
@Test | ||
public void testNoDescription() throws Exception { | ||
FreeStyleProject p = j.createFreeStyleProject("noDescription"); | ||
FreeStyleBuild b = p.scheduleBuild2(0).get(); | ||
|
||
assertEquals("",TokenMacro.expand(b, StreamTaskListener.fromStdout(),"${JOB_DESCRIPTION}")); | ||
} | ||
|
||
@Test | ||
public void testSimple() throws Exception { | ||
FreeStyleProject p = j.createFreeStyleProject("testSimple"); | ||
p.setDescription("This is the description"); | ||
FreeStyleBuild b = p.scheduleBuild2(0).get(); | ||
|
||
assertEquals("This is the description",TokenMacro.expand(b, StreamTaskListener.fromStdout(),"${JOB_DESCRIPTION}")); | ||
} | ||
|
||
@Issue("JENKINS-32012") | ||
@Test | ||
public void testRemoveNewlines() throws Exception { | ||
FreeStyleProject p = j.createFreeStyleProject("testRemoveNewlines"); | ||
p.setDescription("This is a description\nwith a newline"); | ||
FreeStyleBuild b = p.scheduleBuild2(0).get(); | ||
|
||
assertEquals("This is a description with a newline", TokenMacro.expand(b, StreamTaskListener.fromStdout(), "${JOB_DESCRIPTION, removeNewlines=true}")); | ||
} | ||
} |