KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.IOException JavaDoc;
23 import java.lang.reflect.Modifier JavaDoc;
24 import java.util.Collections JavaDoc;
25 import org.netbeans.jmi.javamodel.*;
26 import org.netbeans.junit.*;
27 import org.openide.filesystems.FileStateInvalidException;
28
29 /**
30  *
31  * @author Pavel Flaska
32  */

33 public class SuperClassTest extends NbTestCase {
34
35     JavaClass clazz;
36     String JavaDoc cbn;
37     JavaModelPackage pkg;
38
39     /** Creates a new instance of SuperClassTest */
40     public SuperClassTest() {
41         super("SuperClassTest");
42     }
43
44     protected void setUp() {
45         clazz = Utility.findClass("org.netbeans.test.codegen.SuperClassTest");
46         pkg = (JavaModelPackage) clazz.refImmediatePackage();
47     }
48     
49     public static NbTestSuite suite() {
50         NbTestSuite suite = new NbTestSuite(SuperClassTest.class);
51         return suite;
52     }
53
54     public void testAddClass() throws IOException JavaDoc, FileStateInvalidException {
55         boolean fail = true;
56         Utility.beginTrans(true);
57         try {
58             MultipartId multi = pkg.getMultipartId().createMultipartId("SecondInnerClass", null, null);
59             JavaClass innerClass = pkg.getJavaClass().createJavaClass(
60                 "ThirdInnerClass", // name
61
null, // annnotations
62
Modifier.STATIC, // modifiers
63
null, // javadoc
64
null, // javaDoc text
65
Collections.EMPTY_LIST, // empty features
66
multi, // superclass
67
null, // interfaces
68
null
69                 );
70             clazz.getContents().add(innerClass);
71             fail = false;
72         } finally {
73             Utility.endTrans(fail);
74         }
75         assertFile("File is not correctly generated.",
76             Utility.getFile(getDataDir(), "org/netbeans/test/codegen/SuperClassTest.java"),
77             getGoldenFile("testAddClass_SuperClassTest.pass"),
78             getWorkDir()
79         );
80     }
81
82     public void testChange() throws IOException JavaDoc, FileStateInvalidException {
83         boolean fail = true;
84         Utility.beginTrans(true);
85         try {
86             JavaClass inner = (JavaClass) clazz.getContents().get(2);
87             MultipartId id = pkg.getMultipartId().createMultipartId("SuperClassTest", null, null);
88             inner.setSuperClass((JavaClass) clazz.getContents().get(1));
89             inner.setSuperClassName(id);
90             fail = false;
91         } finally {
92             Utility.endTrans(fail);
93         }
94         assertFile("File is not correctly generated.",
95             Utility.getFile(getDataDir(), "org/netbeans/test/codegen/SuperClassTest.java"),
96             getGoldenFile("testChange_SuperClassTest.pass"),
97             getWorkDir()
98         );
99     }
100
101     public void testAddSuper() throws FileStateInvalidException, IOException JavaDoc {
102         boolean fail = true;
103         Utility.beginTrans(true);
104         try {
105             JavaClass inner = (JavaClass) clazz.getContents().get(1);
106             MultipartId id = pkg.getMultipartId().createMultipartId("NoExt", null, null);
107             inner.setSuperClassName(id);
108             inner.setSuperClass(clazz);
109             fail = false;
110         } finally {
111             Utility.endTrans(fail);
112         }
113         assertFile("File is not correctly generated.",
114             Utility.getFile(getDataDir(), "org/netbeans/test/codegen/SuperClassTest.java"),
115             getGoldenFile("testAddSuper_SuperClassTest.pass"),
116             getWorkDir()
117         );
118     }
119         
120     
121     /**
122      * @param args the command line arguments
123      */

124     public static void main(String JavaDoc[] args) {
125         // TODO code application logic here
126
}
127     
128 }
129
Popular Tags