-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace <a> tags with Slack <link|name>
Replace <a href...>text</a> with <url|text> before escaping the remaining parts of the message fixes #126 fixes nishio-dens/bitbucket-pullrequest-builder-plugin#59
- Loading branch information
Showing
2 changed files
with
93 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
66 changes: 66 additions & 0 deletions
66
src/test/java/jenkins/plugins/slack/workflow/MessageBuilderTest.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,66 @@ | ||
package jenkins.plugins.slack.workflow; | ||
|
||
import hudson.model.FreeStyleBuild; | ||
import hudson.model.FreeStyleProject; | ||
import hudson.model.ItemGroup; | ||
import jenkins.plugins.slack.ActiveNotifier; | ||
import junit.framework.TestCase; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.mockito.Mockito; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
@RunWith(Parameterized.class) | ||
public class MessageBuilderTest extends TestCase { | ||
|
||
private ActiveNotifier.MessageBuilder messageBuilder; | ||
private String expectedResult; | ||
private FreeStyleBuild build; | ||
|
||
|
||
@Before | ||
@Override | ||
public void setUp() throws IOException, ExecutionException, InterruptedException { | ||
messageBuilder = new ActiveNotifier.MessageBuilder(null, build); | ||
} | ||
|
||
public MessageBuilderTest(String projectDisplayName, String buildDisplayName, String expectedResult) { | ||
this.build = Mockito.mock(FreeStyleBuild.class); | ||
FreeStyleProject project = Mockito.mock(FreeStyleProject.class); | ||
|
||
Mockito.when(build.getProject()).thenReturn(project); | ||
Mockito.when(build.getDisplayName()).thenReturn(buildDisplayName); | ||
|
||
ItemGroup ig = Mockito.mock(ItemGroup.class); | ||
Mockito.when(ig.getFullDisplayName()).thenReturn(""); | ||
Mockito.when(project.getParent()).thenReturn(ig); | ||
Mockito.when(project.getDisplayName()).thenReturn(projectDisplayName); | ||
|
||
this.expectedResult = expectedResult; | ||
|
||
} | ||
|
||
@Parameterized.Parameters | ||
public static Collection businessTypeKeys() { | ||
return Arrays.asList(new Object[][]{ | ||
{"", "", " - "}, | ||
{"project", "#43 Started by changes from Bob", "project - #43 Started by changes from Bob "}, | ||
{"project", "#541 <a href=\"https://bitbucket.org/org/project/pull-request/125\">#125 Bug</a>", | ||
"project - #541 <https://bitbucket.org/org/project/pull-request/125|#125 Bug> "}, | ||
{"project", "#541 <b>Bold Project</b>", "project - #541 <b>Bold Project</b> "}, | ||
{"project", "#541 <a no-url>bob</a>", "project - #541 <a no-url>bob</a> "} | ||
}); | ||
} | ||
|
||
@Test | ||
public void testStartMessage() { | ||
assertEquals(expectedResult, messageBuilder.toString()); | ||
} | ||
|
||
} |