1 27 package org.htmlparser.tests.visitorsTests; 28 29 import org.htmlparser.tests.ParserTestCase; 30 import org.htmlparser.visitors.TextExtractingVisitor; 31 32 public class TextExtractingVisitorTest extends ParserTestCase { 33 34 static 35 { 36 System.setProperty ("org.htmlparser.tests.visitorsTests.TextExtractingVisitorTest", "TextExtractingVisitorTest"); 37 } 38 39 public TextExtractingVisitorTest(String name) { 40 super(name); 41 } 42 43 public void testSimpleVisit() throws Exception { 44 createParser("<HTML><HEAD><TITLE>Hello World</TITLE></HEAD></HTML>"); 45 TextExtractingVisitor visitor = new TextExtractingVisitor(); 46 parser.visitAllNodesWith(visitor); 47 assertStringEquals( 48 "extracted text", 49 "Hello World", 50 visitor.getExtractedText() 51 ); 52 } 53 54 public void testSimpleVisitWithRegisteredScanners() throws Exception { 55 createParser("<HTML><HEAD><TITLE>Hello World</TITLE></HEAD></HTML>"); 56 TextExtractingVisitor visitor = new TextExtractingVisitor(); 57 parser.visitAllNodesWith(visitor); 58 assertStringEquals( 59 "extracted text", 60 "Hello World", 61 visitor.getExtractedText() 62 ); 63 } 64 65 public void testVisitHtmlWithSpecialChars() throws Exception { 66 createParser("<BODY>Hello World </BODY>"); 67 TextExtractingVisitor visitor = new TextExtractingVisitor(); 68 parser.visitAllNodesWith(visitor); 69 assertStringEquals( 70 "extracted text", 71 "Hello World ", 72 visitor.getExtractedText() 73 ); 74 } 75 76 public void testVisitHtmlWithPreTags() throws Exception { 77 createParser( 78 "Some text with <pre>this should be preserved</pre>" 79 ); 80 TextExtractingVisitor visitor = new TextExtractingVisitor(); 81 parser.visitAllNodesWith(visitor); 82 assertStringEquals( 83 "extracted text", 84 "Some text with this should be preserved", 85 visitor.getExtractedText() 86 ); 87 } 88 } 89 | Popular Tags |