KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > jmi > javamodel > codegen > VariableAccessTypeTest


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
20 package org.netbeans.jmi.javamodel.codegen;
21
22 import java.util.List JavaDoc;
23 import java.io.IOException JavaDoc;
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 /**
31  *
32  * @author Pavel Flaska
33  */

34 public class VariableAccessTypeTest extends NbTestCase {
35
36     /** Creates a new instance of VariableAccessTypeTest */
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     /**
106      * @param args the command line arguments
107      */

108     public static void main(String JavaDoc[] args) {
109         TestRunner.run(suite());
110     }
111 }
112
Popular Tags