1 27 package org.htmlparser.tests.nodeDecoratorTests; 28 29 import org.htmlparser.StringNodeFactory; 30 import org.htmlparser.tests.ParserTestCase; 31 import org.htmlparser.util.NodeIterator; 32 import org.htmlparser.util.ParserException; 33 34 public class EscapeCharacterRemovingNodeTest extends ParserTestCase { 35 36 static 37 { 38 System.setProperty ("org.htmlparser.tests.nodeDecoratorTests.EscapeCharacterRemovingNodeTest", "EscapeCharacterRemovingNodeTest"); 39 } 40 41 public EscapeCharacterRemovingNodeTest(String name) { 42 super(name); 43 } 44 45 private String parseToObtainDecodedResult(String STRING_TO_DECODE) 46 throws ParserException { 47 StringBuffer decodedContent = new StringBuffer (); 48 49 StringNodeFactory stringNodeFactory = new StringNodeFactory(); 50 stringNodeFactory.setRemoveEscapes (true); 51 createParser(STRING_TO_DECODE); 52 parser.setNodeFactory(stringNodeFactory); 53 54 NodeIterator nodes = parser.elements(); 55 56 while (nodes.hasMoreNodes()) 57 decodedContent.append(nodes.nextNode().toPlainTextString()); 58 59 return decodedContent.toString(); 60 } 61 62 public void testTab() throws Exception { 63 String ENCODED_WORKSHOP_TITLE = 64 "The Testing & Refactoring Workshop\tCreated by Industrial Logic, Inc."; 65 66 String DECODED_WORKSHOP_TITLE = 67 "The Testing & Refactoring WorkshopCreated by Industrial Logic, Inc."; 68 69 assertEquals( 70 "tab in string", 71 DECODED_WORKSHOP_TITLE, 72 parseToObtainDecodedResult(ENCODED_WORKSHOP_TITLE)); 73 } 74 75 public void testCarriageReturn() throws Exception { 76 String ENCODED_WORKSHOP_TITLE = 77 "The Testing & Refactoring Workshop\nCreated by Industrial Logic, Inc.\n"; 78 79 String DECODED_WORKSHOP_TITLE = 80 "The Testing & Refactoring WorkshopCreated by Industrial Logic, Inc."; 81 82 assertEquals( 83 "tab in string", 84 DECODED_WORKSHOP_TITLE, 85 parseToObtainDecodedResult(ENCODED_WORKSHOP_TITLE)); 86 } 87 88 public void testWithDecodingNodeDecorator() throws Exception { 89 String ENCODED_WORKSHOP_TITLE = 90 "The Testing & Refactoring Workshop\nCreated by Industrial Logic, Inc.\n"; 91 92 String DECODED_WORKSHOP_TITLE = 93 "The Testing & Refactoring WorkshopCreated by Industrial Logic, Inc."; 94 95 StringBuffer decodedContent = new StringBuffer (); 96 97 StringNodeFactory stringNodeFactory = new StringNodeFactory(); 98 stringNodeFactory.setDecode (true); 99 stringNodeFactory.setRemoveEscapes (true); 100 101 createParser(ENCODED_WORKSHOP_TITLE); 102 parser.setNodeFactory(stringNodeFactory); 103 NodeIterator nodes = parser.elements(); 104 105 while (nodes.hasMoreNodes()) 106 decodedContent.append(nodes.nextNode().toPlainTextString()); 107 108 assertEquals( 109 "tab in string", 110 DECODED_WORKSHOP_TITLE, 111 decodedContent.toString()); 112 113 } 114 } 115 | Popular Tags |