KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jegg > type > TypeTreeTest


1 /*
2  * Copyright (c) 2004, Bruce Lowery
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * - Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * - Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * - Neither the name of JEGG nor the names of its contributors may be used
14  * to endorse or promote products derived from this software without
15  * specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */

29 package jegg.type;
30
31 import java.util.Collection JavaDoc;
32
33 import jegg.impl.TestBase;
34
35 /**
36  *
37  */

38 public class TypeTreeTest extends TestBase
39 {
40     static
41     {
42         setTestClass(TypeTreeTest.class);
43     }
44     
45     private TypeTree tree;
46     private Node nodeA, nodeA1, nodeA2;
47     private Node nodeB, nodeB1, nodeB2;
48     private Node nodeC, nodeC1, nodeC2;
49     
50     public TypeTreeTest(String JavaDoc n)
51     {
52         super(n);
53     }
54     
55     public void setup()
56     {
57         tree = new TypeTree();
58         nodeA = new Node(TypeA.class);
59         nodeA1 = new Node(TypeA1.class);
60         nodeA2 = new Node(TypeA2.class);
61         nodeB = new Node(TypeB.class);
62         nodeB1 = new Node(TypeB1.class);
63         nodeB2 = new Node(TypeB2.class);
64         nodeC = new Node(TypeC.class);
65         nodeC1 = new Node(TypeC1.class);
66         nodeC2 = new Node(TypeC2.class);
67     }
68     
69     public void teardown()
70     {
71         // EMPTY
72
}
73     
74     public void test1()
75     {
76         tree.insert(TypeA.class, null);
77      
78         tree.insert(TypeC.class,null);
79         tree.insert(TypeC1.class,null);
80         tree.insert(TypeC2.class,null);
81         
82         tree.insert(TypeB1.class,null);
83         tree.insert(TypeB2.class,null);
84         tree.insert(TypeB.class,null);
85         
86         tree.insert(TypeA1.class, null);
87         tree.insert(TypeA2.class, null);
88         
89         Node root = tree.getRoot();
90         assertNotNull(root);
91         
92         Collection JavaDoc branches = root.getBranches();
93         assertNotNull(branches);
94         assertEquals(1,branches.size());
95         assertEquals(Object JavaDoc.class, root.getType());
96         
97         Node rc1 = (Node) root.getBranches().iterator().next();
98         assertNotNull(rc1);
99         
100         Collection JavaDoc rc1_branches = rc1.getBranches();
101         assertNotNull(rc1_branches);
102         assertEquals(3,rc1_branches.size());
103         assertEquals(TypeA.class, rc1.getType());
104         
105         assertEquals(TypeA1.class, tree.find(TypeA1.class).getType());
106         assertEquals(TypeA2.class, tree.find(TypeA2.class).getType());
107         assertEquals(TypeB.class, tree.find(TypeB.class).getType());
108         assertEquals(TypeB1.class, tree.find(TypeB1.class).getType());
109         assertEquals(TypeB2.class, tree.find(TypeB2.class).getType());
110         assertEquals(TypeC.class, tree.find(TypeC.class).getType());
111         assertEquals(TypeC1.class, tree.find(TypeC1.class).getType());
112         assertEquals(TypeC2.class, tree.find(TypeC2.class).getType());
113     }
114 }
115
Popular Tags