KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > explorer > view > VisualizerSpeed95364Test


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.openide.explorer.view;
21
22 import javax.swing.JPanel JavaDoc;
23 import javax.swing.tree.TreeNode JavaDoc;
24 import org.netbeans.junit.NbTestCase;
25 import org.netbeans.junit.NbTestSuite;
26 import org.openide.explorer.ExplorerManager;
27 import org.openide.nodes.AbstractNode;
28 import org.openide.nodes.Children;
29 import org.openide.nodes.Node;
30
31 /**
32  * Tests for issue #95364.
33  */

34 public class VisualizerSpeed95364Test extends NbTestCase {
35     private int size;
36     private TreeNode JavaDoc toCheck;
37     
38     /**
39      *
40      * @param name
41      */

42     public VisualizerSpeed95364Test(String JavaDoc name) {
43         super(name);
44     }
45     
46     /**
47      *
48      * @return
49      */

50     public static NbTestSuite suite() {
51         return NbTestSuite.speedSuite(
52                 VisualizerSpeed95364Test.class, /* what tests to run */
53                 10 /* ten times slower */,
54                 3 /* try three times if it fails */
55                 );
56     }
57     
58     /**
59      *
60      */

61     protected void setUp() {
62         size = getTestNumber();
63         final MyKeys chK = new MyKeys();
64         final AbstractNode root = new AbstractNode(chK);
65         root.setName("test root");
66         
67         final String JavaDoc[] childrenNames = new String JavaDoc[size];
68         for (int i = 0; i < size; i++) {
69             childrenNames[i] = "test"+i;
70         };
71         chK.mySetKeys(childrenNames);
72         toCheck = Visualizer.findVisualizer(root);
73     }
74     
75     private void doTest() {
76         TreeNode JavaDoc tn = null;
77         for (int i = 0; i < 100000; i++) {
78             tn = toCheck.getChildAt(size/2);
79         }
80     }
81     
82     /**
83      *
84      */

85     public void test10() { doTest(); }
86     /**
87      *
88      */

89     public void test100() { doTest(); }
90     /**
91      *
92      */

93     public void test1000() { doTest(); }
94     
95     
96     private static Node JavaDoc createLeaf(String JavaDoc name) {
97         AbstractNode n = new AbstractNode(Children.LEAF);
98         n.setName(name);
99         return n;
100     }
101     
102     private static final class MyKeys extends Children.Keys {
103         protected Node JavaDoc[] createNodes(Object JavaDoc key) {
104             return new Node JavaDoc[] { createLeaf(key.toString())};
105         }
106         
107         public void mySetKeys(Object JavaDoc[] newKeys) {
108             super.setKeys(newKeys);
109         }
110     }
111 }
112
Popular Tags