KickJava   Java API By Example, From Geeks To Geeks.

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


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.lang.reflect.Modifier JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.List JavaDoc;
25 import java.io.IOException JavaDoc;
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 /**
33  *
34  * @author Pavel Flaska
35  */

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     /**
104      * @param args the command line arguments
105      */

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