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