KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > jmi > javamodel > getters > ParamNameTest


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.getters;
20
21 import java.util.Collection JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24 import org.netbeans.jmi.javamodel.Feature;
25 import org.netbeans.jmi.javamodel.JavaClass;
26 import org.netbeans.jmi.javamodel.JavaModelPackage;
27 import org.netbeans.jmi.javamodel.Method;
28 import org.netbeans.jmi.javamodel.Parameter;
29 import org.netbeans.jmi.javamodel.codegen.Utility;
30 import org.netbeans.junit.NbTestCase;
31 import org.netbeans.junit.NbTestSuite;
32 import org.netbeans.modules.classfile.ClassFile;
33
34 /**
35  * Checks the correctness of parameter's name
36  *
37  * @author Pavel Flaska
38  */

39 public class ParamNameTest extends NbTestCase {
40     
41     JavaClass clazz;
42     JavaModelPackage pkg;
43     
44     String JavaDoc[] result = {
45     "void assertTrue(java.lang.String message, boolean condition)",
46     "void assertTrue(boolean condition)",
47     "void assertFalse(java.lang.String message, boolean condition)",
48     "void assertFalse(boolean condition)",
49     "void fail(java.lang.String message)",
50     "void fail()",
51     "void assertEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual)",
52     "void assertEquals(java.lang.Object expected, java.lang.Object actual)",
53     "void assertEquals(java.lang.String message, java.lang.String expected, java.lang.String actual)",
54     "void assertEquals(java.lang.String expected, java.lang.String actual)",
55     "void assertEquals(java.lang.String message, double expected, double actual, double delta)",
56     "void assertEquals(double expected, double actual, double delta)",
57     "void assertEquals(java.lang.String message, float expected, float actual, float delta)",
58     "void assertEquals(float expected, float actual, float delta)",
59     "void assertEquals(java.lang.String message, long expected, long actual)",
60     "void assertEquals(long expected, long actual)",
61     "void assertEquals(java.lang.String message, boolean expected, boolean actual)",
62     "void assertEquals(boolean expected, boolean actual)",
63     "void assertEquals(java.lang.String message, byte expected, byte actual)",
64     "void assertEquals(byte expected, byte actual)",
65     "void assertEquals(java.lang.String message, char expected, char actual)",
66     "void assertEquals(char expected, char actual)",
67     "void assertEquals(java.lang.String message, short expected, short actual)",
68     "void assertEquals(short expected, short actual)",
69     "void assertEquals(java.lang.String message, int expected, int actual)",
70     "void assertEquals(int expected, int actual)",
71     "void assertNotNull(java.lang.Object object)",
72     "void assertNotNull(java.lang.String message, java.lang.Object object)",
73     "void assertNull(java.lang.Object object)",
74     "void assertNull(java.lang.String message, java.lang.Object object)",
75     "void assertSame(java.lang.String message, java.lang.Object expected, java.lang.Object actual)",
76     "void assertSame(java.lang.Object expected, java.lang.Object actual)",
77     "void assertNotSame(java.lang.String message, java.lang.Object expected, java.lang.Object actual)",
78     "void assertNotSame(java.lang.Object expected, java.lang.Object actual)",
79     "void failSame(java.lang.String message)",
80     "void failNotSame(java.lang.String message, java.lang.Object expected, java.lang.Object actual)",
81     "void failNotEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual)",
82     "java.lang.String format(java.lang.String message, java.lang.Object expected, java.lang.Object actual)"
83     };
84
85     /** Creates a new instance of ParamNameTest */
86     public ParamNameTest() {
87         super("ParamNameTest");
88     }
89     
90     public static NbTestSuite suite() {
91         NbTestSuite suite = new NbTestSuite(ParamNameTest.class);
92         return suite;
93     }
94     
95     protected void setUp() {
96         clazz = (JavaClass) Utility.findClass("junit.framework.Assert");
97         pkg = (JavaModelPackage) clazz.refImmediatePackage();
98     }
99
100     public void test() {
101         if (clazz instanceof JavaClass) {
102             getLog().println(clazz.getName() + " contains methods:");
103             int counter = 0;
104             for (Iterator JavaDoc/*Feature*/ it = clazz.getFeatures().iterator(); it.hasNext(); ) {
105                 Feature f = (Feature) it.next();
106                 if (f instanceof Method) {
107                     Method m = (Method) f;
108                     String JavaDoc s = m.getType().getName() + ' ' + m.getName() + '(';
109                     for (Iterator JavaDoc itPar = m.getParameters().iterator(); itPar.hasNext(); ) {
110                         Parameter p = (Parameter) itPar.next();
111                         s += p.getType().getName() + ' ' + p.getName();
112                         if (itPar.hasNext()) {
113                             s += ", ";
114                         } else {
115                             break;
116                         }
117                     }
118                     s += ')';
119                     getLog().println("\t" + s);
120                     assertEquals(result[counter], s);
121                     counter++;
122                 }
123             }
124         } else {
125             getLog().println("Cannot resolve class!");
126         }
127     }
128     
129     private void temporary() {
130         try {
131             ClassFile f = new ClassFile("/tmp/junit/framework/Assert.class", true);
132             Collection JavaDoc/*Method*/ c = f.getMethods();
133             for (Iterator JavaDoc mIt = c.iterator(); mIt.hasNext(); ) {
134                 org.netbeans.modules.classfile.Method m = (org.netbeans.modules.classfile.Method) mIt.next();
135                 getLog().print(m.getName() + "(");
136                 List JavaDoc/*Parameter*/ pars = m.getParameters();
137                 for (Iterator JavaDoc pIt = pars.iterator(); pIt.hasNext(); ) {
138                     org.netbeans.modules.classfile.Parameter p = (org.netbeans.modules.classfile.Parameter) pIt.next();
139                     getLog().print(p.getDescriptor() + " " + p.getName());
140                     if (pIt.hasNext()) {
141                         getLog().print(", ");
142                     }
143                 }
144                 getLog().println(")");
145             }
146         } catch (Exception JavaDoc e) {
147             assertFalse(false);
148         }
149     }
150     
151 }
152
Popular Tags