1 16 package org.apache.commons.betwixt; 17 18 import junit.framework.Test; 19 import junit.framework.TestSuite; 20 import junit.textui.TestRunner; 21 22 23 28 public class TestDescriptors extends AbstractTestCase { 29 30 public static void main( String [] args ) { 31 TestRunner.run( suite() ); 32 } 33 34 public static Test suite() { 35 return new TestSuite(TestDescriptors.class); 36 } 37 38 public TestDescriptors(String testName) { 39 super(testName); 40 } 41 42 public void testElementDescriptorLazyInit() { 43 ElementDescriptor descriptor = new ElementDescriptor(); 44 45 assertTrue("Empty descriptor has no children", !descriptor.hasChildren()); 47 assertTrue("Empty descriptor has no content", !descriptor.hasContent()); 48 assertTrue("Empty descriptor has no attributes", !descriptor.hasAttributes()); 49 50 descriptor.addAttributeDescriptor(new AttributeDescriptor("test:one")); 52 assertTrue("Empty descriptor has no children", !descriptor.hasChildren()); 53 assertTrue("Empty descriptor has no content", !descriptor.hasContent()); 54 assertTrue("Descriptor has attributes (1)", descriptor.hasAttributes()); 55 56 descriptor.addElementDescriptor(new ElementDescriptor("test:two")); 58 assertTrue("Descriptor has children (1)", descriptor.hasChildren()); 59 assertTrue("Descriptor has content (1)", descriptor.hasContent()); 60 assertTrue("Descriptor has attributes (2)", descriptor.hasAttributes()); 61 62 descriptor = new ElementDescriptor(); 64 65 descriptor.addElementDescriptor(new ElementDescriptor("test:one")); 67 assertTrue("Descriptor has children (2)", descriptor.hasChildren()); 68 assertTrue("Descriptor has content (2)", descriptor.hasContent()); 69 assertTrue("Descriptor has no attributes (1)", !descriptor.hasAttributes()); 70 71 descriptor.addAttributeDescriptor(new AttributeDescriptor("test:two")); 73 assertTrue("Descriptor has children (3)", descriptor.hasChildren()); 74 assertTrue("Descriptor has content (3)", descriptor.hasContent()); 75 assertTrue("Descriptor has attributes (2)", descriptor.hasAttributes()); 76 77 descriptor = new ElementDescriptor(); 79 descriptor.addContentDescriptor(new AttributeDescriptor("test:one")); 80 assertTrue("Descriptor has no children (1)", !descriptor.hasChildren()); 81 assertTrue("Descriptor has content (3)", descriptor.hasContent()); 82 assertTrue("Descriptor has no attributes (2)", !descriptor.hasAttributes()); 83 84 descriptor.addElementDescriptor(new ElementDescriptor("test:two")); 86 assertTrue("Descriptor has children (4)", descriptor.hasChildren()); 87 assertTrue("Descriptor has content (4)", descriptor.hasContent()); 88 assertTrue("Descriptor has no attributes (3)", !descriptor.hasAttributes()); 89 90 descriptor.addAttributeDescriptor(new AttributeDescriptor("test:three")); 92 assertTrue("Descriptor has children (5)", descriptor.hasChildren()); 93 assertTrue("Descriptor has content (5)", descriptor.hasContent()); 94 assertTrue("Descriptor has attributes (3)", descriptor.hasAttributes()); 95 } 96 97 public void testGetElementDescriptorByName() 98 { 99 ElementDescriptor descriptor = new ElementDescriptor("Flintstones"); 100 descriptor.addElementDescriptor(new ElementDescriptor("Freddy")); 101 descriptor.addElementDescriptor(new ElementDescriptor("Wilma")); 102 descriptor.addElementDescriptor(new ElementDescriptor("Pebbles")); 103 104 ElementDescriptor returned = descriptor.getElementDescriptor("Freddy"); 105 assertTrue("Freddy is a Flintstone", returned != null); 106 assertEquals("Freddy is the right flintstone", "Freddy", returned.getLocalName()); 107 108 returned = descriptor.getElementDescriptor("Wilma"); 109 assertTrue("Wilma is a Flintstone", returned != null); 110 assertEquals("Wilma is the right flintstone", "Wilma", returned.getLocalName()); 111 112 returned = descriptor.getElementDescriptor("Barney"); 113 assertTrue("Barney is not a Flintstone", returned == null); 114 } 115 116 public void testGetElementDescriptorByNameNullMatch() 117 { 118 ElementDescriptor descriptor = new ElementDescriptor("Flintstones"); 119 descriptor.addElementDescriptor(new ElementDescriptor("Freddy")); 120 descriptor.addElementDescriptor(new ElementDescriptor("Wilma")); 121 descriptor.addElementDescriptor(new ElementDescriptor("Pebbles")); 122 descriptor.addElementDescriptor(new ElementDescriptor()); 123 124 ElementDescriptor returned = descriptor.getElementDescriptor("NotFreddy"); 125 assertTrue("NotFreddy matched", returned != null); 126 assertEquals("NotFreddy match by null descriptor", null, returned.getLocalName()); 127 } 128 } 129 130 | Popular Tags |