File tree Expand file tree Collapse file tree
main/java/in/ashwanthkumar/slack/webhook
test/java/in/ashwanthkumar/slack/webhook Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments