Html extends Component { public String getInnerHtml() { return get(innerHtmlDescriptor); } Html(InputStream stream);  Html(String outerHtml); String getInnerHtml();  }
@Test public void simpleHtml() { Html html = new Html("<span>hello</span>"); Assert.assertEquals(Tag.SPAN, html.getElement().getTag()); Assert.assertEquals("hello", html.getInnerHtml()); }
@Test public void rootAttributes() { Html html = new Html("<span foo='bar'>hello</span>"); Assert.assertEquals(Tag.SPAN, html.getElement().getTag()); Assert.assertEquals(1, html.getElement().getAttributeNames().count()); Assert.assertEquals("bar", html.getElement().getAttribute("foo")); Assert.assertEquals("hello", html.getInnerHtml()); }
@Test public void rootSpecialAttributes() { Html html = new Html( "<span class='foo' style='color: red'>hello</span>"); Element element = html.getElement(); Assert.assertEquals(Tag.SPAN, element.getTag()); Assert.assertEquals(2, element.getAttributeNames().count()); Assert.assertEquals("foo", element.getAttribute("class")); Assert.assertEquals("color:red", element.getAttribute("style")); Assert.assertEquals("hello", html.getInnerHtml()); }
@Test public void brokenHtml() { Html html = new Html("<b></div>"); Assert.assertEquals("b", html.getElement().getTag()); Assert.assertEquals("", html.getInnerHtml()); }
@Test public void extraWhitespace() { String input = " <span> " + " <div>" + " <b>Hello!</b>" + " </div>" + "</span>" + " " + "" + ""; Html html = new Html(input); Assert.assertEquals(Tag.SPAN, html.getElement().getTag()); String expectedInnerHtml = input.replaceAll("^[ ]*<span>", "") .replaceAll("</span>[ ]*$", ""); Assert.assertEquals(expectedInnerHtml, html.getInnerHtml()); }