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 javax.swing.SwingTestCase;
023: import javax.swing.tree.TreePath;
024:
025: public class TreeSelectionEventTest extends SwingTestCase {
026: protected TreeSelectionEvent event;
027:
028: /*
029: * Test method for 'javax.swing.event.TreeSelectionEvent.TreeSelectionEvent(Object, TreePath, boolean, TreePath, TreePath)'
030: */
031: public void testTreeSelectionEventObjectTreePathBooleanTreePathTreePath() {
032: TreePath path = new TreePath("asd");
033: TreePath oldSelection = new TreePath("old");
034: TreePath newSelection = new TreePath("new");
035: Object source = new Object();
036: boolean isNew = true;
037: event = new TreeSelectionEvent(source, path, isNew,
038: oldSelection, newSelection);
039: assertEquals(source, event.getSource());
040: assertEquals(path, event.getPath());
041: assertEquals(isNew, event.areNew[0]);
042: assertEquals(oldSelection, event.getOldLeadSelectionPath());
043: assertEquals(newSelection, event.getNewLeadSelectionPath());
044: }
045:
046: /*
047: * Test method for 'javax.swing.event.TreeSelectionEvent.TreeSelectionEvent(Object, TreePath[], boolean[], TreePath, TreePath)'
048: */
049: public void testTreeSelectionEventObjectTreePathArrayBooleanArrayTreePathTreePath() {
050: TreePath[] paths = new TreePath[] { new TreePath("asd"),
051: new TreePath("qwe"), new TreePath("zxc") };
052: boolean[] areNew = new boolean[] { true, false, true };
053: TreePath oldSelection = new TreePath("old");
054: TreePath newSelection = new TreePath("new");
055: Object source = new Object();
056: event = new TreeSelectionEvent(source, paths, areNew,
057: oldSelection, newSelection);
058: assertEquals(source, event.getSource());
059: assertEquals(paths[0], event.getPaths()[0]);
060: assertEquals(paths[1], event.getPaths()[1]);
061: assertEquals(paths[2], event.getPaths()[2]);
062: assertEquals(areNew[0], event.areNew[0]);
063: assertEquals(areNew[1], event.areNew[1]);
064: assertEquals(areNew[2], event.areNew[2]);
065: assertEquals(oldSelection, event.getOldLeadSelectionPath());
066: assertEquals(newSelection, event.getNewLeadSelectionPath());
067: }
068:
069: /*
070: * Test method for 'javax.swing.event.TreeSelectionEvent.cloneWithSource(Object)'
071: */
072: public void testCloneWithSource() {
073: TreePath[] paths = new TreePath[] { new TreePath("asd"),
074: new TreePath("qwe"), new TreePath("zxc") };
075: boolean[] areNew = new boolean[] { true, false, true };
076: TreePath oldSelection = new TreePath("old");
077: TreePath newSelection = new TreePath("new");
078: Object source = "source";
079: Object newSource = "newSource";
080: event = new TreeSelectionEvent(source, paths, areNew,
081: oldSelection, newSelection);
082: TreeSelectionEvent cloned = (TreeSelectionEvent) event
083: .cloneWithSource(newSource);
084: assertEquals(newSource, cloned.getSource());
085: assertEquals(paths[0], cloned.getPaths()[0]);
086: assertEquals(paths[1], cloned.getPaths()[1]);
087: assertEquals(paths[2], cloned.getPaths()[2]);
088: assertEquals(areNew[0], cloned.areNew[0]);
089: assertEquals(areNew[1], cloned.areNew[1]);
090: assertEquals(areNew[2], cloned.areNew[2]);
091: assertEquals(oldSelection, cloned.getOldLeadSelectionPath());
092: assertEquals(newSelection, cloned.getNewLeadSelectionPath());
093: }
094:
095: /*
096: * Test method for 'javax.swing.event.TreeSelectionEvent.getNewLeadSelectionPath()'
097: */
098: public void testGetNewLeadSelectionPath() {
099: TreePath[] paths = new TreePath[] { new TreePath("asd"),
100: new TreePath("qwe"), new TreePath("zxc") };
101: boolean[] areNew = new boolean[] { true, false, true };
102: TreePath oldSelection = new TreePath("old");
103: TreePath newSelection = new TreePath("new");
104: Object source = "source";
105: event = new TreeSelectionEvent(source, paths, areNew,
106: oldSelection, newSelection);
107: assertEquals(newSelection, event.getNewLeadSelectionPath());
108: }
109:
110: /*
111: * Test method for 'javax.swing.event.TreeSelectionEvent.getOldLeadSelectionPath()'
112: */
113: public void testGetOldLeadSelectionPath() {
114: TreePath[] paths = new TreePath[] { new TreePath("asd"),
115: new TreePath("qwe"), new TreePath("zxc") };
116: boolean[] areNew = new boolean[] { true, false, true };
117: TreePath oldSelection = new TreePath("old");
118: TreePath newSelection = new TreePath("new");
119: Object source = "source";
120: event = new TreeSelectionEvent(source, paths, areNew,
121: oldSelection, newSelection);
122: assertEquals(oldSelection, event.getOldLeadSelectionPath());
123: }
124:
125: /*
126: * Test method for 'javax.swing.event.TreeSelectionEvent.getPath()'
127: */
128: public void testGetPath() {
129: TreePath[] paths = new TreePath[] { new TreePath("asd"),
130: new TreePath("qwe"), new TreePath("zxc") };
131: boolean[] areNew = new boolean[] { true, false, true };
132: TreePath oldSelection = new TreePath("old");
133: TreePath newSelection = new TreePath("new");
134: Object source = new Object();
135: event = new TreeSelectionEvent(source, paths, areNew,
136: oldSelection, newSelection);
137: assertEquals(paths[0], event.getPath());
138: areNew = new boolean[] { false, false, true };
139: event = new TreeSelectionEvent(source, paths, areNew,
140: oldSelection, newSelection);
141: assertEquals(paths[0], event.getPath());
142: event = new TreeSelectionEvent(source, paths[0], true,
143: oldSelection, newSelection);
144: assertEquals(paths[0], event.getPath());
145: }
146:
147: /*
148: * Test method for 'javax.swing.event.TreeSelectionEvent.getPaths()'
149: */
150: public void testGetPaths() {
151: TreePath[] paths = new TreePath[] { new TreePath("asd"),
152: new TreePath("qwe"), new TreePath("zxc") };
153: boolean[] areNew = new boolean[] { true, false, true };
154: TreePath oldSelection = new TreePath("old");
155: TreePath newSelection = new TreePath("new");
156: Object source = new Object();
157: event = new TreeSelectionEvent(source, paths, areNew,
158: oldSelection, newSelection);
159: assertNotSame(paths, event.getPaths());
160: assertEquals(paths[0], event.getPaths()[0]);
161: assertEquals(paths[1], event.getPaths()[1]);
162: assertEquals(paths[2], event.getPaths()[2]);
163: }
164:
165: /*
166: * Test method for 'javax.swing.event.TreeSelectionEvent.isAddedPath(int)'
167: */
168: public void testIsAddedPathInt() {
169: TreePath path1 = new TreePath("asd");
170: TreePath path2 = new TreePath("dsa");
171: TreePath path3 = new TreePath("qwe");
172: TreePath oldSelection = new TreePath("old");
173: TreePath newSelection = new TreePath("new");
174: Object source = new Object();
175: event = new TreeSelectionEvent(source, path1, true,
176: oldSelection, newSelection);
177: assertTrue(event.isAddedPath(0));
178: event = new TreeSelectionEvent(source, path1, false,
179: oldSelection, newSelection);
180: assertFalse(event.isAddedPath(0));
181: event = new TreeSelectionEvent(source, path1, true,
182: oldSelection, newSelection);
183: testExceptionalCase(new IllegalArgumentCase() {
184: @Override
185: public void exceptionalAction() throws Exception {
186: event.isAddedPath(1);
187: }
188: });
189: TreePath[] paths = new TreePath[] { path1, path2, path3 };
190: boolean[] areNew = new boolean[] { true, false, true };
191: event = new TreeSelectionEvent(source, paths, areNew,
192: oldSelection, newSelection);
193: assertTrue(event.isAddedPath(0));
194: assertFalse(event.isAddedPath(1));
195: assertTrue(event.isAddedPath(2));
196: testExceptionalCase(new IllegalArgumentCase() {
197: @Override
198: public void exceptionalAction() throws Exception {
199: event.isAddedPath(3);
200: }
201: });
202: }
203:
204: /*
205: * Test method for 'javax.swing.event.TreeSelectionEvent.isAddedPath()'
206: */
207: public void testIsAddedPath() {
208: TreePath path1 = new TreePath("asd");
209: TreePath path2 = new TreePath("dsa");
210: TreePath path3 = new TreePath("qwe");
211: TreePath oldSelection = new TreePath("old");
212: TreePath newSelection = new TreePath("new");
213: Object source = new Object();
214: event = new TreeSelectionEvent(source, path1, true,
215: oldSelection, newSelection);
216: assertTrue(event.isAddedPath());
217: event = new TreeSelectionEvent(source, path1, false,
218: oldSelection, newSelection);
219: assertFalse(event.isAddedPath());
220: event = new TreeSelectionEvent(source, null, true, null, null);
221: assertTrue(event.isAddedPath());
222: event = new TreeSelectionEvent(source, null, false, null, null);
223: assertFalse(event.isAddedPath());
224: TreePath[] paths = new TreePath[] { path1, path2, path3 };
225: boolean[] areNew = new boolean[] { true, false, true };
226: event = new TreeSelectionEvent(source, paths, areNew,
227: oldSelection, newSelection);
228: assertTrue(event.isAddedPath());
229: areNew = new boolean[] { false, false, true };
230: event = new TreeSelectionEvent(source, paths, areNew,
231: oldSelection, newSelection);
232: assertFalse(event.isAddedPath());
233: }
234:
235: /*
236: * Test method for 'javax.swing.event.TreeSelectionEvent.isAddedPath(TreePath)'
237: */
238: public void testIsAddedPathTreePath() {
239: TreePath path1 = new TreePath("asd");
240: final TreePath path2 = new TreePath("dsa");
241: TreePath path3 = new TreePath("qwe");
242: final TreePath path4 = new TreePath("ewq");
243: TreePath oldSelection = new TreePath("old");
244: TreePath newSelection = new TreePath("new");
245: Object source = new Object();
246: event = new TreeSelectionEvent(source, path1, true,
247: oldSelection, newSelection);
248: assertTrue(event.isAddedPath(path1));
249: event = new TreeSelectionEvent(source, path1, false,
250: oldSelection, newSelection);
251: assertFalse(event.isAddedPath(path1));
252: event = new TreeSelectionEvent(source, path1, true,
253: oldSelection, newSelection);
254: testExceptionalCase(new IllegalArgumentCase() {
255: @Override
256: public void exceptionalAction() throws Exception {
257: event.isAddedPath(path2);
258: }
259: });
260: TreePath[] paths = new TreePath[] { path1, path2, path3 };
261: boolean[] areNew = new boolean[] { true, false, true };
262: event = new TreeSelectionEvent(source, paths, areNew,
263: oldSelection, newSelection);
264: assertTrue(event.isAddedPath(path1));
265: assertFalse(event.isAddedPath(path2));
266: assertTrue(event.isAddedPath(path3));
267: testExceptionalCase(new IllegalArgumentCase() {
268: @Override
269: public void exceptionalAction() throws Exception {
270: event.isAddedPath(path4);
271: }
272: });
273: event = new TreeSelectionEvent(source, null, null,
274: oldSelection, newSelection);
275: }
276: }
|