KickJava   Java API By Example, From Geeks To Geeks.

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


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.JavaPackage;
25 import org.netbeans.junit.NbTestCase;
26 import org.netbeans.junit.NbTestSuite;
27 import org.netbeans.modules.javacore.internalapi.JavaMetamodel;
28
29 /**
30  * @author Jan Becicka (jbecicka@netbeans.org)
31  */

32 public class FindPackageUsagesTest extends NbTestCase {
33
34     public static final String JavaDoc[] USAGES_COLOR_PICKER = {
35         "MultipartId",
36         "MultipartId",
37         "Resource",
38         "Resource",
39         "Resource"
40     };
41     
42     public static final String JavaDoc[] USAGES_IMAGE_VIEWER = {
43         "Resource",
44         "Resource"
45     };
46         
47     public static final String JavaDoc[] USAGES_TEXT_EDITOR = {
48         "Resource",
49         "Resource",
50         "Resource"
51     };
52         
53     public static final String JavaDoc[] USAGES_EXAMPLES = {
54         "MultipartId",
55         "MultipartId",
56         "MultipartId",
57         "MultipartId",
58         "MultipartId",
59         "MultipartId",
60         "MultipartId",
61         "MultipartId",
62         "MultipartId",
63         "MultipartId"
64     };
65     
66     /** Need to be defined because of JUnit */
67     public FindPackageUsagesTest(String JavaDoc name) {
68         super(name);
69         
70     }
71     
72     public static NbTestSuite suite() {
73         NbTestSuite suite = new NbTestSuite();
74         suite.addTest(new FindPackageUsagesTest("testFindExamplesColorPicker"));
75         suite.addTest(new FindPackageUsagesTest("testFindExamplesImageViewer"));
76         suite.addTest(new FindPackageUsagesTest("testFindExamplesTextEditor"));
77         suite.addTest(new FindPackageUsagesTest("testFindExamples"));
78         return suite;
79     }
80     
81     /** Use for execution inside IDE */
82     public static void main(java.lang.String JavaDoc[] args) {
83         TestRunner.run(suite());
84     }
85     
86     public void testFindExamplesColorPicker() {
87         Collection JavaDoc result = getUsers("examples.colorpicker");
88         compare(result, USAGES_COLOR_PICKER);
89     }
90
91     public void testFindExamplesImageViewer() {
92         Collection JavaDoc result = getUsers("examples.imageviewer");
93         compare(result, USAGES_IMAGE_VIEWER);
94     }
95     
96     public void testFindExamplesTextEditor() {
97         Collection JavaDoc result = getUsers("examples.texteditor");
98         compare(result, USAGES_TEXT_EDITOR);
99     }
100     
101     public void testFindExamples() {
102         Collection JavaDoc result = getUsers("examples");
103         compare(result, USAGES_EXAMPLES);
104     }
105     
106     private Collection JavaDoc getUsers(String JavaDoc className) {
107         JavaPackage pckg = (JavaPackage) JavaMetamodel.getManager().getDefaultExtent().getJavaPackage().resolvePackage(className);
108         assertNotNull(pckg);
109         return pckg.getReferences();
110     }
111     
112     private void compare(Collection JavaDoc col, String JavaDoc[] classNames) {
113         FindUtils.compare(col, classNames, getLog());
114     }
115 }
116
Popular Tags