1 19 package org.netbeans.jmi.javamodel.getters; 20 21 import java.util.Collection ; 22 import java.util.Iterator ; 23 import java.util.List ; 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 39 public class ParamNameTest extends NbTestCase { 40 41 JavaClass clazz; 42 JavaModelPackage pkg; 43 44 String [] 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 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 it = clazz.getFeatures().iterator(); it.hasNext(); ) { 105 Feature f = (Feature) it.next(); 106 if (f instanceof Method) { 107 Method m = (Method) f; 108 String s = m.getType().getName() + ' ' + m.getName() + '('; 109 for (Iterator 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 c = f.getMethods(); 133 for (Iterator 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 pars = m.getParameters(); 137 for (Iterator 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 e) { 147 assertFalse(false); 148 } 149 } 150 151 } 152 | Popular Tags |