Skip to content

Commit

Permalink
Not adding colon if the imageOrIcon starts with http
Browse files Browse the repository at this point in the history
Fixing regression issue due to #4
  • Loading branch information
ashwanthkumar committed Nov 25, 2017
1 parent 7b3a64b commit 9acab0b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/in/ashwanthkumar/slack/webhook/Slack.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import in.ashwanthkumar.slack.webhook.service.SlackService;
import in.ashwanthkumar.utils.collections.Lists;
import in.ashwanthkumar.utils.lang.StringUtils;

import java.io.IOException;
import java.net.InetSocketAddress;
Expand Down Expand Up @@ -82,7 +83,7 @@ public Slack displayName(String user) {
* @param imageOrIcon Icon Image URL or emoji code from http://www.emoji-cheat-sheet.com/
*/
public Slack icon(String imageOrIcon) {
if (imageOrIcon != null && !imageOrIcon.isEmpty()) {
if (StringUtils.isNotEmpty(imageOrIcon) && !StringUtils.startsWith(imageOrIcon, "http")) {
if (!imageOrIcon.startsWith(":")) {
imageOrIcon = ":" + imageOrIcon;
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/in/ashwanthkumar/slack/webhook/SlackTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,15 @@ public void shouldNotAddColonToIconNameIfAlreadyExists() throws IOException {
assertThat(iconCaptor.getValue(), is(":ghost:"));
}

@Test
public void shouldNotAddColonToIconNameOrImageIfUrl() throws IOException {
Slack slack = new Slack("mockUrl", slackService);
slack.icon("http://github.com/i/am/sorry.png");
ArgumentCaptor<String> iconCaptor = ArgumentCaptor.forClass(String.class);
SlackMessage message = new SlackMessage("hello");
doNothing().when(slackService).push(anyString(), eq(message), anyString(), iconCaptor.capture(), anyString(), anyString());
slack.sendToChannel("test-channel").push(message);
assertThat(iconCaptor.getValue(), is("http://github.com/i/am/sorry.png"));
}

}

0 comments on commit 9acab0b

Please sign in to comment.