* @author Alan Harder
*/
public class UrlAnnotatorTest extends TestCase {
public void testAnnotate() {
ConsoleAnnotator ca = new UrlAnnotator().newInstance(null);
MarkupText text = new MarkupText("Hello <foo>http://foo/</foo> Bye");
ca.annotate(null, text);
assertEquals("Hello <foo><a href='http://foo/'>http://foo/</a></foo> Bye",
text.toString(true));
text = new MarkupText("Hello [foo]http://foo/bar.txt[/foo] Bye");
ca.annotate(null, text);
assertEquals("Hello [foo]<a href='http://foo/bar.txt'>http://foo/bar.txt</a>[/foo] Bye",
text.toString(true));
text = new MarkupText(
"Hello 'http://foo' or \"ftp://bar\" or <https://baz/> or (http://a.b.c/x.y) Bye");
ca.annotate(null, text);
assertEquals("Hello '<a href='http://foo'>http://foo</a>' or \"<a href='ftp://bar'>"
+ "ftp://bar</a>\" or <<a href='https://baz/'>https://baz/</a>> or (<a "
+ "href='http://a.b.c/x.y'>http://a.b.c/x.y</a>) Bye",
text.toString(true));
text = new MarkupText("Fake 'http://foo or \"ftp://bar or <https://baz/ or (http://a.b.c/x.y Bye");
ca.annotate(null, text);
assertEquals("Fake '<a href='http://foo'>http://foo</a> or \"<a href='ftp://bar'>"
+ "ftp://bar</a> or <<a href='https://baz/'>https://baz/</a> or (<a "
+ "href='http://a.b.c/x.y'>http://a.b.c/x.y</a> Bye",
text.toString(true));
text = new MarkupText("Punctuation: http://foo/.");
ca.annotate(null, text);
assertEquals("Punctuation: <a href='http://foo/'>http://foo/</a>.", text.toString(true));
}