Source Code Cross Referenced for DefaultTreeModelTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » tree » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » javax package » javax.swing.tree 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.tree;
021:
022:        import java.beans.PropertyChangeListener;
023:        import java.util.Arrays;
024:        import java.util.EventListener;
025:        import javax.swing.SwingTestCase;
026:        import javax.swing.event.TreeModelEvent;
027:        import javax.swing.event.TreeModelListener;
028:        import javax.swing.event.SwingPropertyChangeSupportTest.FindableListener;
029:
030:        public class DefaultTreeModelTest extends SwingTestCase {
031:            protected DefaultTreeModel model = null;
032:
033:            protected DefaultMutableTreeNode root = null;
034:
035:            class ConcreteTreeModelListener extends FindableListener implements 
036:                    TreeModelListener {
037:                public TreeModelEvent event = null;
038:
039:                public String type = null;
040:
041:                public boolean fired = false;
042:
043:                private final boolean debugOutput;
044:
045:                ConcreteTreeModelListener() {
046:                    super ();
047:                    debugOutput = false;
048:                }
049:
050:                ConcreteTreeModelListener(final boolean debugOutput) {
051:                    super ();
052:                    this .debugOutput = debugOutput;
053:                }
054:
055:                @Override
056:                public void reset() {
057:                    event = null;
058:                    type = null;
059:                    fired = false;
060:                }
061:
062:                public void treeNodesChanged(TreeModelEvent e) {
063:                    event = e;
064:                    fired = true;
065:                    type = "changed";
066:                    if (debugOutput) {
067:                        System.out.println("changed: " + e);
068:                    }
069:                }
070:
071:                public void treeNodesInserted(TreeModelEvent e) {
072:                    event = e;
073:                    fired = true;
074:                    type = "inserted";
075:                    if (debugOutput) {
076:                        System.out.println("inserted: " + e);
077:                    }
078:                }
079:
080:                public void treeNodesRemoved(TreeModelEvent e) {
081:                    event = e;
082:                    fired = true;
083:                    type = "removed";
084:                    if (debugOutput) {
085:                        System.out.println("removed: " + e);
086:                    }
087:                }
088:
089:                public void treeStructureChanged(TreeModelEvent e) {
090:                    event = e;
091:                    fired = true;
092:                    type = "structure";
093:                    if (debugOutput) {
094:                        System.out.println("structure changed: " + e);
095:                    }
096:                }
097:
098:                public void checkEvent(Object source, Object[] path,
099:                        int[] childIndices, Object[] children) {
100:                    assertNotNull("event", event);
101:                    assertEquals("source", source, event.getSource());
102:                    assertTrue("path", Arrays.equals(path, event.getPath()));
103:                    assertTrue("childIndices", Arrays.equals(childIndices,
104:                            event.getChildIndices()));
105:                    assertTrue("children", Arrays.equals(children, event
106:                            .getChildren()));
107:                }
108:            }
109:
110:            @Override
111:            protected void setUp() throws Exception {
112:                super .setUp();
113:                root = new DefaultMutableTreeNode("root");
114:                model = new DefaultTreeModel(root);
115:            }
116:
117:            @Override
118:            protected void tearDown() throws Exception {
119:                super .tearDown();
120:            }
121:
122:            /*
123:             * Test method for 'javax.swing.tree.DefaultTreeModel.DefaultTreeModel(TreeNode)'
124:             */
125:            public void testDefaultTreeModelTreeNode() {
126:                TreeNode node = new DefaultMutableTreeNode(null);
127:                model = new DefaultTreeModel(node);
128:                assertEquals(node, model.root);
129:                assertFalse(model.asksAllowsChildren);
130:                assertNotNull(model.listenerList);
131:                model = new DefaultTreeModel(null);
132:                assertNull(model.root);
133:                assertFalse(model.asksAllowsChildren);
134:                assertNotNull(model.listenerList);
135:            }
136:
137:            /*
138:             * Test method for 'javax.swing.tree.DefaultTreeModel.DefaultTreeModel(TreeNode, boolean)'
139:             */
140:            public void testDefaultTreeModelTreeNodeBoolean() {
141:                TreeNode node = new DefaultMutableTreeNode(null);
142:                model = new DefaultTreeModel(node, true);
143:                assertEquals(node, model.root);
144:                assertTrue(model.asksAllowsChildren);
145:                assertNotNull(model.listenerList);
146:                model = new DefaultTreeModel(null, false);
147:                assertNull(model.root);
148:                assertFalse(model.asksAllowsChildren);
149:                assertNotNull(model.listenerList);
150:            }
151:
152:            /*
153:             * Test method for 'javax.swing.tree.DefaultTreeModel.setAsksAllowsChildren(boolean)'
154:             */
155:            public void testSetAsksAllowsChildren() {
156:                TreeNode node = new DefaultMutableTreeNode(null);
157:                model = new DefaultTreeModel(node);
158:                model.setAsksAllowsChildren(true);
159:                assertTrue(model.asksAllowsChildren);
160:                model.setAsksAllowsChildren(false);
161:                assertFalse(model.asksAllowsChildren);
162:            }
163:
164:            /*
165:             * Test method for 'javax.swing.tree.DefaultTreeModel.asksAllowsChildren()'
166:             */
167:            public void testSetGetAsksAllowsChildren() {
168:                TreeNode node = new DefaultMutableTreeNode(null);
169:                model = new DefaultTreeModel(node);
170:                model.asksAllowsChildren = true;
171:                assertTrue(model.asksAllowsChildren());
172:                model.asksAllowsChildren = false;
173:                assertFalse(model.asksAllowsChildren());
174:            }
175:
176:            /*
177:             * Test method for 'javax.swing.tree.DefaultTreeModel.addTreeModelListener(TreeModelListener)'
178:             */
179:            public void testAddTreeModelListener() {
180:                ConcreteTreeModelListener listener1 = new ConcreteTreeModelListener();
181:                ConcreteTreeModelListener listener2 = new ConcreteTreeModelListener();
182:                TreeModelListener[] listenersArray = null;
183:                model.addTreeModelListener(listener1);
184:                listenersArray = model.getTreeModelListeners();
185:                assertTrue(listenersArray.length == 1);
186:                assertEquals(1, model.listenerList
187:                        .getListeners(TreeModelListener.class).length);
188:                assertEquals(1,
189:                        model.getListeners(TreeModelListener.class).length);
190:                assertTrue(listener1.findMe(listenersArray) > 0);
191:                model.addTreeModelListener(listener2);
192:                listenersArray = model.getTreeModelListeners();
193:                assertEquals(2, listenersArray.length);
194:                assertTrue(listener1.findMe(listenersArray) > 0);
195:                assertTrue(listener2.findMe(listenersArray) > 0);
196:                model.addTreeModelListener(listener2);
197:                listenersArray = model.getTreeModelListeners();
198:                assertEquals(3, listenersArray.length);
199:            }
200:
201:            /*
202:             * Test method for 'javax.swing.tree.DefaultTreeModel.removeTreeModelListener(TreeModelListener)'
203:             */
204:            public void testRemoveTreeModelListener() {
205:                ConcreteTreeModelListener changeListener1 = new ConcreteTreeModelListener();
206:                ConcreteTreeModelListener changeListener2 = new ConcreteTreeModelListener();
207:                ConcreteTreeModelListener changeListener3 = new ConcreteTreeModelListener();
208:                TreeModelListener[] listenersArray = null;
209:                model.addTreeModelListener(changeListener1);
210:                model.addTreeModelListener(changeListener2);
211:                model.addTreeModelListener(changeListener3);
212:                listenersArray = model.getTreeModelListeners();
213:                assertEquals(3, listenersArray.length);
214:                assertEquals(1, changeListener1.findMe(listenersArray));
215:                assertEquals(1, changeListener2.findMe(listenersArray));
216:                assertEquals(1, changeListener3.findMe(listenersArray));
217:                model.removeTreeModelListener(changeListener2);
218:                listenersArray = model.getTreeModelListeners();
219:                assertEquals(2, listenersArray.length);
220:                assertEquals(1, changeListener1.findMe(listenersArray));
221:                assertEquals(0, changeListener2.findMe(listenersArray));
222:                assertEquals(1, changeListener3.findMe(listenersArray));
223:                model.removeTreeModelListener(changeListener1);
224:                listenersArray = model.getTreeModelListeners();
225:                assertEquals(1, listenersArray.length);
226:                assertEquals(1, changeListener3.findMe(listenersArray));
227:                model.removeTreeModelListener(changeListener3);
228:                listenersArray = model.getTreeModelListeners();
229:                assertEquals(0, listenersArray.length);
230:            }
231:
232:            /*
233:             * Test method for 'javax.swing.tree.DefaultTreeModel.getTreeModelListeners()'
234:             */
235:            public void testGetTreeModelListeners() {
236:                ConcreteTreeModelListener changeListener1 = new ConcreteTreeModelListener();
237:                ConcreteTreeModelListener changeListener2 = new ConcreteTreeModelListener();
238:                ConcreteTreeModelListener changeListener3 = new ConcreteTreeModelListener();
239:                TreeModelListener[] listenersArray = null;
240:                listenersArray = model.getTreeModelListeners();
241:                assertTrue(listenersArray != null && listenersArray.length == 0);
242:                model.addTreeModelListener(changeListener1);
243:                model.addTreeModelListener(changeListener2);
244:                model.addTreeModelListener(changeListener3);
245:                model.addTreeModelListener(changeListener2);
246:                listenersArray = model.getTreeModelListeners();
247:                assertTrue(listenersArray.length == 4);
248:                assertTrue(changeListener1.findMe(listenersArray) == 1);
249:                assertTrue(changeListener2.findMe(listenersArray) == 2);
250:                assertTrue(changeListener3.findMe(listenersArray) == 1);
251:            }
252:
253:            /*
254:             * Test method for 'javax.swing.tree.DefaultTreeModel.getListeners(EventListener)'
255:             */
256:            public void testGetListeners() {
257:                TreeModelListener listener1 = new ConcreteTreeModelListener();
258:                TreeModelListener listener2 = new ConcreteTreeModelListener();
259:                EventListener[] listenersArray = null;
260:                listenersArray = model.getListeners(TreeModelListener.class);
261:                assertEquals(0, listenersArray.length);
262:                model.addTreeModelListener(listener1);
263:                model.addTreeModelListener(listener2);
264:                listenersArray = model
265:                        .getListeners(PropertyChangeListener.class);
266:                assertEquals(0, listenersArray.length);
267:                listenersArray = model.getListeners(TreeModelListener.class);
268:                assertEquals(2, listenersArray.length);
269:                model.removeTreeModelListener(listener1);
270:                listenersArray = model.getListeners(TreeModelListener.class);
271:                assertEquals(1, listenersArray.length);
272:                model.addTreeModelListener(listener2);
273:                listenersArray = model.getListeners(TreeModelListener.class);
274:                assertEquals(2, listenersArray.length);
275:            }
276:
277:            /*
278:             * Test method for 'javax.swing.tree.DefaultTreeModel.getChild(Object, int)'
279:             */
280:            public void testGetChild() {
281:                DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("1");
282:                DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("2");
283:                DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("3");
284:                DefaultMutableTreeNode node4 = new DefaultMutableTreeNode("4");
285:                DefaultMutableTreeNode node5 = new DefaultMutableTreeNode("5");
286:                node1.add(node2);
287:                node1.add(node5);
288:                node2.add(node3);
289:                node2.add(node4);
290:                assertEquals(node2, model.getChild(node1, 0));
291:                assertEquals(node5, model.getChild(node1, 1));
292:                assertEquals(node3, model.getChild(node2, 0));
293:                assertEquals(node4, model.getChild(node2, 1));
294:            }
295:
296:            /*
297:             * Test method for 'javax.swing.tree.DefaultTreeModel.getChildCount(Object)'
298:             */
299:            public void testGetChildCount() {
300:                DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("1");
301:                DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("2");
302:                DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("3");
303:                DefaultMutableTreeNode node4 = new DefaultMutableTreeNode("4");
304:                DefaultMutableTreeNode node5 = new DefaultMutableTreeNode("5");
305:                node1.add(node2);
306:                node1.add(node5);
307:                node2.add(node3);
308:                node2.add(node4);
309:                assertEquals(2, model.getChildCount(node1));
310:                assertEquals(2, model.getChildCount(node2));
311:                assertEquals(0, model.getChildCount(node3));
312:                assertEquals(0, model.getChildCount(node4));
313:                assertEquals(0, model.getChildCount(node5));
314:            }
315:
316:            /*
317:             * Test method for 'javax.swing.tree.DefaultTreeModel.getIndexOfChild(Object, Object)'
318:             */
319:            public void testGetIndexOfChild() {
320:                DefaultMutableTreeNode node1 = new DefaultMutableTreeNode(null);
321:                DefaultMutableTreeNode node2 = new DefaultMutableTreeNode(null);
322:                DefaultMutableTreeNode node3 = new DefaultMutableTreeNode(null);
323:                DefaultMutableTreeNode node4 = new DefaultMutableTreeNode(null);
324:                node1.add(node2);
325:                node1.add(node3);
326:                node3.add(node4);
327:                assertEquals(-1, model.getIndexOfChild(null, node1));
328:                assertEquals(-1, model.getIndexOfChild(node1, null));
329:                assertEquals(0, model.getIndexOfChild(node1, node2));
330:                assertEquals(1, model.getIndexOfChild(node1, node3));
331:                assertEquals(-1, model.getIndexOfChild(node1, node4));
332:                assertEquals(0, model.getIndexOfChild(node3, node4));
333:                assertEquals(-1, model.getIndexOfChild(node4, node3));
334:            }
335:
336:            /*
337:             * Test method for 'javax.swing.tree.DefaultTreeModel.setRoot(TreeNode)'
338:             */
339:            public void testSetRoot() {
340:                TreeNode root1 = new DefaultMutableTreeNode(null);
341:                TreeNode root2 = new DefaultMutableTreeNode(null);
342:                TreeNode root3 = null;
343:                ConcreteTreeModelListener listener = new ConcreteTreeModelListener(
344:                        false);
345:                model.addTreeModelListener(listener);
346:                model.setRoot(root1);
347:                assertEquals(root1, model.root);
348:                assertNotNull(listener.event);
349:                assertEquals("structure", listener.type);
350:                listener.checkEvent(model, new Object[] { root1 }, null, null);
351:                listener.reset();
352:                model.setRoot(root2);
353:                assertEquals(root2, model.root);
354:                assertNotNull(listener.event);
355:                assertEquals("structure", listener.type);
356:                listener.checkEvent(model, new Object[] { root2 }, null, null);
357:                listener.reset();
358:                model.setRoot(root2);
359:                assertEquals(root2, model.root);
360:                assertNotNull(listener.event);
361:                assertEquals("structure", listener.type);
362:                listener.checkEvent(model, new Object[] { root2 }, null, null);
363:                listener.reset();
364:                model.setRoot(root3);
365:                assertEquals(root3, model.root);
366:                assertNotNull(listener.event);
367:                assertEquals("structure", listener.type);
368:                listener.checkEvent(model, null, new int[0], null);
369:                listener.reset();
370:            }
371:
372:            /*
373:             * Test method for 'javax.swing.tree.DefaultTreeModel.getRoot()'
374:             */
375:            public void testGetRoot() {
376:                TreeNode root1 = new DefaultMutableTreeNode(null);
377:                TreeNode root2 = new DefaultMutableTreeNode(null);
378:                TreeNode root3 = null;
379:                model.root = root1;
380:                assertEquals(root1, model.getRoot());
381:                model.root = root2;
382:                assertEquals(root2, model.getRoot());
383:                model.root = root3;
384:                assertEquals(root3, model.getRoot());
385:            }
386:
387:            /*
388:             * Test method for 'javax.swing.tree.DefaultTreeModel.isLeaf(Object)'
389:             */
390:            public void testIsLeaf() {
391:                DefaultMutableTreeNode node1 = new DefaultMutableTreeNode(null,
392:                        true);
393:                DefaultMutableTreeNode node2 = new DefaultMutableTreeNode(null,
394:                        false);
395:                DefaultMutableTreeNode node3 = new DefaultMutableTreeNode(null);
396:                model.setAsksAllowsChildren(true);
397:                assertFalse(model.isLeaf(node1));
398:                assertTrue(model.isLeaf(node2));
399:                model.setAsksAllowsChildren(false);
400:                assertTrue(model.isLeaf(node1));
401:                assertTrue(model.isLeaf(node2));
402:                node1.add(node3);
403:                model.setAsksAllowsChildren(true);
404:                assertFalse(model.isLeaf(node1));
405:                model.setAsksAllowsChildren(false);
406:                assertFalse(model.isLeaf(node1));
407:            }
408:
409:            /*
410:             * Test method for 'javax.swing.tree.DefaultTreeModel.valueForPathChanged(TreePath, Object)'
411:             */
412:            public void testValueForPathChanged() {
413:                DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("1");
414:                DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("2");
415:                DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("3");
416:                DefaultMutableTreeNode node4 = new DefaultMutableTreeNode("4");
417:                DefaultMutableTreeNode node5 = new DefaultMutableTreeNode("5");
418:                node1.add(node2);
419:                node1.add(node5);
420:                node2.add(node3);
421:                node2.add(node4);
422:                model.valueForPathChanged(new TreePath(node1), "11");
423:                assertEquals("11", node1.getUserObject());
424:                model.valueForPathChanged(new TreePath(new Object[] { node1,
425:                        node2 }), "22");
426:                assertEquals("22", node2.getUserObject());
427:                assertEquals("11", node1.getUserObject());
428:                model.valueForPathChanged(new TreePath(new Object[] { node2 }),
429:                        "222");
430:                assertEquals("222", node2.getUserObject());
431:                assertEquals("11", node1.getUserObject());
432:                model.valueForPathChanged(new TreePath(new Object[] { node2,
433:                        node4 }), "222444");
434:                assertEquals("222", node2.getUserObject());
435:                assertEquals("222444", node4.getUserObject());
436:            }
437:
438:            /*
439:             * Test method for 'javax.swing.tree.DefaultTreeModel.reload()'
440:             */
441:            public void testReload() {
442:                DefaultMutableTreeNode node1 = root;
443:                DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("2");
444:                DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("3");
445:                DefaultMutableTreeNode node4 = new DefaultMutableTreeNode("4");
446:                DefaultMutableTreeNode node5 = new DefaultMutableTreeNode("5");
447:                node1.add(node2);
448:                node1.add(node5);
449:                node2.add(node3);
450:                node2.add(node4);
451:                ConcreteTreeModelListener listener = new ConcreteTreeModelListener();
452:                model.addTreeModelListener(listener);
453:                model.setRoot(null);
454:                model.reload();
455:                assertNotNull(listener.event);
456:                assertEquals("structure", listener.type);
457:                listener.checkEvent(model, null, new int[0], null);
458:                listener.reset();
459:                model.setRoot(root);
460:                model.reload();
461:                assertNotNull(listener.event);
462:                listener.checkEvent(model, new Object[] { root }, null, null);
463:                listener.reset();
464:            }
465:
466:            /*
467:             * Test method for 'javax.swing.tree.DefaultTreeModel.reload(TreeNode)'
468:             */
469:            public void testReloadTreeNode() {
470:                DefaultMutableTreeNode node1 = root;
471:                DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("2");
472:                DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("3");
473:                DefaultMutableTreeNode node4 = new DefaultMutableTreeNode("4");
474:                DefaultMutableTreeNode node5 = new DefaultMutableTreeNode("5");
475:                node1.add(node2);
476:                node1.add(node5);
477:                node2.add(node3);
478:                node2.add(node4);
479:                ConcreteTreeModelListener listener = new ConcreteTreeModelListener();
480:                model.addTreeModelListener(listener);
481:                model.reload(null);
482:                assertNull(listener.event);
483:                model.setRoot(null);
484:                model.reload(null);
485:                assertNotNull(listener.event);
486:                assertEquals("structure", listener.type);
487:                listener.checkEvent(model, null, new int[0], null);
488:                listener.reset();
489:                model.setRoot(root);
490:                model.reload(root);
491:                assertNotNull(listener.event);
492:                listener.checkEvent(model, new Object[] { root }, null, null);
493:                listener.reset();
494:                model.reload(node2);
495:                assertNotNull(listener.event);
496:                listener.checkEvent(model, new Object[] { root, node2 }, null,
497:                        null);
498:                listener.reset();
499:                model.reload(node4);
500:                assertNotNull(listener.event);
501:                listener.checkEvent(model, new Object[] { root, node2, node4 },
502:                        null, null);
503:                listener.reset();
504:            }
505:
506:            /*
507:             * Test method for 'javax.swing.tree.DefaultTreeModel.insertNodeInto(MutableTreeNode, MutableTreeNode, int)'
508:             */
509:            public void testInsertNodeInto() {
510:                DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("1");
511:                DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("2");
512:                DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("3");
513:                ConcreteTreeModelListener listener = new ConcreteTreeModelListener();
514:                model.addTreeModelListener(listener);
515:                try {
516:                    model.insertNodeInto(null, node1, 0);
517:                    fail("no exception's been thrown");
518:                } catch (IllegalArgumentException e) {
519:                }
520:                model.insertNodeInto(node1, node2, 0);
521:                assertNotNull(listener.event);
522:                listener.checkEvent(model, new Object[] { node2 },
523:                        new int[] { 0 }, new Object[] { node1 });
524:                assertEquals(node1, node2.getChildAt(0));
525:                listener.reset();
526:                model.insertNodeInto(node3, node2, 0);
527:                listener.checkEvent(model, new Object[] { node2 },
528:                        new int[] { 0 }, new Object[] { node3 });
529:                assertEquals(node3, node2.getChildAt(0));
530:                assertEquals(node1, node2.getChildAt(1));
531:            }
532:
533:            /*
534:             * Test method for 'javax.swing.tree.DefaultTreeModel.removeNodeFromParent(MutableTreeNode)'
535:             */
536:            public void testRemoveNodeFromParent() {
537:                DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("1");
538:                DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("2");
539:                DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("3");
540:                node1.add(node2);
541:                node1.add(node3);
542:                ConcreteTreeModelListener listener = new ConcreteTreeModelListener();
543:                model.addTreeModelListener(listener);
544:                try {
545:                    model.removeNodeFromParent(node1);
546:                    fail("no exception's been thrown");
547:                } catch (IllegalArgumentException e) {
548:                }
549:                model.removeNodeFromParent(node3);
550:                assertNotNull(listener.event);
551:                listener.checkEvent(model, new Object[] { node1 },
552:                        new int[] { 1 }, new Object[] { node3 });
553:                assertEquals(1, node1.getChildCount());
554:                listener.reset();
555:                model.removeNodeFromParent(node2);
556:                assertNotNull(listener.event);
557:                listener.checkEvent(model, new Object[] { node1 },
558:                        new int[] { 0 }, new Object[] { node2 });
559:                assertEquals(0, node1.getChildCount());
560:                listener.reset();
561:            }
562:
563:            /*
564:             * Test method for 'javax.swing.tree.DefaultTreeModel.nodeChanged(TreeNode)'
565:             */
566:            public void testNodeChanged() {
567:                DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("1");
568:                DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("2");
569:                DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("3");
570:                DefaultMutableTreeNode node4 = new DefaultMutableTreeNode("4");
571:                DefaultMutableTreeNode node5 = new DefaultMutableTreeNode("4");
572:                node1.add(node2);
573:                node1.add(node5);
574:                node2.add(node3);
575:                node2.add(node4);
576:                ConcreteTreeModelListener listener = new ConcreteTreeModelListener();
577:                model.addTreeModelListener(listener);
578:                model.nodeChanged(null);
579:                assertNull(listener.event);
580:                model.nodeChanged(node1);
581:                assertNull(listener.event);
582:                model.nodeChanged(root);
583:                assertNotNull(listener.event);
584:                assertEquals("changed", listener.type);
585:                listener.checkEvent(model, new Object[] { root }, null, null);
586:                listener.reset();
587:                model.nodeChanged(node2);
588:                assertNotNull(listener.event);
589:                assertEquals("changed", listener.type);
590:                listener.checkEvent(model, new Object[] { node1 },
591:                        new int[] { 0 }, new Object[] { node2 });
592:                listener.reset();
593:                model.nodeChanged(node3);
594:                assertNotNull(listener.event);
595:                assertEquals("changed", listener.type);
596:                listener.checkEvent(model, new Object[] { node1, node2 },
597:                        new int[] { 0 }, new Object[] { node3 });
598:                listener.reset();
599:                model.nodeChanged(node4);
600:                assertNotNull(listener.event);
601:                assertEquals("changed", listener.type);
602:                listener.checkEvent(model, new Object[] { node1, node2 },
603:                        new int[] { 1 }, new Object[] { node4 });
604:                listener.reset();
605:            }
606:
607:            /*
608:             * Test method for 'javax.swing.tree.DefaultTreeModel.nodesWereInserted(TreeNode, int[])'
609:             */
610:            public void testNodesWereInserted() {
611:                DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("1");
612:                DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("2");
613:                DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("3");
614:                DefaultMutableTreeNode node4 = new DefaultMutableTreeNode("4");
615:                DefaultMutableTreeNode node5 = new DefaultMutableTreeNode("5");
616:                node1.add(node2);
617:                node1.add(node5);
618:                node2.add(node3);
619:                node2.add(node4);
620:                ConcreteTreeModelListener listener = new ConcreteTreeModelListener();
621:                model.addTreeModelListener(listener);
622:                model.nodesWereInserted(null, null);
623:                assertNull(listener.event);
624:                model.nodesWereInserted(node1, null);
625:                assertNull(listener.event);
626:                model.nodesWereInserted(node1, new int[0]);
627:                assertNull(listener.event);
628:                model.nodesWereInserted(node1, new int[] { 1, 0 });
629:                assertNotNull(listener.event);
630:                assertEquals("inserted", listener.type);
631:                listener.checkEvent(model, new Object[] { node1 }, new int[] {
632:                        1, 0 }, new Object[] { node5, node2 });
633:                listener.reset();
634:                model.nodesWereInserted(node2, new int[] { 0, 1 });
635:                assertNotNull(listener.event);
636:                assertEquals("inserted", listener.type);
637:                listener.checkEvent(model, new Object[] { node1, node2 },
638:                        new int[] { 0, 1 }, new Object[] { node3, node4 });
639:                listener.reset();
640:            }
641:
642:            /*
643:             * Test method for 'javax.swing.tree.DefaultTreeModel.nodesWereRemoved(TreeNode, int[], Object[])'
644:             */
645:            public void testNodesWereRemoved() {
646:                DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("1");
647:                DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("2");
648:                DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("3");
649:                DefaultMutableTreeNode node4 = new DefaultMutableTreeNode("4");
650:                DefaultMutableTreeNode node5 = new DefaultMutableTreeNode("5");
651:                node1.add(node2);
652:                node1.add(node5);
653:                node2.add(node3);
654:                node2.add(node4);
655:                ConcreteTreeModelListener listener = new ConcreteTreeModelListener();
656:                model.addTreeModelListener(listener);
657:                model.nodesWereRemoved(null, null, null);
658:                assertNull(listener.event);
659:                model.nodesWereRemoved(node1, null, null);
660:                assertNull(listener.event);
661:                model.nodesWereRemoved(node1, new int[] { 1, 0 }, new Object[] {
662:                        node3, node4 });
663:                assertNotNull(listener.event);
664:                assertEquals("removed", listener.type);
665:                listener.checkEvent(model, new Object[] { node1 }, new int[] {
666:                        1, 0 }, new Object[] { node3, node4 });
667:                listener.reset();
668:                model.nodesWereRemoved(node4, new int[] { 1 }, new Object[] {
669:                        node3, node5 });
670:                assertNotNull(listener.event);
671:                assertEquals("removed", listener.type);
672:                listener.checkEvent(model,
673:                        new Object[] { node1, node2, node4 }, new int[] { 1 },
674:                        new Object[] { node3, node5 });
675:                listener.reset();
676:            }
677:
678:            /*
679:             * Test method for 'javax.swing.tree.DefaultTreeModel.nodesChanged(TreeNode, int[])'
680:             */
681:            public void testNodesChanged() {
682:                DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("1");
683:                DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("2");
684:                DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("3");
685:                DefaultMutableTreeNode node4 = new DefaultMutableTreeNode("4");
686:                DefaultMutableTreeNode node5 = new DefaultMutableTreeNode("5");
687:                DefaultMutableTreeNode node6 = new DefaultMutableTreeNode("6");
688:                node1.add(node2);
689:                node1.add(node5);
690:                node2.add(node3);
691:                node2.add(node4);
692:                root.add(node6);
693:                ConcreteTreeModelListener listener = new ConcreteTreeModelListener();
694:                model.addTreeModelListener(listener);
695:                model.nodesChanged(null, null);
696:                assertNull(listener.event);
697:                model.nodesChanged(node1, null);
698:                assertNull(listener.event);
699:                model.nodesChanged(root, null);
700:                assertNotNull(listener.event);
701:                assertEquals("changed", listener.type);
702:                listener.checkEvent(model, new Object[] { root }, null, null);
703:                listener.reset();
704:                model.nodesChanged(root, new int[] { 0 });
705:                assertNotNull(listener.event);
706:                assertEquals("changed", listener.type);
707:                listener.checkEvent(model, new Object[] { root },
708:                        new int[] { 0 }, new Object[] { node6 });
709:                listener.reset();
710:                model.nodesChanged(node1, new int[0]);
711:                assertNull(listener.event);
712:                model.nodesChanged(null, new int[] { 1 });
713:                assertNull(listener.event);
714:                model.nodesChanged(node2, new int[] { 1 });
715:                assertNotNull(listener.event);
716:                assertEquals("changed", listener.type);
717:                listener.checkEvent(model, new Object[] { node1, node2 },
718:                        new int[] { 1 }, new Object[] { node4 });
719:                listener.reset();
720:                model.nodesChanged(node1, new int[] { 0 });
721:                assertNotNull(listener.event);
722:                assertEquals("changed", listener.type);
723:                listener.checkEvent(model, new Object[] { node1 },
724:                        new int[] { 0 }, new Object[] { node2 });
725:                listener.reset();
726:                model.nodesChanged(node1, new int[] { 0, 1 });
727:                assertNotNull(listener.event);
728:                assertEquals("changed", listener.type);
729:                listener.checkEvent(model, new Object[] { node1 }, new int[] {
730:                        0, 1 }, new Object[] { node2, node5 });
731:                listener.reset();
732:            }
733:
734:            /*
735:             * Test method for 'javax.swing.tree.DefaultTreeModel.nodeStructureChanged(TreeNode)'
736:             */
737:            public void testNodeStructureChanged() {
738:                DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("1");
739:                DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("2");
740:                DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("3");
741:                DefaultMutableTreeNode node4 = new DefaultMutableTreeNode("4");
742:                DefaultMutableTreeNode node5 = new DefaultMutableTreeNode("5");
743:                node1.add(node2);
744:                node1.add(node5);
745:                node2.add(node3);
746:                node2.add(node4);
747:                ConcreteTreeModelListener listener = new ConcreteTreeModelListener();
748:                model.addTreeModelListener(listener);
749:                model.nodeStructureChanged(null);
750:                assertNull(listener.event);
751:                model.setRoot(null);
752:                listener.reset();
753:                model.nodeStructureChanged(null);
754:                assertNull(listener.event);
755:                model.nodeStructureChanged(node1);
756:                assertNotNull(listener.event);
757:                assertEquals("structure", listener.type);
758:                listener.checkEvent(model, new Object[] { node1 }, null, null);
759:                listener.reset();
760:                model.nodeStructureChanged(node2);
761:                assertNotNull(listener.event);
762:                listener.checkEvent(model, new Object[] { node1, node2 }, null,
763:                        null);
764:                listener.reset();
765:                model.nodeStructureChanged(node4);
766:                assertNotNull(listener.event);
767:                listener.checkEvent(model,
768:                        new Object[] { node1, node2, node4 }, null, null);
769:                listener.reset();
770:            }
771:
772:            /*
773:             * Test method for 'javax.swing.tree.DefaultTreeModel.getPathToRoot(TreeNode)'
774:             */
775:            public void testGetPathToRootTreeNode() {
776:                DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("1");
777:                DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("2");
778:                DefaultMutableTreeNode node3 = root;
779:                DefaultMutableTreeNode node4 = new DefaultMutableTreeNode("4");
780:                node1.add(node2);
781:                node2.add(node3);
782:                node3.add(node4);
783:                if (isHarmony()) {
784:                    assertEquals(0, model.getPathToRoot(null).length);
785:                } else {
786:                    assertNull(model.getPathToRoot(null));
787:                }
788:                assertTrue(Arrays.equals(new TreeNode[] { node1 }, model
789:                        .getPathToRoot(node1)));
790:                assertTrue(Arrays.equals(new TreeNode[] { node1, node2 }, model
791:                        .getPathToRoot(node2)));
792:                assertTrue(Arrays.equals(new TreeNode[] { node3 }, model
793:                        .getPathToRoot(node3)));
794:                assertTrue(Arrays.equals(new TreeNode[] { node3, node4 }, model
795:                        .getPathToRoot(node4)));
796:            }
797:
798:            /*
799:             * Test method for 'javax.swing.tree.DefaultTreeModel.fireTreeNodesChanged(Object, Object[], int[], Object[])'
800:             */
801:            public void testFireTreeNodesChanged() {
802:                Object source1 = "source1";
803:                Object[] paths1 = new Object[] { "1", "2" };
804:                int[] indices1 = new int[] { 100, 200 };
805:                Object[] children1 = new Object[] { "10", "20" };
806:                ConcreteTreeModelListener listener1 = new ConcreteTreeModelListener();
807:                ConcreteTreeModelListener listener2 = new ConcreteTreeModelListener();
808:                model.addTreeModelListener(listener1);
809:                model.addTreeModelListener(listener2);
810:                model
811:                        .fireTreeNodesChanged(source1, paths1, indices1,
812:                                children1);
813:                assertNotNull(listener1.event);
814:                assertNotNull(listener2.event);
815:                assertEquals("changed", listener1.type);
816:                assertEquals("changed", listener2.type);
817:                listener1.checkEvent(source1, paths1, indices1, children1);
818:                listener2.checkEvent(source1, paths1, indices1, children1);
819:            }
820:
821:            /*
822:             * Test method for 'javax.swing.tree.DefaultTreeModel.fireTreeNodesInserted(Object, Object[], int[], Object[])'
823:             */
824:            public void testFireTreeNodesInserted() {
825:                Object source1 = "source1";
826:                Object[] paths1 = new Object[] { "1", "2" };
827:                int[] indices1 = new int[] { 100, 200 };
828:                Object[] children1 = new Object[] { "10", "20" };
829:                ConcreteTreeModelListener listener1 = new ConcreteTreeModelListener();
830:                ConcreteTreeModelListener listener2 = new ConcreteTreeModelListener();
831:                model.addTreeModelListener(listener1);
832:                model.addTreeModelListener(listener2);
833:                model.fireTreeNodesInserted(source1, paths1, indices1,
834:                        children1);
835:                assertNotNull(listener1.event);
836:                assertNotNull(listener2.event);
837:                assertEquals("inserted", listener1.type);
838:                assertEquals("inserted", listener2.type);
839:                listener1.checkEvent(source1, paths1, indices1, children1);
840:                listener2.checkEvent(source1, paths1, indices1, children1);
841:            }
842:
843:            /*
844:             * Test method for 'javax.swing.tree.DefaultTreeModel.fireTreeNodesRemoved(Object, Object[], int[], Object[])'
845:             */
846:            public void testFireTreeNodesRemoved() {
847:                Object source1 = "source1";
848:                Object[] paths1 = new Object[] { "1", "2" };
849:                int[] indices1 = new int[] { 100, 200 };
850:                Object[] children1 = new Object[] { "10", "20" };
851:                ConcreteTreeModelListener listener1 = new ConcreteTreeModelListener();
852:                ConcreteTreeModelListener listener2 = new ConcreteTreeModelListener();
853:                model.addTreeModelListener(listener1);
854:                model.addTreeModelListener(listener2);
855:                model
856:                        .fireTreeNodesRemoved(source1, paths1, indices1,
857:                                children1);
858:                assertNotNull(listener1.event);
859:                assertNotNull(listener2.event);
860:                assertEquals("removed", listener1.type);
861:                assertEquals("removed", listener2.type);
862:                listener1.checkEvent(source1, paths1, indices1, children1);
863:                listener2.checkEvent(source1, paths1, indices1, children1);
864:            }
865:
866:            /*
867:             * Test method for 'javax.swing.tree.DefaultTreeModel.fireTreeStructureChanged(Object, Object[], int[], Object[])'
868:             */
869:            public void testFireTreeStructureChanged() {
870:                Object source1 = "source1";
871:                Object[] paths1 = new Object[] { "1", "2" };
872:                int[] indices1 = new int[] { 100, 200 };
873:                Object[] children1 = new Object[] { "10", "20" };
874:                ConcreteTreeModelListener listener1 = new ConcreteTreeModelListener();
875:                ConcreteTreeModelListener listener2 = new ConcreteTreeModelListener();
876:                model.addTreeModelListener(listener1);
877:                model.addTreeModelListener(listener2);
878:                model.fireTreeStructureChanged(source1, paths1, indices1,
879:                        children1);
880:                assertNotNull(listener1.event);
881:                assertNotNull(listener2.event);
882:                assertEquals("structure", listener1.type);
883:                assertEquals("structure", listener2.type);
884:                listener1.checkEvent(source1, paths1, indices1, children1);
885:                listener2.checkEvent(source1, paths1, indices1, children1);
886:            }
887:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.