*/\r
package com.gitblit.tests;\r
\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
import org.junit.Test;\r
\r
+import com.gitblit.IStoredSettings;\r
+import com.gitblit.Keys;\r
+import com.gitblit.tests.mock.MemorySettings;\r
import com.gitblit.utils.MarkdownUtils;\r
\r
public class MarkdownUtilsTest extends GitblitUnitTest {\r
assertEquals("<table><tr><td><test></td></tr></table>",\r
MarkdownUtils.transformMarkdown("<table><tr><td><test></td></tr></table>"));\r
}\r
-}
\ No newline at end of file
+\r
+\r
+ @Test\r
+ public void testUserMentions() {\r
+ IStoredSettings settings = getSettings();\r
+ String repositoryName = "test3";\r
+ String mentionHtml = "<strong><a href=\"http://localhost/user/%1$s\">@%1$s</a></strong>";\r
+\r
+ String input = "@j.doe";\r
+ String output = "<p>" + String.format(mentionHtml, "j.doe") + "</p>";\r
+ assertEquals(output, MarkdownUtils.transformGFM(settings, input, repositoryName));\r
+\r
+ input = " @j.doe";\r
+ output = "<p>" + String.format(mentionHtml, "j.doe") + "</p>";\r
+ assertEquals(output, MarkdownUtils.transformGFM(settings, input, repositoryName));\r
+\r
+ input = "@j.doe.";\r
+ output = "<p>" + String.format(mentionHtml, "j.doe") + ".</p>";\r
+ assertEquals(output, MarkdownUtils.transformGFM(settings, input, repositoryName));\r
+\r
+ input = "To @j.doe: ask @jim.beam!";\r
+ output = "<p>To " + String.format(mentionHtml, "j.doe")\r
+ + ": ask " + String.format(mentionHtml, "jim.beam") + "!</p>";\r
+ assertEquals(output, MarkdownUtils.transformGFM(settings, input, repositoryName));\r
+\r
+ input = "@sta.rt\n"\r
+ + "\n"\r
+ + "User mentions in tickets are broken.\n"\r
+ + "So:\n"\r
+ + "@mc_guyver can fix this.\n"\r
+ + "@j.doe, can you test after the fix by @m+guyver?\n"\r
+ + "Please review this, @jim.beam!\n"\r
+ + "Was reported by @jill and @j!doe from jane@doe yesterday.\n"\r
+ + "\n"\r
+ + "@jack.daniels can vote for john@wayne.name hopefully.\n"\r
+ + "@en.de";\r
+ output = "<p>" + String.format(mentionHtml, "sta.rt") + "</p>"\r
+ + "<p>" + "User mentions in tickets are broken.<br/>"\r
+ + "So:<br/>"\r
+ + String.format(mentionHtml, "mc_guyver") + " can fix this.<br/>"\r
+ + String.format(mentionHtml, "j.doe") + ", can you test after the fix by " + String.format(mentionHtml, "m+guyver") + "?<br/>"\r
+ + "Please review this, " + String.format(mentionHtml, "jim.beam") + "!<br/>"\r
+ + "Was reported by " + String.format(mentionHtml, "jill")\r
+ + " and " + String.format(mentionHtml, "j!doe")\r
+ + " from <a href=\"mailto:jane@doe\">jane@doe</a> yesterday." \r
+ + "</p>"\r
+ + "<p>" + String.format(mentionHtml, "jack.daniels") + " can vote for "\r
+ + "<a href=\"mailto:john@wayne.name\">john@wayne.name</a> hopefully.<br/>"\r
+ + String.format(mentionHtml, "en.de")\r
+ + "</p>";\r
+ assertEquals(output, MarkdownUtils.transformGFM(settings, input, repositoryName));\r
+\r
+ }\r
+\r
+\r
+\r
+\r
+ private MemorySettings getSettings() {\r
+ Map<String, Object> backingMap = new HashMap<String, Object>();\r
+\r
+ backingMap.put(Keys.web.canonicalUrl, "http://localhost");\r
+ backingMap.put(Keys.web.shortCommitIdLength, "7");\r
+\r
+ MemorySettings ms = new MemorySettings(backingMap);\r
+ return ms;\r
+ }\r
+}\r