KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > jmi > javamodel > usages > FindClassUsagesTest


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.netbeans.jmi.javamodel.usages;
21
22 import java.util.Collection JavaDoc;
23 import junit.textui.TestRunner;
24 import org.netbeans.jmi.javamodel.JavaClass;
25 import org.netbeans.jmi.javamodel.codegen.Utility;
26 import org.netbeans.junit.NbTestCase;
27 import org.netbeans.junit.NbTestSuite;
28 import org.netbeans.modules.javacore.internalapi.JavaMetamodel;
29
30 /**
31  * @author Jan Becicka (jbecicka@netbeans.org)
32  */

33 public class FindClassUsagesTest extends NbTestCase {
34
35     public static final String JavaDoc[] USAGES_COLOR_PICKER = {"NewClassExpression"};
36     public static final String JavaDoc[] USAGES_COLOR_PREVIEW = {
37         "ClassExpression",
38         "ClassExpression",
39         "ClassExpression",
40         "ClassExpression",
41         "Field",
42         "NewClassExpression"};
43     public static final String JavaDoc[] USAGES_COLOR_PREVIEW_BEANINFO = {};
44     public static final String JavaDoc[] USAGES_IMAGE_FRAME = {"LocalVarDeclaration", "NewClassExpression"};
45     public static final String JavaDoc[] USAGES_IMAGE_VIEWER = {"NewClassExpression"};
46     public static final String JavaDoc[] USAGES_ABOUT = {"NewClassExpression"};
47     public static final String JavaDoc[] USAGES_FINDER = {"NewClassExpression"};
48     public static final String JavaDoc[] USAGES_TED = {"NewClassExpression"};
49     
50     /** Need to be defined because of JUnit */
51     public FindClassUsagesTest(String JavaDoc name) {
52         super(name);
53         
54     }
55     
56     public static NbTestSuite suite() {
57         NbTestSuite suite = new NbTestSuite();
58         suite.addTest(new FindClassUsagesTest("testFindColorPicker"));
59         suite.addTest(new FindClassUsagesTest("testFindColorPreview"));
60         suite.addTest(new FindClassUsagesTest("testFindColorPreviewBeanInfo"));
61         suite.addTest(new FindClassUsagesTest("testFindImageFrame"));
62         suite.addTest(new FindClassUsagesTest("testFindImageViewer"));
63         suite.addTest(new FindClassUsagesTest("testFindAbout"));
64         suite.addTest(new FindClassUsagesTest("testFindFinder"));
65         suite.addTest(new FindClassUsagesTest("testFindTed"));
66         return suite;
67     }
68     
69     /** Use for execution inside IDE */
70     public static void main(java.lang.String JavaDoc[] args) {
71         TestRunner.run(suite());
72     }
73     
74     public void testFindColorPicker() {
75         Collection JavaDoc result = getUsers("examples.colorpicker.ColorPicker");
76         compare(result, USAGES_COLOR_PICKER);
77     }
78
79     public void testFindColorPreview() {
80         Collection JavaDoc result = getUsers("examples.colorpicker.ColorPreview");
81         compare(result, USAGES_COLOR_PREVIEW);
82     }
83     
84     public void testFindColorPreviewBeanInfo() {
85         Collection JavaDoc result = getUsers("examples.colorpicker.ColorPreviewBeanInfo");
86         compare(result, USAGES_COLOR_PREVIEW_BEANINFO);
87     }
88     
89     public void testFindImageFrame() {
90         Collection JavaDoc result = getUsers("examples.imageviewer.ImageFrame");
91         compare(result, USAGES_IMAGE_FRAME);
92     }
93     
94     public void testFindImageViewer() {
95         Collection JavaDoc result = getUsers("examples.imageviewer.ImageViewer");
96         compare(result, USAGES_IMAGE_VIEWER);
97     }
98     
99     public void testFindAbout() {
100         Collection JavaDoc result = getUsers("examples.texteditor.About");
101         compare(result, USAGES_ABOUT);
102     }
103     
104     public void testFindFinder() {
105         Collection JavaDoc result = getUsers("examples.texteditor.Finder");
106         compare(result, USAGES_FINDER);
107     }
108     
109     public void testFindTed() {
110         Collection JavaDoc result = getUsers("examples.texteditor.Ted");
111         compare(result, USAGES_TED);
112     }
113     
114     private Collection JavaDoc getUsers(String JavaDoc className) {
115         JavaClass myclass = Utility.findClass(className);
116         assertNotNull(myclass);
117         return myclass.getReferences();
118     }
119     
120     private void compare(Collection JavaDoc col, String JavaDoc[] classNames) {
121         FindUtils.compare(col, classNames, getLog());
122     }
123 }
124
Popular Tags