1 7 8 package org.dom4j.datatype; 9 10 import java.util.Iterator ; 11 import java.util.List ; 12 13 import org.dom4j.AbstractTestCase; 14 import org.dom4j.Attribute; 15 import org.dom4j.Element; 16 import org.dom4j.Node; 17 18 25 public class AbstractDataTypeTestCase extends AbstractTestCase { 26 protected void testNodes(String xpath, Class type) { 29 List list = document.selectNodes(xpath); 30 31 assertTrue("Results are not empty", !list.isEmpty()); 32 33 for (Iterator iter = list.iterator(); iter.hasNext();) { 34 Node node = (Node) iter.next(); 35 36 if (node instanceof Element) { 37 Element element = (Element) node; 38 testDataType(element, element.getData(), type); 39 } else if (node instanceof Attribute) { 40 Attribute attribute = (Attribute) node; 41 testDataType(attribute, attribute.getData(), type); 42 } else { 43 assertTrue("Did not find an attribute or element: " + node, 44 false); 45 } 46 } 47 } 48 49 protected void testDataType(Node node, Object data, Class type) { 50 assertTrue("Data object is not null", data != null); 51 52 assertTrue("Data object is of the correct type. Expected: " 53 + type.getName() + " and found: " + data.getClass().getName(), 54 type.isAssignableFrom(data.getClass())); 55 } 56 } 57 58 94 | Popular Tags |