Skip to content

Commit 3de910b

Browse files
committed
Adding SlackLinkUtils and few other methods
1 parent 35dbc6a commit 3de910b

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package in.ashwanthkumar.slack.webhook;
2+
3+
public class SlackLinkUtils {
4+
public static String email(String email, String user) {
5+
return String.format("<mailto:%s|%s>", email, user);
6+
}
7+
8+
public static String email(String email) {
9+
return String.format("<mailto:%s>", email);
10+
}
11+
12+
public static String link(String href, String name) {
13+
return String.format("<%s|%s>", href, name);
14+
}
15+
16+
public static String link(String href) {
17+
return String.format("<%s>", href);
18+
}
19+
20+
public static String user(String handle, String name) {
21+
return String.format("<@%s|%s>", handle, name);
22+
}
23+
24+
public static String user(String handle) {
25+
return String.format("<@%s>", handle);
26+
}
27+
28+
public static String channel(String channel) {
29+
return String.format("<#%s>", channel);
30+
}
31+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package in.ashwanthkumar.slack.webhook;
2+
3+
import org.junit.Test;
4+
5+
import static in.ashwanthkumar.slack.webhook.SlackLinkUtils.*;
6+
import static org.hamcrest.CoreMatchers.is;
7+
import static org.junit.Assert.assertThat;
8+
9+
public class SlackLinkUtilsTest {
10+
@Test
11+
public void shouldGenerateEmailInLinkableFormat() {
12+
assertThat(email("foo-bar@ashwanthkumar.in", "Ashwanth"), is("<mailto:foo-bar@ashwanthkumar.in|Ashwanth>"));
13+
assertThat(email("foo-bar@ashwanthkumar.in"), is("<mailto:foo-bar@ashwanthkumar.in>"));
14+
}
15+
16+
@Test
17+
public void shouldGenrateHrefsInLinkFormat() {
18+
assertThat(link("www.foo.com", "Foo"), is("<www.foo.com|Foo>"));
19+
assertThat(link("www.foo.com"), is("<www.foo.com>"));
20+
}
21+
22+
@Test
23+
public void shouldGenerateUserHandlesInLinkableFormat() {
24+
assertThat(user("ashwanthkumar", "Ash"), is("<@ashwanthkumar|Ash>"));
25+
assertThat(user("ashwanthkumar"), is("<@ashwanthkumar>"));
26+
}
27+
28+
@Test
29+
public void shouldGenerateChannelsInLinkableFormat() {
30+
assertThat(channel("general"), is("<#general>"));
31+
}
32+
33+
34+
}

0 commit comments

Comments
 (0)