001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Alexander T. Simbirtsev
019: * @version $Revision$
020: */package javax.swing.event;
021:
022: import java.util.Arrays;
023: import javax.swing.SwingTestCase;
024: import javax.swing.tree.TreePath;
025:
026: public class TreeModelEventTest extends SwingTestCase {
027: protected TreeModelEvent event = null;
028:
029: @Override
030: protected void setUp() throws Exception {
031: super .setUp();
032: }
033:
034: @Override
035: protected void tearDown() throws Exception {
036: event = null;
037: super .tearDown();
038: }
039:
040: /*
041: * Test method for 'javax.swing.event.TreeModelEvent.TreeModelEvent(Object, TreePath, int[], Object[])'
042: */
043: public void testTreeModelEventObjectTreePathIntArrayObjectArray() {
044: Object source = "111";
045: TreePath path = new TreePath("222");
046: int[] indices = new int[] { 1, 2 };
047: Object[] children = new Object[] { "1", "2", "3" };
048: event = new TreeModelEvent(source, path, indices, children);
049: assertEquals(source, event.getSource());
050: assertSame(path, event.path);
051: assertSame(indices, event.childIndices);
052: assertSame(children, event.children);
053: event = new TreeModelEvent(source, (TreePath) null, null, null);
054: assertEquals(source, event.getSource());
055: assertNull(event.path);
056: assertNull(event.childIndices);
057: assertNull(event.children);
058: }
059:
060: /*
061: * Test method for 'javax.swing.event.TreeModelEvent.TreeModelEvent(Object, Object[], int[], Object[])'
062: */
063: public void testTreeModelEventObjectObjectArrayIntArrayObjectArray() {
064: Object source = "111";
065: Object[] path = new Object[] { "11", "22", "33" };
066: int[] indices = new int[] { 1, 2 };
067: Object[] children = new Object[] { "1", "2", "3" };
068: event = new TreeModelEvent(source, path, indices, children);
069: assertEquals(source, event.getSource());
070: assertNotNull(event.path);
071: assertSame(indices, event.childIndices);
072: assertEquals(indices[0], event.getChildIndices()[0]);
073: assertEquals(indices[1], event.getChildIndices()[1]);
074: assertSame(children, event.children);
075: assertEquals(children[0], event.getChildren()[0]);
076: assertEquals(children[1], event.getChildren()[1]);
077: assertEquals(children[2], event.getChildren()[2]);
078: event = new TreeModelEvent(source, path, null, null);
079: assertEquals(source, event.getSource());
080: assertNotNull(event.path);
081: assertNull(event.childIndices);
082: assertNull(event.children);
083: event = new TreeModelEvent(source, (TreePath) null, null, null);
084: assertEquals(source, event.getSource());
085: assertNull(event.path);
086: assertNull(event.childIndices);
087: assertNull(event.children);
088: }
089:
090: /*
091: * Test method for 'javax.swing.event.TreeModelEvent.TreeModelEvent(Object, Object[])'
092: */
093: public void testTreeModelEventObjectObjectArray() {
094: Object source = "111";
095: Object[] path = new Object[] { "11", "22", "33" };
096: event = new TreeModelEvent(source, path);
097: assertEquals(source, event.getSource());
098: assertNotNull(event.path);
099: assertNotNull(event.childIndices);
100: assertEquals(0, event.childIndices.length);
101: assertNull(event.children);
102: }
103:
104: /*
105: * Test method for 'javax.swing.event.TreeModelEvent.TreeModelEvent(Object, TreePath)'
106: */
107: public void testTreeModelEventObjectTreePath() {
108: Object source = "111";
109: TreePath path = new TreePath("222");
110: event = new TreeModelEvent(source, path);
111: assertEquals(source, event.getSource());
112: assertSame(path, event.path);
113: assertNotNull(event.childIndices);
114: assertEquals(0, event.childIndices.length);
115: assertNull(event.children);
116: event = new TreeModelEvent(source, (TreePath) null);
117: assertEquals(source, event.getSource());
118: assertNull(event.path);
119: assertNotNull(event.childIndices);
120: assertEquals(0, event.childIndices.length);
121: assertNull(event.children);
122: }
123:
124: /*
125: * Test method for 'javax.swing.event.TreeModelEvent.getChildIndices()'
126: */
127: public void testGetChildIndices() {
128: Object source = "111";
129: TreePath path = new TreePath("222");
130: int[] indices1 = new int[] { 1, 2 };
131: int[] indices2 = new int[] { 11, 22 };
132: Object[] children = new Object[] { "1", "2", "3" };
133: event = new TreeModelEvent(source, path, indices1, children);
134: assertNotSame(indices1, event.getChildIndices());
135: assertTrue(Arrays.equals(indices1, event.getChildIndices()));
136: event.childIndices = indices2;
137: assertNotSame(indices2, event.getChildIndices());
138: assertTrue(Arrays.equals(indices2, event.getChildIndices()));
139: }
140:
141: /*
142: * Test method for 'javax.swing.event.TreeModelEvent.getChildren()'
143: */
144: public void testGetChildren() {
145: Object source = "111";
146: TreePath path = new TreePath("222");
147: int[] indices = new int[] { 1, 2 };
148: Object[] children1 = new Object[] { "1", "2", "3" };
149: Object[] children2 = new Object[] { "11", "22", "33" };
150: event = new TreeModelEvent(source, path, indices, children1);
151: assertNotSame(children1, event.getChildren());
152: assertTrue(Arrays.equals(children1, event.getChildren()));
153: event.children = children2;
154: assertNotSame(children2, event.getChildren());
155: assertTrue(Arrays.equals(children2, event.getChildren()));
156: }
157:
158: /*
159: * Test method for 'javax.swing.event.TreeModelEvent.getPath()'
160: */
161: public void testGetPath() {
162: Object source = "111";
163: Object[] array1 = new Object[] { "1", "2", "3" };
164: Object[] array2 = new Object[] { "11", "22", "33" };
165: TreePath path1 = new TreePath(array1);
166: Object[] path2 = array2;
167: TreePath path3 = new TreePath(array2);
168: event = new TreeModelEvent(source, path1);
169: assertNotSame(array1, event.getPath());
170: assertTrue(Arrays.equals(array1, event.getPath()));
171: event = new TreeModelEvent(source, path2);
172: assertNotSame(array2, event.getPath());
173: assertTrue(Arrays.equals(array2, event.getPath()));
174: event.path = path3;
175: assertNotSame(array2, event.getPath());
176: assertTrue(Arrays.equals(array2, event.getPath()));
177: event.path = null;
178: assertNull(event.getPath());
179: }
180:
181: /*
182: * Test method for 'javax.swing.event.TreeModelEvent.getTreePath()'
183: */
184: public void testGetTreePath() {
185: Object source = "111";
186: Object[] array1 = new Object[] { "1", "2", "3" };
187: Object[] array2 = new Object[] { "11", "22", "33" };
188: TreePath path1 = new TreePath(array1);
189: Object[] path2 = array2;
190: TreePath path3 = new TreePath(array2);
191: event = new TreeModelEvent(source, path1);
192: assertSame(path1, event.getTreePath());
193: event = new TreeModelEvent(source, path2);
194: assertTrue(Arrays.equals(array2, event.getTreePath().getPath()));
195: event.path = path3;
196: assertSame(path3, event.getTreePath());
197: event.path = null;
198: assertNull(event.getTreePath());
199: }
200:
201: /*
202: * Test method for 'javax.swing.event.TreeModelEvent.toString()'
203: */
204: public void testToString() {
205: Object source = "111";
206: TreePath path = new TreePath("222");
207: String str = new TreeModelEvent(source, path).toString();
208: assertNotNull(str);
209: assertFalse(str.equals(""));
210: }
211: }
|