-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
java.lang.NumberFormatException: When using parametrized scheduler (#510
) * ActiveNotifier MessageBuilder: handle { in messages outside links (#509) * ActiveNotifier MessageBuilder: add test coverage
- Loading branch information
Showing
2 changed files
with
77 additions
and
2 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
71 changes: 71 additions & 0 deletions
71
src/test/java/jenkins/plugins/slack/MessageBuilderEscapeTest.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,71 @@ | ||
package jenkins.plugins.slack; | ||
|
||
import hudson.model.AbstractBuild; | ||
import hudson.model.AbstractProject; | ||
import hudson.model.ItemGroup; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class MessageBuilderEscapeTest { | ||
|
||
private static ActiveNotifier.MessageBuilder messageBuilder; | ||
|
||
@BeforeClass | ||
public static void setupMessageBuilder() { | ||
AbstractBuild build = mock(AbstractBuild.class); | ||
AbstractProject project = mock(AbstractProject.class); | ||
AbstractProject job = mock(AbstractProject.class); | ||
ItemGroup group = mock(ItemGroup.class); | ||
SlackNotifier notifier = mock(SlackNotifier.class); | ||
|
||
when(build.getDisplayName()).thenReturn("build"); | ||
when(build.getProject()).thenReturn(project); | ||
when(build.getParent()).thenReturn(job); | ||
when(job.getParent()).thenReturn(group); | ||
when(group.getFullDisplayName()).thenReturn("group"); | ||
when(project.getParent()).thenReturn(group); | ||
|
||
when(job.getFullDisplayName()).thenReturn("job"); | ||
when(project.getFullDisplayName()).thenReturn("project"); | ||
|
||
messageBuilder = new ActiveNotifier.MessageBuilder(notifier, build); | ||
} | ||
|
||
@Test | ||
public void testEscapeAnchor() throws IOException { | ||
String input = "<a href='target'>test</a>"; | ||
String expected = "<'target'|test>"; | ||
String escaped = messageBuilder.escape(input); | ||
assertEquals(expected, escaped); | ||
} | ||
|
||
@Test | ||
public void testEscapePercent() throws IOException { | ||
String input = "hello % world"; | ||
String expected = "hello % world"; | ||
String escaped = messageBuilder.escape(input); | ||
assertEquals(expected, escaped); | ||
} | ||
|
||
@Test | ||
public void testEscapeBraces() throws IOException { | ||
String input = "something { is } odd"; | ||
String expected = "something { is } odd"; | ||
String escaped = messageBuilder.escape(input); | ||
assertEquals(expected, escaped); | ||
} | ||
|
||
@Test | ||
public void testEscapeBracesInLink() throws IOException { | ||
String input = "<a href='target'>test { case }</a>"; | ||
String expected = "<'target'|test { case }>"; | ||
String escaped = messageBuilder.escape(input); | ||
assertEquals(expected, escaped); | ||
} | ||
} |