@Test
public void testHTML() throws Exception {

    Parser p = new MockParser(OVER_DEFAULT);
    BasicContentHandlerFactory.HANDLER_TYPE type =
            BasicContentHandlerFactory.HANDLER_TYPE.HTML;
    ContentHandler handler =
            new BasicContentHandlerFactory(type, -1).getNewContentHandler();
    assertTrue(handler instanceof ToHTMLContentHandler);
    p.parse(null, handler, null, null);
    String extracted = handler.toString();
    assertContains("<head><title>This is the title", extracted);
    assertContains("aaaaaaaaaa", extracted);
    assertTrue(extracted.length() > 110000);
    //now test write limit
    p = new MockParser(10);
    handler = new BasicContentHandlerFactory(type, 5).getNewContentHandler();
    assertTrue(handler instanceof WriteOutContentHandler);
    assertWriteLimitReached(p, (WriteOutContentHandler) handler);
    extracted = handler.toString();
    assertContains("This ", extracted);
    assertNotContains("aaaa", extracted);
    //now test outputstream call
    p = new MockParser(OVER_DEFAULT);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    handler = new BasicContentHandlerFactory(type, -1).getNewContentHandler(os, ENCODING);
    assertTrue(handler instanceof ToHTMLContentHandler);
    p.parse(null, handler, null, null);
    assertContains("This is the title", os.toByteArray());
    assertContains("aaaaaaaaaa", os.toByteArray());
    assertContains("<body", os.toByteArray());
    assertContains("<html", os.toByteArray());
    assertTrue(os.toByteArray().length > 110000);
    p = new MockParser(10);
    os = new ByteArrayOutputStream();
    handler = new BasicContentHandlerFactory(type, 5).getNewContentHandler(os, ENCODING);
    assertTrue(handler instanceof WriteOutContentHandler);
    assertWriteLimitReached(p, (WriteOutContentHandler) handler);
    assertEquals(0, os.toByteArray().length);
}