1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.betwixt;
17
18 import junit.framework.Test;
19 import junit.framework.TestSuite;
20 import junit.textui.TestRunner;
21
22 /*** Test harness for the Descriptors (ElementDescriptor and so on).
23 *
24 * @author Robert Burrell Donkin
25 * @version $Revision: 1.5 $
26 */
27 public class TestDescriptors extends AbstractTestCase {
28
29 public static void main( String[] args ) {
30 TestRunner.run( suite() );
31 }
32
33 public static Test suite() {
34 return new TestSuite(TestDescriptors.class);
35 }
36
37 public TestDescriptors(String testName) {
38 super(testName);
39 }
40
41 public void testElementDescriptorLazyInit() {
42 ElementDescriptor descriptor = new ElementDescriptor();
43
44
45 assertTrue("Empty descriptor has no children", !descriptor.hasChildren());
46 assertTrue("Empty descriptor has no content", !descriptor.hasContent());
47 assertTrue("Empty descriptor has no attributes", !descriptor.hasAttributes());
48
49
50 descriptor.addAttributeDescriptor(new AttributeDescriptor("test:one"));
51 assertTrue("Empty descriptor has no children", !descriptor.hasChildren());
52 assertTrue("Empty descriptor has no content", !descriptor.hasContent());
53 assertTrue("Descriptor has attributes (1)", descriptor.hasAttributes());
54
55
56 descriptor.addElementDescriptor(new ElementDescriptor("test:two"));
57 assertTrue("Descriptor has children (1)", descriptor.hasChildren());
58 assertTrue("Descriptor has content (1)", descriptor.hasContent());
59 assertTrue("Descriptor has attributes (2)", descriptor.hasAttributes());
60
61
62 descriptor = new ElementDescriptor();
63
64
65 descriptor.addElementDescriptor(new ElementDescriptor("test:one"));
66 assertTrue("Descriptor has children (2)", descriptor.hasChildren());
67 assertTrue("Descriptor has content (2)", descriptor.hasContent());
68 assertTrue("Descriptor has no attributes (1)", !descriptor.hasAttributes());
69
70
71 descriptor.addAttributeDescriptor(new AttributeDescriptor("test:two"));
72 assertTrue("Descriptor has children (3)", descriptor.hasChildren());
73 assertTrue("Descriptor has content (3)", descriptor.hasContent());
74 assertTrue("Descriptor has attributes (2)", descriptor.hasAttributes());
75
76
77 descriptor = new ElementDescriptor();
78 descriptor.addContentDescriptor(new AttributeDescriptor("test:one"));
79 assertTrue("Descriptor has no children (1)", !descriptor.hasChildren());
80 assertTrue("Descriptor has content (3)", descriptor.hasContent());
81 assertTrue("Descriptor has no attributes (2)", !descriptor.hasAttributes());
82
83
84 descriptor.addElementDescriptor(new ElementDescriptor("test:two"));
85 assertTrue("Descriptor has children (4)", descriptor.hasChildren());
86 assertTrue("Descriptor has content (4)", descriptor.hasContent());
87 assertTrue("Descriptor has no attributes (3)", !descriptor.hasAttributes());
88
89
90 descriptor.addAttributeDescriptor(new AttributeDescriptor("test:three"));
91 assertTrue("Descriptor has children (5)", descriptor.hasChildren());
92 assertTrue("Descriptor has content (5)", descriptor.hasContent());
93 assertTrue("Descriptor has attributes (3)", descriptor.hasAttributes());
94 }
95 }
96