1515 */
1616package com .gitblit .tests ;
1717
18+ import java .util .HashMap ;
19+ import java .util .Map ;
20+
1821import org .junit .Test ;
1922
23+ import com .gitblit .IStoredSettings ;
24+ import com .gitblit .Keys ;
25+ import com .gitblit .tests .mock .MemorySettings ;
2026import com .gitblit .utils .MarkdownUtils ;
2127
2228public class MarkdownUtilsTest extends GitblitUnitTest {
@@ -39,4 +45,70 @@ public void testMarkdown() throws Exception {
3945 assertEquals ("<table><tr><td><test></td></tr></table>" ,
4046 MarkdownUtils .transformMarkdown ("<table><tr><td><test></td></tr></table>" ));
4147 }
42- }
48+
49+
50+ @ Test
51+ public void testUserMentions () {
52+ IStoredSettings settings = getSettings ();
53+ String repositoryName = "test3" ;
54+ String mentionHtml = "<strong><a href=\" http://localhost/user/%1$s\" >@%1$s</a></strong>" ;
55+
56+ String input = "@j.doe" ;
57+ String output = "<p>" + String .format (mentionHtml , "j.doe" ) + "</p>" ;
58+ assertEquals (output , MarkdownUtils .transformGFM (settings , input , repositoryName ));
59+
60+ input = " @j.doe" ;
61+ output = "<p>" + String .format (mentionHtml , "j.doe" ) + "</p>" ;
62+ assertEquals (output , MarkdownUtils .transformGFM (settings , input , repositoryName ));
63+
64+ input = "@j.doe." ;
65+ output = "<p>" + String .format (mentionHtml , "j.doe" ) + ".</p>" ;
66+ assertEquals (output , MarkdownUtils .transformGFM (settings , input , repositoryName ));
67+
68+ input = "To @j.doe: ask @jim.beam!" ;
69+ output = "<p>To " + String .format (mentionHtml , "j.doe" )
70+ + ": ask " + String .format (mentionHtml , "jim.beam" ) + "!</p>" ;
71+ assertEquals (output , MarkdownUtils .transformGFM (settings , input , repositoryName ));
72+
73+ input = "@sta.rt\n "
74+ + "\n "
75+ + "User mentions in tickets are broken.\n "
76+ + "So:\n "
77+ + "@mc_guyver can fix this.\n "
78+ + "@j.doe, can you test after the fix by @m+guyver?\n "
79+ + "Please review this, @jim.beam!\n "
80+ + "Was reported by @jill and @j!doe from jane@doe yesterday.\n "
81+ + "\n "
82+ +
"@jack.daniels can vote for [email protected] hopefully.\n " 83+ + "@en.de" ;
84+ output = "<p>" + String .format (mentionHtml , "sta.rt" ) + "</p>"
85+ + "<p>" + "User mentions in tickets are broken.<br/>"
86+ + "So:<br/>"
87+ + String .format (mentionHtml , "mc_guyver" ) + " can fix this.<br/>"
88+ + String .format (mentionHtml , "j.doe" ) + ", can you test after the fix by " + String .format (mentionHtml , "m+guyver" ) + "?<br/>"
89+ + "Please review this, " + String .format (mentionHtml , "jim.beam" ) + "!<br/>"
90+ + "Was reported by " + String .format (mentionHtml , "jill" )
91+ + " and " + String .format (mentionHtml , "j!doe" )
92+ + " from <a href=\" mailto:jane@doe\" >jane@doe</a> yesterday."
93+ + "</p>"
94+ + "<p>" + String .format (mentionHtml , "jack.daniels" ) + " can vote for "
95+ + "<a href=\" mailto:john@wayne.name\" >john@wayne.name</a> hopefully.<br/>"
96+ + String .format (mentionHtml , "en.de" )
97+ + "</p>" ;
98+ assertEquals (output , MarkdownUtils .transformGFM (settings , input , repositoryName ));
99+
100+ }
101+
102+
103+
104+
105+ private MemorySettings getSettings () {
106+ Map <String , Object > backingMap = new HashMap <String , Object >();
107+
108+ backingMap .put (Keys .web .canonicalUrl , "http://localhost" );
109+ backingMap .put (Keys .web .shortCommitIdLength , "7" );
110+
111+ MemorySettings ms = new MemorySettings (backingMap );
112+ return ms ;
113+ }
114+ }
0 commit comments