1 9 10 package test.dom4j; 11 12 import junit.framework.Test; 13 import junit.framework.TestSuite; 14 import junit.textui.TestRunner; 15 import org.dom4j.Attribute; 16 import org.dom4j.Document; 17 import org.dom4j.Element; 18 import org.dom4j.QName; 19 20 25 public class TestNullAttributes extends AbstractTestCase { 26 27 protected Document document; 28 protected Element element; 29 30 public static void main(String [] args) { 31 TestRunner.run(suite()); 32 } 33 34 public static Test suite() { 35 return new TestSuite(TestNullAttributes.class); 36 } 37 38 public TestNullAttributes(String name) { 39 super(name); 40 } 41 42 protected void setUp() throws Exception { 45 super.setUp(); 46 document = nodeFactory.createDocument(); 47 element = document.addElement("root"); 48 } 49 50 public void testStringNames() throws Exception { 53 54 element.addAttribute("foo", null); 55 Attribute attribute = element.attribute("foo"); 56 assertTrue(attribute == null); 57 58 element.addAttribute("foo", "123"); 59 attribute = element.attribute("foo"); 60 assertTrue(attribute != null); 61 62 element.addAttribute("foo", null); 63 attribute = element.attribute("foo"); 64 assertTrue(attribute == null); 65 } 66 67 public void testQNames() throws Exception { 68 69 QName bar = nodeFactory.createQName("bar"); 70 71 element.addAttribute(bar, null); 72 Attribute attribute = element.attribute(bar); 73 assertTrue(attribute == null); 74 75 element.addAttribute(bar, "123"); 76 attribute = element.attribute(bar); 77 assertTrue(attribute != null); 78 79 element.addAttribute(bar, null); 80 attribute = element.attribute(bar); 81 assertTrue(attribute == null); 82 } 83 84 public void testAttributes() throws Exception { 85 86 Attribute attribute = nodeFactory.createAttribute(element, "v", null); 87 88 assertTrue(attribute.getText() == null); 89 assertTrue(attribute.getValue() == null); 90 91 element.add(attribute); 92 attribute = element.attribute("v"); 93 assertTrue(attribute == null); 94 95 attribute = nodeFactory.createAttribute(element, "v", "123"); 96 element.add(attribute); 97 attribute = element.attribute("v"); 98 assertTrue(attribute != null); 99 100 attribute = nodeFactory.createAttribute(element, "v", null); 101 element.add(attribute); 102 attribute = element.attribute("v"); 103 assertTrue(attribute == null); 104 } 105 106 } 107 108 109 153 | Popular Tags |