gerrit-gwtexpui: Convert tests to use Google Truth

Change-Id: I7a8bf41df3b9118a7c21cdbf89925ffe76119019
This commit is contained in:
David Pursehouse
2015-06-03 17:57:44 +09:00
parent 56ef7a8902
commit cd4c01dadc
10 changed files with 315 additions and 315 deletions

View File

@@ -73,7 +73,7 @@ java_test(
]), ]),
deps = [ deps = [
':SafeHtml', ':SafeHtml',
'//lib:junit', '//lib:truth',
'//lib/gwt:user', '//lib/gwt:user',
'//lib/gwt:dev', '//lib/gwt:dev',
], ],

View File

@@ -14,10 +14,8 @@
package com.google.gwtexpui.safehtml.client; package com.google.gwtexpui.safehtml.client;
import static com.google.common.truth.Truth.assertThat;
import static com.google.gwtexpui.safehtml.client.LinkFindReplace.hasValidScheme; import static com.google.gwtexpui.safehtml.client.LinkFindReplace.hasValidScheme;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@@ -32,29 +30,30 @@ public class LinkFindReplaceTest {
String find = "find"; String find = "find";
String link = "link"; String link = "link";
LinkFindReplace a = new LinkFindReplace(find, link); LinkFindReplace a = new LinkFindReplace(find, link);
assertEquals(find, a.pattern().getSource()); assertThat(a.pattern().getSource()).isEqualTo(find);
assertEquals("<a href=\"link\">find</a>", a.replace(find)); assertThat(a.replace(find)).isEqualTo("<a href=\"link\">find</a>");
assertEquals("find = " + find + ", link = " + link, a.toString()); assertThat(a.toString()).isEqualTo("find = " + find + ", link = " + link);
} }
@Test @Test
public void testBackreference() { public void testBackreference() {
assertEquals("<a href=\"/bug?id=123\">issue 123</a>", LinkFindReplace l = new LinkFindReplace(
new LinkFindReplace("(bug|issue)\\s*([0-9]+)", "/bug?id=$2") "(bug|issue)\\s*([0-9]+)", "/bug?id=$2");
.replace("issue 123")); assertThat(l.replace("issue 123"))
.isEqualTo("<a href=\"/bug?id=123\">issue 123</a>");
} }
@Test @Test
public void testHasValidScheme() { public void testHasValidScheme() {
assertTrue(hasValidScheme("/absolute/path")); assertThat(hasValidScheme("/absolute/path")).isTrue();
assertTrue(hasValidScheme("relative/path")); assertThat(hasValidScheme("relative/path")).isTrue();
assertTrue(hasValidScheme("http://url/")); assertThat(hasValidScheme("http://url/")).isTrue();
assertTrue(hasValidScheme("HTTP://url/")); assertThat(hasValidScheme("HTTP://url/")).isTrue();
assertTrue(hasValidScheme("https://url/")); assertThat(hasValidScheme("https://url/")).isTrue();
assertTrue(hasValidScheme("mailto://url/")); assertThat(hasValidScheme("mailto://url/")).isTrue();
assertFalse(hasValidScheme("ftp://url/")); assertThat(hasValidScheme("ftp://url/")).isFalse();
assertFalse(hasValidScheme("data:evil")); assertThat(hasValidScheme("data:evil")).isFalse();
assertFalse(hasValidScheme("javascript:alert(1)")); assertThat(hasValidScheme("javascript:alert(1)")).isFalse();
} }
@Test @Test
@@ -72,15 +71,16 @@ public class LinkFindReplaceTest {
@Test @Test
public void testReplaceEscaping() { public void testReplaceEscaping() {
assertEquals("<a href=\"a&quot;&amp;&#39;&lt;&gt;b\">find</a>", assertThat(new LinkFindReplace("find", "a\"&'<>b").replace("find"))
new LinkFindReplace("find", "a\"&'<>b").replace("find")); .isEqualTo("<a href=\"a&quot;&amp;&#39;&lt;&gt;b\">find</a>");
} }
@Test @Test
public void testHtmlInFind() { public void testHtmlInFind() {
String rawFind = "<b>&quot;bold&quot;</b>"; String rawFind = "<b>&quot;bold&quot;</b>";
LinkFindReplace a = new LinkFindReplace(rawFind, "/bold"); LinkFindReplace a = new LinkFindReplace(rawFind, "/bold");
assertEquals(rawFind, a.pattern().getSource()); assertThat(a.pattern().getSource()).isEqualTo(rawFind);
assertEquals("<a href=\"/bold\">" + rawFind + "</a>", a.replace(rawFind)); assertThat(a.replace(rawFind))
.isEqualTo("<a href=\"/bold\">" + rawFind + "</a>");
} }
} }

View File

@@ -14,7 +14,7 @@
package com.google.gwtexpui.safehtml.client; package com.google.gwtexpui.safehtml.client;
import static org.junit.Assert.assertEquals; import static com.google.common.truth.Truth.assertThat;
import org.junit.Test; import org.junit.Test;
@@ -24,8 +24,8 @@ public class RawFindReplaceTest {
final String find = "find"; final String find = "find";
final String replace = "replace"; final String replace = "replace";
final RawFindReplace a = new RawFindReplace(find, replace); final RawFindReplace a = new RawFindReplace(find, replace);
assertEquals(find, a.pattern().getSource()); assertThat(a.pattern().getSource()).isEqualTo(find);
assertEquals(replace, a.replace(find)); assertThat(a.replace(find)).isEqualTo(replace);
assertEquals("find = " + find + ", replace = " + replace, a.toString()); assertThat(a.toString()).isEqualTo("find = " + find + ", replace = " + replace);
} }
} }

View File

@@ -14,12 +14,7 @@
package com.google.gwtexpui.safehtml.client; package com.google.gwtexpui.safehtml.client;
import static org.junit.Assert.assertEquals; import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@@ -32,13 +27,13 @@ public class SafeHtmlBuilderTest {
@Test @Test
public void testEmpty() { public void testEmpty() {
final SafeHtmlBuilder b = new SafeHtmlBuilder(); final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertTrue(b.isEmpty()); assertThat(b.isEmpty()).isTrue();
assertFalse(b.hasContent()); assertThat(b.hasContent()).isFalse();
assertEquals("", b.asString()); assertThat(b.asString()).isEmpty();
b.append("a"); b.append("a");
assertTrue(b.hasContent()); assertThat(b.hasContent()).isTrue();
assertEquals("a", b.asString()); assertThat(b.asString()).isEqualTo("a");
} }
@Test @Test
@@ -47,216 +42,216 @@ public class SafeHtmlBuilderTest {
b.append(1); b.append(1);
final SafeHtml h = b.toSafeHtml(); final SafeHtml h = b.toSafeHtml();
assertNotNull(h); assertThat(h).isNotNull();
assertNotSame(h, b); assertThat(h).isNotSameAs(b);
assertFalse(h instanceof SafeHtmlBuilder); assertThat(h).isNotInstanceOf(SafeHtmlBuilder.class);
assertEquals("1", h.asString()); assertThat(h.asString()).isEqualTo("1");
} }
@Test @Test
public void testAppend_boolean() { public void testAppend_boolean() {
final SafeHtmlBuilder b = new SafeHtmlBuilder(); final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append(true)); assertThat(b).isSameAs(b.append(true));
assertSame(b, b.append(false)); assertThat(b).isSameAs(b.append(false));
assertEquals("truefalse", b.asString()); assertThat(b.asString()).isEqualTo("truefalse");
} }
@Test @Test
public void testAppend_char() { public void testAppend_char() {
final SafeHtmlBuilder b = new SafeHtmlBuilder(); final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append('a')); assertThat(b).isSameAs(b.append('a'));
assertSame(b, b.append('b')); assertThat(b).isSameAs(b.append('b'));
assertEquals("ab", b.asString()); assertThat("ab");
} }
@Test @Test
public void testAppend_int() { public void testAppend_int() {
final SafeHtmlBuilder b = new SafeHtmlBuilder(); final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append(4)); assertThat(b).isSameAs(b.append(4));
assertSame(b, b.append(2)); assertThat(b).isSameAs(b.append(2));
assertSame(b, b.append(-100)); assertThat(b).isSameAs(b.append(-100));
assertEquals("42-100", b.asString()); assertThat(b.asString()).isEqualTo("42-100");
} }
@Test @Test
public void testAppend_long() { public void testAppend_long() {
final SafeHtmlBuilder b = new SafeHtmlBuilder(); final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append(4L)); assertThat(b).isSameAs(b.append(4L));
assertSame(b, b.append(2L)); assertThat(b).isSameAs(b.append(2L));
assertEquals("42", b.asString()); assertThat(b.asString()).isEqualTo("42");
} }
@Test @Test
public void testAppend_float() { public void testAppend_float() {
final SafeHtmlBuilder b = new SafeHtmlBuilder(); final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append(0.0f)); assertThat(b).isSameAs(b.append(0.0f));
assertEquals("0.0", b.asString()); assertThat(b.asString()).isEqualTo("0.0");
} }
@Test @Test
public void testAppend_double() { public void testAppend_double() {
final SafeHtmlBuilder b = new SafeHtmlBuilder(); final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append(0.0)); assertThat(b).isSameAs(b.append(0.0));
assertEquals("0.0", b.asString()); assertThat(b.asString()).isEqualTo("0.0");
} }
@Test @Test
public void testAppend_String() { public void testAppend_String() {
final SafeHtmlBuilder b = new SafeHtmlBuilder(); final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append((String) null)); assertThat(b).isSameAs(b.append((String) null));
assertEquals("", b.asString()); assertThat(b.asString()).isEmpty();
assertSame(b, b.append("foo")); assertThat(b).isSameAs(b.append("foo"));
assertSame(b, b.append("bar")); assertThat(b).isSameAs(b.append("bar"));
assertEquals("foobar", b.asString()); assertThat(b.asString()).isEqualTo("foobar");
} }
@Test @Test
public void testAppend_StringBuilder() { public void testAppend_StringBuilder() {
final SafeHtmlBuilder b = new SafeHtmlBuilder(); final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append((StringBuilder) null)); assertThat(b).isSameAs(b.append((StringBuilder) null));
assertEquals("", b.asString()); assertThat(b.asString()).isEmpty();
assertSame(b, b.append(new StringBuilder("foo"))); assertThat(b).isSameAs(b.append(new StringBuilder("foo")));
assertSame(b, b.append(new StringBuilder("bar"))); assertThat(b).isSameAs(b.append(new StringBuilder("bar")));
assertEquals("foobar", b.asString()); assertThat(b.asString()).isEqualTo("foobar");
} }
@Test @Test
public void testAppend_StringBuffer() { public void testAppend_StringBuffer() {
final SafeHtmlBuilder b = new SafeHtmlBuilder(); final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append((StringBuffer) null)); assertThat(b).isSameAs(b.append((StringBuffer) null));
assertEquals("", b.asString()); assertThat(b.asString()).isEmpty();
assertSame(b, b.append(new StringBuffer("foo"))); assertThat(b).isSameAs(b.append(new StringBuffer("foo")));
assertSame(b, b.append(new StringBuffer("bar"))); assertThat(b).isSameAs(b.append(new StringBuffer("bar")));
assertEquals("foobar", b.asString()); assertThat(b.asString()).isEqualTo("foobar");
} }
@Test @Test
public void testAppend_Object() { public void testAppend_Object() {
final SafeHtmlBuilder b = new SafeHtmlBuilder(); final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append((Object) null)); assertThat(b).isSameAs(b.append((Object) null));
assertEquals("", b.asString()); assertThat(b.asString()).isEmpty();
assertSame(b, b.append(new Object() { assertThat(b).isSameAs(b.append(new Object() {
@Override @Override
public String toString() { public String toString() {
return "foobar"; return "foobar";
} }
})); }));
assertEquals("foobar", b.asString()); assertThat(b.asString()).isEqualTo("foobar");
} }
@Test @Test
public void testAppend_CharSequence() { public void testAppend_CharSequence() {
final SafeHtmlBuilder b = new SafeHtmlBuilder(); final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append((CharSequence) null)); assertThat(b).isSameAs(b.append((CharSequence) null));
assertEquals("", b.asString()); assertThat(b.asString()).isEmpty();
assertSame(b, b.append((CharSequence) "foo")); assertThat(b).isSameAs(b.append((CharSequence) "foo"));
assertSame(b, b.append((CharSequence) "bar")); assertThat(b).isSameAs(b.append((CharSequence) "bar"));
assertEquals("foobar", b.asString()); assertThat(b.asString()).isEqualTo("foobar");
} }
@Test @Test
public void testAppend_SafeHtml() { public void testAppend_SafeHtml() {
final SafeHtmlBuilder b = new SafeHtmlBuilder(); final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.append((SafeHtml) null)); assertThat(b).isSameAs(b.append((SafeHtml) null));
assertEquals("", b.asString()); assertThat(b.asString()).isEmpty();
assertSame(b, b.append(new SafeHtmlString("foo"))); assertThat(b).isSameAs(b.append(new SafeHtmlString("foo")));
assertSame(b, b.append(new SafeHtmlBuilder().append("bar"))); assertThat(b).isSameAs(b.append(new SafeHtmlBuilder().append("bar")));
assertEquals("foobar", b.asString()); assertThat(b.asString()).isEqualTo("foobar");
} }
@Test @Test
public void testHtmlSpecialCharacters() { public void testHtmlSpecialCharacters() {
assertEquals("&amp;", escape("&")); assertThat(escape("&")).isEqualTo("&amp;");
assertEquals("&lt;", escape("<")); assertThat(escape("<")).isEqualTo("&lt;");
assertEquals("&gt;", escape(">")); assertThat(escape(">")).isEqualTo("&gt;");
assertEquals("&quot;", escape("\"")); assertThat(escape("\"")).isEqualTo("&quot;");
assertEquals("&#39;", escape("'")); assertThat(escape("'")).isEqualTo("&#39;");
assertEquals("&amp;", escape('&')); assertThat(escape('&')).isEqualTo("&amp;");
assertEquals("&lt;", escape('<')); assertThat(escape('<')).isEqualTo("&lt;");
assertEquals("&gt;", escape('>')); assertThat(escape('>')).isEqualTo("&gt;");
assertEquals("&quot;", escape('"')); assertThat(escape('"')).isEqualTo("&quot;");
assertEquals("&#39;", escape('\'')); assertThat(escape('\'')).isEqualTo("&#39;");
assertEquals("&lt;b&gt;", escape("<b>")); assertThat(escape("<b>")).isEqualTo("&lt;b&gt;");
assertEquals("&amp;lt;b&amp;gt;", escape("&lt;b&gt;")); assertThat(escape("&lt;b&gt;")).isEqualTo("&amp;lt;b&amp;gt;");
} }
@Test @Test
public void testEntityNbsp() { public void testEntityNbsp() {
final SafeHtmlBuilder b = new SafeHtmlBuilder(); final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.nbsp()); assertThat(b).isSameAs(b.nbsp());
assertEquals("&nbsp;", b.asString()); assertThat(b.asString()).isEqualTo("&nbsp;");
} }
@Test @Test
public void testTagBr() { public void testTagBr() {
final SafeHtmlBuilder b = new SafeHtmlBuilder(); final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.br()); assertThat(b).isSameAs(b.br());
assertEquals("<br />", b.asString()); assertThat(b.asString()).isEqualTo("<br />");
} }
@Test @Test
public void testTagTableTrTd() { public void testTagTableTrTd() {
final SafeHtmlBuilder b = new SafeHtmlBuilder(); final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.openElement("table")); assertThat(b).isSameAs(b.openElement("table"));
assertSame(b, b.openTr()); assertThat(b).isSameAs(b.openTr());
assertSame(b, b.openTd()); assertThat(b).isSameAs(b.openTd());
assertSame(b, b.append("d<a>ta")); assertThat(b).isSameAs(b.append("d<a>ta"));
assertSame(b, b.closeTd()); assertThat(b).isSameAs(b.closeTd());
assertSame(b, b.closeTr()); assertThat(b).isSameAs(b.closeTr());
assertSame(b, b.closeElement("table")); assertThat(b).isSameAs(b.closeElement("table"));
assertEquals("<table><tr><td>d&lt;a&gt;ta</td></tr></table>", b.asString()); assertThat(b.asString()).isEqualTo("<table><tr><td>d&lt;a&gt;ta</td></tr></table>");
} }
@Test @Test
public void testTagDiv() { public void testTagDiv() {
final SafeHtmlBuilder b = new SafeHtmlBuilder(); final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.openDiv()); assertThat(b).isSameAs(b.openDiv());
assertSame(b, b.append("d<a>ta")); assertThat(b).isSameAs(b.append("d<a>ta"));
assertSame(b, b.closeDiv()); assertThat(b).isSameAs(b.closeDiv());
assertEquals("<div>d&lt;a&gt;ta</div>", b.asString()); assertThat(b.asString()).isEqualTo("<div>d&lt;a&gt;ta</div>");
} }
@Test @Test
public void testTagAnchor() { public void testTagAnchor() {
final SafeHtmlBuilder b = new SafeHtmlBuilder(); final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.openAnchor()); assertThat(b).isSameAs(b.openAnchor());
assertEquals("", b.getAttribute("href")); assertThat(b.getAttribute("href")).isEmpty();
assertSame(b, b.setAttribute("href", "http://here")); assertThat(b).isSameAs(b.setAttribute("href", "http://here"));
assertEquals("http://here", b.getAttribute("href")); assertThat(b.getAttribute("href")).isEqualTo("http://here");
assertSame(b, b.setAttribute("href", "d<a>ta")); assertThat(b).isSameAs(b.setAttribute("href", "d<a>ta"));
assertEquals("d<a>ta", b.getAttribute("href")); assertThat(b.getAttribute("href")).isEqualTo("d<a>ta");
assertEquals("", b.getAttribute("target")); assertThat(b.getAttribute("target")).isEmpty();
assertSame(b, b.setAttribute("target", null)); assertThat(b).isSameAs(b.setAttribute("target", null));
assertEquals("", b.getAttribute("target")); assertThat(b.getAttribute("target")).isEmpty();
assertSame(b, b.append("go")); assertThat(b).isSameAs(b.append("go"));
assertSame(b, b.closeAnchor()); assertThat(b).isSameAs(b.closeAnchor());
assertEquals("<a href=\"d&lt;a&gt;ta\">go</a>", b.asString()); assertThat(b.asString()).isEqualTo("<a href=\"d&lt;a&gt;ta\">go</a>");
} }
@Test @Test
public void testTagHeightWidth() { public void testTagHeightWidth() {
final SafeHtmlBuilder b = new SafeHtmlBuilder(); final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.openElement("img")); assertThat(b).isSameAs(b.openElement("img"));
assertSame(b, b.setHeight(100)); assertThat(b).isSameAs(b.setHeight(100));
assertSame(b, b.setWidth(42)); assertThat(b).isSameAs(b.setWidth(42));
assertSame(b, b.closeSelf()); assertThat(b).isSameAs(b.closeSelf());
assertEquals("<img height=\"100\" width=\"42\" />", b.asString()); assertThat(b.asString()).isEqualTo("<img height=\"100\" width=\"42\" />");
} }
@Test @Test
public void testStyleName() { public void testStyleName() {
final SafeHtmlBuilder b = new SafeHtmlBuilder(); final SafeHtmlBuilder b = new SafeHtmlBuilder();
assertSame(b, b.openSpan()); assertThat(b).isSameAs(b.openSpan());
assertSame(b, b.setStyleName("foo")); assertThat(b).isSameAs(b.setStyleName("foo"));
assertSame(b, b.addStyleName("bar")); assertThat(b).isSameAs(b.addStyleName("bar"));
assertSame(b, b.append("d<a>ta")); assertThat(b).isSameAs(b.append("d<a>ta"));
assertSame(b, b.closeSpan()); assertThat(b).isSameAs(b.closeSpan());
assertEquals("<span class=\"foo bar\">d&lt;a&gt;ta</span>", b.asString()); assertThat(b.asString()).isEqualTo("<span class=\"foo bar\">d&lt;a&gt;ta</span>");
} }
@Test @Test

View File

@@ -14,8 +14,7 @@
package com.google.gwtexpui.safehtml.client; package com.google.gwtexpui.safehtml.client;
import static org.junit.Assert.assertEquals; import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertNotSame;
import org.junit.Test; import org.junit.Test;
@@ -24,72 +23,81 @@ public class SafeHtml_LinkifyTest {
public void testLinkify_SimpleHttp1() { public void testLinkify_SimpleHttp1() {
final SafeHtml o = html("A http://go.here/ B"); final SafeHtml o = html("A http://go.here/ B");
final SafeHtml n = o.linkify(); final SafeHtml n = o.linkify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("A <a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a> B", n.asString()); assertThat(n.asString()).isEqualTo(
"A <a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a> B");
} }
@Test @Test
public void testLinkify_SimpleHttps2() { public void testLinkify_SimpleHttps2() {
final SafeHtml o = html("A https://go.here/ B"); final SafeHtml o = html("A https://go.here/ B");
final SafeHtml n = o.linkify(); final SafeHtml n = o.linkify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("A <a href=\"https://go.here/\" target=\"_blank\">https://go.here/</a> B", n.asString()); assertThat(n.asString()).isEqualTo(
"A <a href=\"https://go.here/\" target=\"_blank\">https://go.here/</a> B");
} }
@Test @Test
public void testLinkify_Parens1() { public void testLinkify_Parens1() {
final SafeHtml o = html("A (http://go.here/) B"); final SafeHtml o = html("A (http://go.here/) B");
final SafeHtml n = o.linkify(); final SafeHtml n = o.linkify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("A (<a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>) B", n.asString()); assertThat(n.asString()).isEqualTo(
"A (<a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>) B");
} }
@Test @Test
public void testLinkify_Parens() { public void testLinkify_Parens() {
final SafeHtml o = html("A http://go.here/#m() B"); final SafeHtml o = html("A http://go.here/#m() B");
final SafeHtml n = o.linkify(); final SafeHtml n = o.linkify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("A <a href=\"http://go.here/#m()\" target=\"_blank\">http://go.here/#m()</a> B", n.asString()); assertThat(n.asString()).isEqualTo(
"A <a href=\"http://go.here/#m()\" target=\"_blank\">http://go.here/#m()</a> B");
} }
@Test @Test
public void testLinkify_AngleBrackets1() { public void testLinkify_AngleBrackets1() {
final SafeHtml o = html("A <http://go.here/> B"); final SafeHtml o = html("A <http://go.here/> B");
final SafeHtml n = o.linkify(); final SafeHtml n = o.linkify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("A &lt;<a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>&gt; B", n.asString()); assertThat(n.asString()).isEqualTo(
"A &lt;<a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>&gt; B");
} }
@Test @Test
public void testLinkify_TrailingPlainLetter() { public void testLinkify_TrailingPlainLetter() {
final SafeHtml o = html("A http://go.here/foo B"); final SafeHtml o = html("A http://go.here/foo B");
final SafeHtml n = o.linkify(); final SafeHtml n = o.linkify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("A <a href=\"http://go.here/foo\" target=\"_blank\">http://go.here/foo</a> B", n.asString()); assertThat(n.asString()).isEqualTo(
"A <a href=\"http://go.here/foo\" target=\"_blank\">http://go.here/foo</a> B");
} }
@Test @Test
public void testLinkify_TrailingDot() { public void testLinkify_TrailingDot() {
final SafeHtml o = html("A http://go.here/. B"); final SafeHtml o = html("A http://go.here/. B");
final SafeHtml n = o.linkify(); final SafeHtml n = o.linkify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("A <a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>. B", n.asString()); assertThat(n.asString()).isEqualTo(
"A <a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>. B");
} }
@Test @Test
public void testLinkify_TrailingComma() { public void testLinkify_TrailingComma() {
final SafeHtml o = html("A http://go.here/, B"); final SafeHtml o = html("A http://go.here/, B");
final SafeHtml n = o.linkify(); final SafeHtml n = o.linkify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("A <a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>, B", n.asString()); assertThat(n.asString()).isEqualTo(
"A <a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>, B");
} }
@Test @Test
public void testLinkify_TrailingDotDot() { public void testLinkify_TrailingDotDot() {
final SafeHtml o = html("A http://go.here/.. B"); final SafeHtml o = html("A http://go.here/.. B");
final SafeHtml n = o.linkify(); final SafeHtml n = o.linkify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("A <a href=\"http://go.here/.\" target=\"_blank\">http://go.here/.</a>. B", n.asString()); assertThat(n.asString()).isEqualTo(
"A <a href=\"http://go.here/.\" target=\"_blank\">http://go.here/.</a>. B");
} }
private static SafeHtml html(String text) { private static SafeHtml html(String text) {

View File

@@ -14,9 +14,7 @@
package com.google.gwtexpui.safehtml.client; package com.google.gwtexpui.safehtml.client;
import static org.junit.Assert.assertEquals; import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import org.junit.Test; import org.junit.Test;
@@ -28,8 +26,8 @@ public class SafeHtml_ReplaceTest {
@Test @Test
public void testReplaceEmpty() { public void testReplaceEmpty() {
SafeHtml o = html("A\nissue42\nB"); SafeHtml o = html("A\nissue42\nB");
assertSame(o, o.replaceAll(null)); assertThat(o.replaceAll(null)).isSameAs(o);
assertSame(o, o.replaceAll(Collections.<FindReplace> emptyList())); assertThat(o.replaceAll(Collections.<FindReplace> emptyList())).isSameAs(o);
} }
@Test @Test
@@ -37,8 +35,9 @@ public class SafeHtml_ReplaceTest {
SafeHtml o = html("A\nissue 42\nB"); SafeHtml o = html("A\nissue 42\nB");
SafeHtml n = o.replaceAll(repls( SafeHtml n = o.replaceAll(repls(
new RawFindReplace("(issue\\s(\\d+))", "<a href=\"?$2\">$1</a>"))); new RawFindReplace("(issue\\s(\\d+))", "<a href=\"?$2\">$1</a>")));
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("A\n<a href=\"?42\">issue 42</a>\nB", n.asString()); assertThat(n.asString()).isEqualTo(
"A\n<a href=\"?42\">issue 42</a>\nB");
} }
@Test @Test
@@ -46,8 +45,9 @@ public class SafeHtml_ReplaceTest {
SafeHtml o = html("issue 42"); SafeHtml o = html("issue 42");
SafeHtml n = o.replaceAll(repls( SafeHtml n = o.replaceAll(repls(
new RawFindReplace("(issue\\s(\\d+))", "<a href=\"?$2\">$1</a>"))); new RawFindReplace("(issue\\s(\\d+))", "<a href=\"?$2\">$1</a>")));
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("<a href=\"?42\">issue 42</a>", n.asString()); assertThat(n.asString()).isEqualTo(
"<a href=\"?42\">issue 42</a>");
} }
@Test @Test
@@ -55,12 +55,12 @@ public class SafeHtml_ReplaceTest {
SafeHtml o = html("A\nissue 42\nissue 9918\nB"); SafeHtml o = html("A\nissue 42\nissue 9918\nB");
SafeHtml n = o.replaceAll(repls( SafeHtml n = o.replaceAll(repls(
new RawFindReplace("(issue\\s(\\d+))", "<a href=\"?$2\">$1</a>"))); new RawFindReplace("(issue\\s(\\d+))", "<a href=\"?$2\">$1</a>")));
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("A\n" assertThat(n.asString()).isEqualTo(
"A\n"
+ "<a href=\"?42\">issue 42</a>\n" + "<a href=\"?42\">issue 42</a>\n"
+ "<a href=\"?9918\">issue 9918</a>\n" + "<a href=\"?9918\">issue 9918</a>\n"
+ "B" + "B");
, n.asString());
} }
@Test @Test
@@ -71,12 +71,12 @@ public class SafeHtml_ReplaceTest {
"<a href=\"gwtexpui-bug?$2\">$1</a>"), "<a href=\"gwtexpui-bug?$2\">$1</a>"),
new RawFindReplace("(issue\\s+(\\d+))", new RawFindReplace("(issue\\s+(\\d+))",
"<a href=\"generic-bug?$2\">$1</a>"))); "<a href=\"generic-bug?$2\">$1</a>")));
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("A\n" assertThat(n.asString()).isEqualTo(
"A\n"
+ "<a href=\"generic-bug?42\">issue 42</a>\n" + "<a href=\"generic-bug?42\">issue 42</a>\n"
+ "Really <a href=\"gwtexpui-bug?9918\">GWTEXPUI-9918</a> is better\n" + "Really <a href=\"gwtexpui-bug?9918\">GWTEXPUI-9918</a> is better\n"
+ "B" + "B");
, n.asString());
} }
@Test @Test
@@ -86,9 +86,9 @@ public class SafeHtml_ReplaceTest {
RawFindReplace bc = new RawFindReplace("bc", "23"); RawFindReplace bc = new RawFindReplace("bc", "23");
RawFindReplace cd = new RawFindReplace("cd", "YZ"); RawFindReplace cd = new RawFindReplace("cd", "YZ");
assertEquals("ABcd", o.replaceAll(repls(ab, bc)).asString()); assertThat(o.replaceAll(repls(ab, bc)).asString()).isEqualTo("ABcd");
assertEquals("ABcd", o.replaceAll(repls(bc, ab)).asString()); assertThat(o.replaceAll(repls(bc, ab)).asString()).isEqualTo("ABcd");
assertEquals("ABYZ", o.replaceAll(repls(ab, bc, cd)).asString()); assertThat(o.replaceAll(repls(ab, bc, cd)).asString()).isEqualTo("ABYZ");
} }
@Test @Test
@@ -97,8 +97,8 @@ public class SafeHtml_ReplaceTest {
RawFindReplace ab = new RawFindReplace("ab", "AB"); RawFindReplace ab = new RawFindReplace("ab", "AB");
RawFindReplace abc = new RawFindReplace("[^d][^d][^d]", "234"); RawFindReplace abc = new RawFindReplace("[^d][^d][^d]", "234");
assertEquals("ABcd", o.replaceAll(repls(ab, abc)).asString()); assertThat(o.replaceAll(repls(ab, abc)).asString()).isEqualTo("ABcd");
assertEquals("234d", o.replaceAll(repls(abc, ab)).asString()); assertThat(o.replaceAll(repls(abc, ab)).asString()).isEqualTo("234d");
} }
@Test @Test
@@ -107,8 +107,8 @@ public class SafeHtml_ReplaceTest {
RawFindReplace ab1 = new RawFindReplace("ab", "AB"); RawFindReplace ab1 = new RawFindReplace("ab", "AB");
RawFindReplace ab2 = new RawFindReplace("[^cd][^cd]", "12"); RawFindReplace ab2 = new RawFindReplace("[^cd][^cd]", "12");
assertEquals("ABcd", o.replaceAll(repls(ab1, ab2)).asString()); assertThat(o.replaceAll(repls(ab1, ab2)).asString()).isEqualTo("ABcd");
assertEquals("12cd", o.replaceAll(repls(ab2, ab1)).asString()); assertThat(o.replaceAll(repls(ab2, ab1)).asString()).isEqualTo("12cd");
} }
@Test @Test
@@ -116,10 +116,10 @@ public class SafeHtml_ReplaceTest {
SafeHtml o = html("abcd"); SafeHtml o = html("abcd");
LinkFindReplace evil = new LinkFindReplace("(b)", "javascript:alert('$1')"); LinkFindReplace evil = new LinkFindReplace("(b)", "javascript:alert('$1')");
LinkFindReplace ok = new LinkFindReplace("(b)", "/$1"); LinkFindReplace ok = new LinkFindReplace("(b)", "/$1");
assertEquals("abcd", o.replaceAll(repls(evil)).asString()); assertThat(o.replaceAll(repls(evil)).asString()).isEqualTo("abcd");
String linked = "a<a href=\"/b\">b</a>cd"; String linked = "a<a href=\"/b\">b</a>cd";
assertEquals(linked, o.replaceAll(repls(ok)).asString()); assertThat(o.replaceAll(repls(ok)).asString()).isEqualTo(linked);
assertEquals(linked, o.replaceAll(repls(evil, ok)).asString()); assertThat(o.replaceAll(repls(evil, ok)).asString()).isEqualTo(linked);
} }
private static SafeHtml html(String text) { private static SafeHtml html(String text) {

View File

@@ -14,8 +14,7 @@
package com.google.gwtexpui.safehtml.client; package com.google.gwtexpui.safehtml.client;
import static org.junit.Assert.assertEquals; import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertNotSame;
import org.junit.Test; import org.junit.Test;
@@ -31,40 +30,40 @@ public class SafeHtml_WikifyListTest {
public void testBulletList1() { public void testBulletList1() {
final SafeHtml o = html("A\n\n* line 1\n* 2nd line"); final SafeHtml o = html("A\n\n* line 1\n* 2nd line");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("<p>A</p>"// assertThat(n.asString()).isEqualTo(
+ BEGIN_LIST // "<p>A</p>"
+ item("line 1") // + BEGIN_LIST
+ item("2nd line") // + item("line 1")
+ END_LIST // + item("2nd line")
, n.asString()); + END_LIST);
} }
@Test @Test
public void testBulletList2() { public void testBulletList2() {
final SafeHtml o = html("A\n\n* line 1\n* 2nd line\n\nB"); final SafeHtml o = html("A\n\n* line 1\n* 2nd line\n\nB");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("<p>A</p>"// assertThat(n.asString()).isEqualTo(
+ BEGIN_LIST // "<p>A</p>"
+ item("line 1") // + BEGIN_LIST
+ item("2nd line") // + item("line 1")
+ END_LIST // + item("2nd line")
+ "<p>B</p>" // + END_LIST
, n.asString()); + "<p>B</p>");
} }
@Test @Test
public void testBulletList3() { public void testBulletList3() {
final SafeHtml o = html("* line 1\n* 2nd line\n\nB"); final SafeHtml o = html("* line 1\n* 2nd line\n\nB");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals(BEGIN_LIST // assertThat(n.asString()).isEqualTo(
+ item("line 1") // BEGIN_LIST
+ item("2nd line") // + item("line 1")
+ END_LIST // + item("2nd line")
+ "<p>B</p>" // + END_LIST
, n.asString()); + "<p>B</p>");
} }
@Test @Test
@@ -73,13 +72,13 @@ public class SafeHtml_WikifyListTest {
+ "* Be on IMAP or EAS (not on POP)\n"// + "* Be on IMAP or EAS (not on POP)\n"//
+ "* Be very unlucky\n"); + "* Be very unlucky\n");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("<p>To see this bug, you have to:</p>" // assertThat(n.asString()).isEqualTo(
+ BEGIN_LIST // "<p>To see this bug, you have to:</p>"
+ item("Be on IMAP or EAS (not on POP)") // + BEGIN_LIST
+ item("Be very unlucky") // + item("Be on IMAP or EAS (not on POP)")
+ END_LIST // + item("Be very unlucky")
, n.asString()); + END_LIST);
} }
@Test @Test
@@ -89,53 +88,53 @@ public class SafeHtml_WikifyListTest {
+ "* Be on IMAP or EAS (not on POP)\n"// + "* Be on IMAP or EAS (not on POP)\n"//
+ "* Be very unlucky\n"); + "* Be very unlucky\n");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("<p>To see this bug, you have to:</p>" // assertThat(n.asString()).isEqualTo(
+ BEGIN_LIST // "<p>To see this bug, you have to:</p>"
+ item("Be on IMAP or EAS (not on POP)") // + BEGIN_LIST
+ item("Be very unlucky") // + item("Be on IMAP or EAS (not on POP)")
+ END_LIST // + item("Be very unlucky")
, n.asString()); + END_LIST);
} }
@Test @Test
public void testDashList1() { public void testDashList1() {
final SafeHtml o = html("A\n\n- line 1\n- 2nd line"); final SafeHtml o = html("A\n\n- line 1\n- 2nd line");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("<p>A</p>"// assertThat(n.asString()).isEqualTo(
+ BEGIN_LIST // "<p>A</p>"
+ item("line 1") // + BEGIN_LIST
+ item("2nd line") // + item("line 1")
+ END_LIST // + item("2nd line")
, n.asString()); + END_LIST);
} }
@Test @Test
public void testDashList2() { public void testDashList2() {
final SafeHtml o = html("A\n\n- line 1\n- 2nd line\n\nB"); final SafeHtml o = html("A\n\n- line 1\n- 2nd line\n\nB");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("<p>A</p>"// assertThat(n.asString()).isEqualTo(
+ BEGIN_LIST // "<p>A</p>"
+ item("line 1") // + BEGIN_LIST
+ item("2nd line") // + item("line 1")
+ END_LIST // + item("2nd line")
+ "<p>B</p>" // + END_LIST
, n.asString()); + "<p>B</p>");
} }
@Test @Test
public void testDashList3() { public void testDashList3() {
final SafeHtml o = html("- line 1\n- 2nd line\n\nB"); final SafeHtml o = html("- line 1\n- 2nd line\n\nB");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals(BEGIN_LIST // assertThat(n.asString()).isEqualTo(
+ item("line 1") // BEGIN_LIST
+ item("2nd line") // + item("line 1")
+ END_LIST // + item("2nd line")
+ "<p>B</p>" // + END_LIST
, n.asString()); + "<p>B</p>");
} }
private static SafeHtml html(String text) { private static SafeHtml html(String text) {

View File

@@ -14,8 +14,7 @@
package com.google.gwtexpui.safehtml.client; package com.google.gwtexpui.safehtml.client;
import static org.junit.Assert.assertEquals; import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertNotSame;
import org.junit.Test; import org.junit.Test;
@@ -31,56 +30,56 @@ public class SafeHtml_WikifyPreformatTest {
public void testPreformat1() { public void testPreformat1() {
final SafeHtml o = html("A\n\n This is pre\n formatted"); final SafeHtml o = html("A\n\n This is pre\n formatted");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("<p>A</p>"// assertThat(n.asString()).isEqualTo(
+ "<p>" // "<p>A</p>"
+ pre(" This is pre") // + "<p>"
+ pre(" formatted") // + pre(" This is pre")
+ "</p>" // + pre(" formatted")
, n.asString()); + "</p>");
} }
@Test @Test
public void testPreformat2() { public void testPreformat2() {
final SafeHtml o = html("A\n\n This is pre\n formatted\n\nbut this is not"); final SafeHtml o = html("A\n\n This is pre\n formatted\n\nbut this is not");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("<p>A</p>" // assertThat(n.asString()).isEqualTo(
+ "<p>" // "<p>A</p>"
+ pre(" This is pre") // + "<p>"
+ pre(" formatted") // + pre(" This is pre")
+ "</p>" // + pre(" formatted")
+ "<p>but this is not</p>" // + "</p>"
, n.asString()); + "<p>but this is not</p>");
} }
@Test @Test
public void testPreformat3() { public void testPreformat3() {
final SafeHtml o = html("A\n\n Q\n <R>\n S\n\nB"); final SafeHtml o = html("A\n\n Q\n <R>\n S\n\nB");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("<p>A</p>" // assertThat(n.asString()).isEqualTo(
+ "<p>" // "<p>A</p>"
+ pre(" Q") // + "<p>"
+ pre(" &lt;R&gt;") // + pre(" Q")
+ pre(" S") // + pre(" &lt;R&gt;")
+ "</p>" // + pre(" S")
+ "<p>B</p>" // + "</p>"
, n.asString()); + "<p>B</p>");
} }
@Test @Test
public void testPreformat4() { public void testPreformat4() {
final SafeHtml o = html(" Q\n <R>\n S\n\nB"); final SafeHtml o = html(" Q\n <R>\n S\n\nB");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("<p>" // assertThat(n.asString()).isEqualTo(
+ pre(" Q") // "<p>"
+ pre(" &lt;R&gt;") // + pre(" Q")
+ pre(" S") // + pre(" &lt;R&gt;")
+ "</p>" // + pre(" S")
+ "<p>B</p>" // + "</p>"
, n.asString()); + "<p>B</p>");
} }
private static SafeHtml html(String text) { private static SafeHtml html(String text) {

View File

@@ -14,8 +14,7 @@
package com.google.gwtexpui.safehtml.client; package com.google.gwtexpui.safehtml.client;
import static org.junit.Assert.assertEquals; import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertNotSame;
import org.junit.Test; import org.junit.Test;
@@ -31,32 +30,28 @@ public class SafeHtml_WikifyQuoteTest {
public void testQuote1() { public void testQuote1() {
final SafeHtml o = html("> I'm happy\n > with quotes!\n\nSee above."); final SafeHtml o = html("> I'm happy\n > with quotes!\n\nSee above.");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals( assertThat(n.asString()).isEqualTo(
quote("I&#39;m happy\nwith quotes!") quote("I&#39;m happy\nwith quotes!")
+ "<p>See above.</p>", + "<p>See above.</p>");
n.asString());
} }
@Test @Test
public void testQuote2() { public void testQuote2() {
final SafeHtml o = html("See this said:\n\n > a quoted\n > string block\n\nOK?"); final SafeHtml o = html("See this said:\n\n > a quoted\n > string block\n\nOK?");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals( assertThat(n.asString()).isEqualTo(
"<p>See this said:</p>" "<p>See this said:</p>"
+ quote("a quoted\nstring block") + quote("a quoted\nstring block")
+ "<p>OK?</p>", + "<p>OK?</p>");
n.asString());
} }
@Test @Test
public void testNestedQuotes1() { public void testNestedQuotes1() {
final SafeHtml o = html(" > > prior\n > \n > next\n"); final SafeHtml o = html(" > > prior\n > \n > next\n");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertEquals( assertThat(n.asString()).isEqualTo(quote(quote("prior") + "next\n"));
quote(quote("prior") + "next\n"),
n.asString());
} }
private static SafeHtml html(String text) { private static SafeHtml html(String text) {

View File

@@ -14,8 +14,7 @@
package com.google.gwtexpui.safehtml.client; package com.google.gwtexpui.safehtml.client;
import static org.junit.Assert.assertEquals; import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertNotSame;
import org.junit.Test; import org.junit.Test;
@@ -24,80 +23,85 @@ public class SafeHtml_WikifyTest {
public void testWikify_OneLine1() { public void testWikify_OneLine1() {
final SafeHtml o = html("A B"); final SafeHtml o = html("A B");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("<p>A B</p>", n.asString()); assertThat(n.asString()).isEqualTo("<p>A B</p>");
} }
@Test @Test
public void testWikify_OneLine2() { public void testWikify_OneLine2() {
final SafeHtml o = html("A B\n"); final SafeHtml o = html("A B\n");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("<p>A B\n</p>", n.asString()); assertThat(n.asString()).isEqualTo("<p>A B\n</p>");
} }
@Test @Test
public void testWikify_OneParagraph1() { public void testWikify_OneParagraph1() {
final SafeHtml o = html("A\nB"); final SafeHtml o = html("A\nB");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("<p>A\nB</p>", n.asString()); assertThat(n.asString()).isEqualTo("<p>A\nB</p>");
} }
@Test @Test
public void testWikify_OneParagraph2() { public void testWikify_OneParagraph2() {
final SafeHtml o = html("A\nB\n"); final SafeHtml o = html("A\nB\n");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("<p>A\nB\n</p>", n.asString()); assertThat(n.asString()).isEqualTo("<p>A\nB\n</p>");
} }
@Test @Test
public void testWikify_TwoParagraphs() { public void testWikify_TwoParagraphs() {
final SafeHtml o = html("A\nB\n\nC\nD"); final SafeHtml o = html("A\nB\n\nC\nD");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("<p>A\nB</p><p>C\nD</p>", n.asString()); assertThat(n.asString()).isEqualTo("<p>A\nB</p><p>C\nD</p>");
} }
@Test @Test
public void testLinkify_SimpleHttp1() { public void testLinkify_SimpleHttp1() {
final SafeHtml o = html("A http://go.here/ B"); final SafeHtml o = html("A http://go.here/ B");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("<p>A <a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a> B</p>", n.asString()); assertThat(n.asString()).isEqualTo(
"<p>A <a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a> B</p>");
} }
@Test @Test
public void testLinkify_SimpleHttps2() { public void testLinkify_SimpleHttps2() {
final SafeHtml o = html("A https://go.here/ B"); final SafeHtml o = html("A https://go.here/ B");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("<p>A <a href=\"https://go.here/\" target=\"_blank\">https://go.here/</a> B</p>", n.asString()); assertThat(n.asString()).isEqualTo(
"<p>A <a href=\"https://go.here/\" target=\"_blank\">https://go.here/</a> B</p>");
} }
@Test @Test
public void testLinkify_Parens1() { public void testLinkify_Parens1() {
final SafeHtml o = html("A (http://go.here/) B"); final SafeHtml o = html("A (http://go.here/) B");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("<p>A (<a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>) B</p>", n.asString()); assertThat(n.asString()).isEqualTo(
"<p>A (<a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>) B</p>");
} }
@Test @Test
public void testLinkify_Parens() { public void testLinkify_Parens() {
final SafeHtml o = html("A http://go.here/#m() B"); final SafeHtml o = html("A http://go.here/#m() B");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("<p>A <a href=\"http://go.here/#m()\" target=\"_blank\">http://go.here/#m()</a> B</p>", n.asString()); assertThat(n.asString()).isEqualTo(
"<p>A <a href=\"http://go.here/#m()\" target=\"_blank\">http://go.here/#m()</a> B</p>");
} }
@Test @Test
public void testLinkify_AngleBrackets1() { public void testLinkify_AngleBrackets1() {
final SafeHtml o = html("A <http://go.here/> B"); final SafeHtml o = html("A <http://go.here/> B");
final SafeHtml n = o.wikify(); final SafeHtml n = o.wikify();
assertNotSame(o, n); assertThat(o).isNotSameAs(n);
assertEquals("<p>A &lt;<a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>&gt; B</p>", n.asString()); assertThat(n.asString()).isEqualTo(
"<p>A &lt;<a href=\"http://go.here/\" target=\"_blank\">http://go.here/</a>&gt; B</p>");
} }
private static SafeHtml html(String text) { private static SafeHtml html(String text) {