1 7 8 package org.dom4j.xpath; 9 10 import junit.textui.TestRunner; 11 12 import java.util.Iterator ; 13 import java.util.List ; 14 15 import org.dom4j.AbstractTestCase; 16 import org.dom4j.Text; 17 18 24 public class TextTest extends AbstractTestCase { 25 protected static String [] paths = {"text()", "//author/text()"}; 26 27 public static void main(String [] args) { 28 TestRunner.run(TextTest.class); 29 } 30 31 public void testXPaths() throws Exception { 34 int size = paths.length; 35 36 for (int i = 0; i < size; i++) { 37 testXPath(paths[i]); 38 } 39 } 40 41 protected void testXPath(String xpath) { 44 List list = document.selectNodes(xpath); 45 46 for (Iterator iter = list.iterator(); iter.hasNext();) { 47 Object object = iter.next(); 48 49 log("Found Result: " + object); 50 51 assertTrue("Results not Text objects", object instanceof Text); 52 53 Text text = (Text) object; 54 55 assertTrue("Results should support the parent relationship", text 56 .supportsParent()); 57 assertTrue( 58 "Results should contain reference to the parent element", 59 text.getParent() != null); 60 assertTrue("Results should not reference to the owning document", 61 text.getDocument() != null); 62 } 63 } 64 } 65 66 102 | Popular Tags |