1 19 20 package org.netbeans.jmi.javamodel.codegen; 21 22 import java.lang.reflect.Modifier ; 23 import java.util.Collections ; 24 import java.util.List ; 25 import java.io.IOException ; 26 import org.openide.filesystems.FileStateInvalidException; 27 import junit.textui.TestRunner; 28 import org.netbeans.jmi.javamodel.*; 29 import org.netbeans.junit.NbTestCase; 30 import org.netbeans.junit.NbTestSuite; 31 32 36 public class MethodTypeTest extends NbTestCase { 37 38 public MethodTypeTest() { 39 super("MethodTypeTest"); 40 } 41 42 public static NbTestSuite suite() { 43 NbTestSuite suite = new NbTestSuite(MethodTypeTest.class); 44 return suite; 45 } 46 47 private JavaModelPackage pkg; 48 private JavaClass clazz; 49 50 protected void setUp() { 51 clazz = Utility.findClass("org.netbeans.test.codegen.MethodTypeClass"); 52 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 53 } 54 55 public void testGetTypeConstr() { 56 boolean fail = true; 57 Utility.beginTrans(true); 58 try { 59 Constructor constr = (Constructor) clazz.getContents().get(1); 60 ExpressionStatement stat = (ExpressionStatement) constr.getBody().getStatements().get(0); 61 Assignment assign = (Assignment) stat.getExpression(); 62 MethodInvocation invo = (MethodInvocation) assign.getRightSide(); 63 if ("org.netbeans.test.codegen.Retezec".equals(invo.getType().getName()) == false) { 64 fail("Expected return type Retezec not found. (Found " + invo.getType().getName() + ")."); 65 } 66 fail = false; 67 } finally { 68 Utility.endTrans(fail); 69 } 70 } 71 72 public void testGetMethodType() { 73 boolean fail = true; 74 Utility.beginTrans(true); 75 try { 76 Method method = (Method) clazz.getContents().get(2); 77 Type type = method.getType(); 78 if ("org.netbeans.test.codegen.Retezec".equals(type.getName()) == false) { 79 fail("Expected return type Retezec not found. (Found " + type.getName() + ")."); 80 } 81 fail = false; 82 } finally { 83 Utility.endTrans(fail); 84 } 85 } 86 87 public void testGetTypeInvocation() { 88 boolean fail = true; 89 Utility.beginTrans(true); 90 try { 91 Method method = (Method) clazz.getContents().get(2); 92 ReturnStatement stat = (ReturnStatement) method.getBody().getStatements().get(0); 93 MethodInvocation invo = (MethodInvocation) stat.getExpression(); 94 if ("org.netbeans.test.codegen.Retezec".equals(invo.getType().getName()) == false) { 95 fail("Expected return type Retezec not found. (Found " + invo.getType().getName() + ")."); 96 } 97 fail = false; 98 } finally { 99 Utility.endTrans(fail); 100 } 101 } 102 103 106 public static void main(String [] args) { 107 TestRunner.run(suite()); 108 } 109 } 110 | Popular Tags |