KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > jmi > javamodel > FeaturesTest


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 package org.netbeans.jmi.javamodel;
20
21 import java.util.HashMap JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import junit.textui.TestRunner;
24 import org.netbeans.junit.NbTestCase;
25 import org.netbeans.junit.NbTestSuite;
26
27
28 public class FeaturesTest extends NbTestCase {
29
30     /** Need to be defined because of JUnit */
31     public FeaturesTest(String JavaDoc name) {
32         super(name);
33
34     }
35
36     public static NbTestSuite suite() {
37         NbTestSuite suite = new NbTestSuite();
38         suite.addTest(new FeaturesTest("testAllFeatures"));
39         return suite;
40     }
41     
42     /** Use for execution inside IDE */
43     public static void main(java.lang.String JavaDoc[] args) {
44         TestRunner.run(suite());
45     }
46
47     String JavaDoc cbn;
48     HashMap JavaDoc classes;
49     int numOfFeaturesInClasses;
50     
51     protected void setUp() {
52 // ResourceImpl.READ_ONLY = true;
53

54         cbn = "testsrc";
55         
56         classes = new HashMap JavaDoc();
57         classes.put("junit.framework.Assert", new Integer JavaDoc(39));
58         classes.put("junit.framework.AssertionFailedError", new Integer JavaDoc(2));
59         classes.put("junit.framework.ComparisonFailure", new Integer JavaDoc(4));
60         classes.put("junit.framework.Protectable", new Integer JavaDoc(1));
61         classes.put("junit.framework.Test", new Integer JavaDoc(2));
62         classes.put("junit.framework.TestCase", new Integer JavaDoc(14));
63         classes.put("junit.framework.TestFailure", new Integer JavaDoc(9));
64         classes.put("junit.framework.TestListener", new Integer JavaDoc(4));
65         classes.put("junit.framework.TestResult", new Integer JavaDoc(23));
66         classes.put("junit.framework.TestSuite", new Integer JavaDoc(24));
67         
68         numOfFeaturesInClasses = classes.size();
69         for (Iterator JavaDoc it = classes.values().iterator(); it.hasNext(); ) {
70             numOfFeaturesInClasses += ((Integer JavaDoc)it.next()).intValue();
71         }
72     }
73     
74     
75     public void testAllFeatures() {/*
76         Utility.beginTrans(false);
77         try {
78             JavaModelPackage pkg = Utility.getJavaModelPackage(cbn);
79             HashMap featuresInClasses = new HashMap();
80             for (Iterator it = classes.keySet().iterator(); it.hasNext(); ) {
81                 String className = (String) it.next();
82                 JavaClass javaClass = (JavaClass) pkg.getType().resolve(className);
83                 assertNotNull(className+" class instance", javaClass);
84                 featuresInClasses.put(javaClass, new Integer(0));
85             }
86             
87             Collection features = pkg.getFeature().refAllOfType();
88             int numOfFeatures = 0;
89             int numOfFeaturesWithoutDeclaringClass = 0;
90             for (Iterator it = features.iterator(); it.hasNext(); ) {
91                 ++numOfFeatures;
92                 FeatureImpl feature = (FeatureImpl) it.next();
93                 
94                 JavaClass javaClass = (JavaClass) feature.getDeclaringClass();
95                 if (javaClass == null) {
96                     ++numOfFeaturesWithoutDeclaringClass;
97                     continue;
98                 }
99                 
100                 Integer n = (Integer) featuresInClasses.get(javaClass);
101                 if (n != null) {
102                     featuresInClasses.put(javaClass, new Integer(n.intValue()+1));
103                 }
104             }
105             
106             //assertEquals("Total number of features", numOfFeaturesInClasses, numOfFeatures);
107             System.out.println("Total number of features: "+numOfFeatures);
108             //assertEquals("Total number of features without declaring class: ", classes.size(), numOfFeaturesWithoutDeclaringClass);
109             System.out.println("Total number of features without declaring class: "+numOfFeaturesWithoutDeclaringClass);
110             
111             for (Iterator it = featuresInClasses.entrySet().iterator(); it.hasNext(); ) {
112                 Map.Entry entry = (Map.Entry) it.next();
113                 JavaClass javaClass = (JavaClass) entry.getKey();
114                 int numOfFeaturesInClass = ((Integer) entry.getValue()).intValue();
115                 int expectedNumOfFeaturesInClass = ((Integer) classes.get(javaClass.getName())).intValue();
116                 assertEquals("Number of features in "+javaClass.getName(), expectedNumOfFeaturesInClass, numOfFeaturesInClass);
117             }
118         }
119         finally {
120             Utility.endTrans();
121         }*/

122     }
123     
124 }
125
Popular Tags