01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Alexey A. Ivanov
19: * @version $Revision$
20: */package javax.swing.text;
21:
22: import javax.swing.text.AbstractDocument.AbstractElement;
23: import javax.swing.tree.TreeNode;
24: import junit.framework.TestCase;
25:
26: /**
27: * Tests methods of AbstractElement which implement TreeNode interface.
28: * This class contains only methods that are not abstract in
29: * AbstractElement (they must be overridden and therefore tested in a
30: * subclass) and whose behavior may slightly change from a subclass to
31: * another.
32: *
33: */
34: public class AbstractDocument_AbstractElement_TreeNodeTest extends
35: TestCase {
36: protected AbstractDocument doc;
37:
38: protected AbstractElement aElement;
39:
40: protected AbstractElement parented;
41:
42: protected AbstractElement parent;
43:
44: @Override
45: protected void setUp() throws Exception {
46: // Initialize static variables of enclosing class
47: AbstractDocument_AbstractElementTest.init();
48: // Copy their values to instance variables
49: doc = AbstractDocument_AbstractElementTest.aDocument;
50: aElement = AbstractDocument_AbstractElementTest.aElement;
51: parented = AbstractDocument_AbstractElementTest.parented;
52: parent = aElement;
53: }
54:
55: public void testGetChildCount() {
56: assertEquals(aElement.getElementCount(), aElement
57: .getChildCount());
58: assertEquals(parented.getElementCount(), parented
59: .getChildCount());
60: }
61:
62: public void testGetChildAt() {
63: assertSame(aElement.getElement(0), aElement.getChildAt(0));
64: assertSame(aElement.getElement(1), aElement.getChildAt(1));
65: assertSame(aElement.getElement(2), aElement.getChildAt(2));
66: assertSame(aElement.getElement(5), aElement.getChildAt(5));
67: assertSame(aElement.getElement(10), aElement.getChildAt(10));
68: }
69:
70: public void testGetIndex() {
71: assertEquals(-1, aElement.getIndex(null));
72: TreeNode node = aElement.getChildAt(0);
73: // Check sanity of the value
74: if (aElement.getAllowsChildren()
75: && aElement.getChildCount() > 0) {
76: assertNotNull(node);
77: }
78: // If node == null, the first condition will be true, if not
79: // the second one will come into play. Any way we get what we
80: // want.
81: assertTrue(node == null || (0 == aElement.getIndex(node)));
82: assertTrue((node = aElement.getChildAt(1)) == null
83: || (1 == aElement.getIndex(node)));
84: }
85:
86: public void testGetParent() {
87: assertNull(aElement.getParent());
88: assertNotNull(parented.getParent());
89: assertSame(parent, parented.getParent());
90: assertSame(parented.getParentElement(), parented.getParent());
91: }
92: }
|