KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.jmi.javamodel.codegen;
20
21 import java.lang.reflect.Modifier JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import junit.textui.TestRunner;
24 import org.netbeans.jmi.javamodel.Feature;
25 import org.netbeans.jmi.javamodel.Field;
26 import org.netbeans.jmi.javamodel.FieldGroup;
27 import org.netbeans.jmi.javamodel.JavaClass;
28 import org.netbeans.jmi.javamodel.JavaModelPackage;
29 import org.netbeans.jmi.javamodel.TypeReference;
30 import org.netbeans.junit.NbTestCase;
31 import org.netbeans.junit.NbTestSuite;
32 import org.netbeans.modules.javacore.jmiimpl.javamodel.TypeReferenceImpl;
33 import org.openide.filesystems.FileStateInvalidException;
34
35 /**
36  *
37  * @author Pavel Flaska
38  */

39 public class FieldTest2 extends NbTestCase {
40     
41     /** Creates a new instance of FieldTest2 */
42     public FieldTest2() {
43         super("FieldTest2");
44     }
45     
46     public static NbTestSuite suite() {
47         NbTestSuite suite = new NbTestSuite(FieldTest2.class);
48         return suite;
49     }
50     
51     JavaClass clazz;
52     JavaModelPackage pkg;
53     
54     protected void setUp() {
55         clazz = Utility.findClass("org.netbeans.test.codegen.FieldTest2");
56         pkg = (JavaModelPackage) clazz.refImmediatePackage();
57     }
58
59     /**
60      * Test move field from field group to the single field declaration.
61      */

62     public void testMoveField() throws java.io.IOException JavaDoc, FileStateInvalidException {
63         boolean fail = true;
64         Utility.beginTrans(true);
65         try {
66             Field nerudova = null;
67             for (Iterator JavaDoc fIt = clazz.getContents().iterator(); fIt.hasNext(); ) {
68                 Object JavaDoc feature = fIt.next();
69                 if (feature instanceof FieldGroup) {
70                     FieldGroup group = (FieldGroup) feature;
71                     nerudova = (Field) group.getFields().remove(2);
72                     nerudova.setTypeName((TypeReference) ((TypeReferenceImpl) group.getTypeName()).duplicate());
73                     nerudova.setModifiers(Modifier.PRIVATE);
74                 }
75             }
76             clazz.getFeatures().add(nerudova);
77             fail = false;
78         }
79         finally {
80             Utility.endTrans(fail);
81         }
82         assertFile("File is not correctly generated.",
83             Utility.getFile(getDataDir(), "org/netbeans/test/codegen/FieldTest2.java"),
84             getGoldenFile("FieldTest2.pass"),
85             getWorkDir()
86         );
87     }
88     
89     /**
90      * @param args the command line arguments
91      */

92     public static void main(String JavaDoc[] args) {
93         TestRunner.run(suite());
94     }
95     
96 }
97
Popular Tags