KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import junit.textui.TestRunner;
26 import org.netbeans.jmi.javamodel.Expression;
27 import org.netbeans.jmi.javamodel.Field;
28 import org.netbeans.jmi.javamodel.FieldGroup;
29 import org.netbeans.jmi.javamodel.ForStatement;
30 import org.netbeans.jmi.javamodel.JavaClass;
31 import org.netbeans.jmi.javamodel.JavaModelPackage;
32 import org.netbeans.jmi.javamodel.LocalVarDeclaration;
33 import org.netbeans.jmi.javamodel.LocalVariable;
34 import org.netbeans.jmi.javamodel.Method;
35 import org.netbeans.jmi.javamodel.MethodClass;
36 import org.netbeans.jmi.javamodel.MultipartId;
37 import org.netbeans.jmi.javamodel.OperatorEnum;
38 import org.netbeans.jmi.javamodel.StatementBlock;
39 import org.netbeans.jmi.javamodel.UnaryExpression;
40 import org.netbeans.junit.NbTestCase;
41 import org.netbeans.junit.NbTestSuite;
42 import org.openide.filesystems.FileStateInvalidException;
43
44 /**
45  *
46  * @author Pavel Flaska
47  */

48 public class GroupTest extends NbTestCase {
49     
50     /** Need to be defined because of JUnit */
51     public GroupTest() {
52         super("GroupTest");
53     }
54     
55     public static NbTestSuite suite() {
56         NbTestSuite suite = new NbTestSuite(GroupTest.class);
57         return suite;
58     }
59     
60     JavaClass clazz;
61     JavaModelPackage pkg;
62     
63     protected void setUp() {
64         clazz = Utility.findClass("org.netbeans.test.codegen.GroupTestClass");
65         pkg = (JavaModelPackage) clazz.refImmediatePackage();
66     }
67
68     /**
69      * Tests the field groups.
70      */

71     public void testGroup() throws java.io.IOException JavaDoc, FileStateInvalidException {
72         boolean fail = true;
73         Utility.beginTrans(true);
74         try {
75             int i = 0;
76             for (Iterator JavaDoc fIt = clazz.getContents().iterator(); fIt.hasNext(); ) {
77                 i++;
78                 FieldGroup fieldGroup = (FieldGroup) fIt.next();
79                 Field fieldToRemove = null;
80                 for (Iterator JavaDoc fieldsIt = fieldGroup.getFields().iterator(); fieldsIt.hasNext(); ) {
81                     Field f = (Field) fieldsIt.next();
82                     String JavaDoc fieldName = f.getName();
83                     if ("b".equals(fieldName)) {
84                         f.setName("bingo");
85                     } else if ("sun".equals(fieldName)) {
86                         f.setInitialValueText("\"does not have notebooks!\"");
87                     } else if ("ibm".equals(fieldName)) {
88                         f.setInitialValueText("\"Thinkpad\"");
89                     } else if ("coca".equals(fieldName)) {
90                         fieldToRemove = f;
91                     } else if ("rc".equals(fieldName)) {
92                         f.setInitialValueText(null);
93                     }
94                 }
95                 fieldGroup.getFields().remove(fieldToRemove);
96             }
97             fail = false;
98         }
99         finally {
100             Utility.endTrans(fail);
101         }
102         assertFile("File is not correctly generated.",
103             Utility.getFile(getDataDir(), "org/netbeans/test/codegen/GroupTestClass.java"),
104             getGoldenFile("GroupTestClass.pass"),
105             getWorkDir()
106         );
107     }
108
109     
110     /**
111      * @param args the command line arguments
112      */

113     public static void main(String JavaDoc[] args) {
114         TestRunner.run(suite());
115     }
116     
117 }
118
Popular Tags