1 19 20 33 package org.htmlparser.tests.scannersTests; 34 35 import org.htmlparser.Node; 36 import org.htmlparser.scanners.HtmlScanner; 37 import org.htmlparser.scanners.TitleScanner; 38 import org.htmlparser.tags.Html; 39 import org.htmlparser.tags.TitleTag; 40 import org.htmlparser.tests.ParserTestCase; 41 import org.htmlparser.util.NodeList; 42 43 public class HtmlTest extends ParserTestCase 44 { 45 46 public HtmlTest(String name) 47 { 48 super(name); 49 } 50 51 public void testScan() throws Exception 52 { 53 createParser( 54 "<html>" 55 + " <head>" 56 + " <title>Some Title</title>" 57 + " </head>" 58 + " <body>" 59 + " Some data" 60 + " </body>" 61 + "</html>"); 62 parser.addScanner(new TitleScanner("")); 63 parser.addScanner(new HtmlScanner()); 64 parseAndAssertNodeCount(1); 65 assertType("html tag", Html.class, node[0]); 66 Html html = (Html) node[0]; 67 NodeList nodeList = new NodeList(); 68 html.collectInto(nodeList, TitleTag.class); 69 assertEquals("nodelist size", 1, nodeList.size()); 70 Node node = nodeList.elementAt(0); 71 assertType("expected title tag", TitleTag.class, node); 72 TitleTag titleTag = (TitleTag) node; 73 assertStringEquals("title", "Some Title", titleTag.getTitle()); 74 } 75 } 76 | Popular Tags |