KickJava   Java API By Example, From Geeks To Geeks.

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


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.Collections JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import junit.textui.TestRunner;
26 import org.netbeans.jmi.javamodel.*;
27 import org.netbeans.junit.NbTestCase;
28 import org.netbeans.junit.NbTestSuite;
29 import org.openide.filesystems.FileStateInvalidException;
30
31 /**
32  *
33  * @author Pavel Flaska
34  */

35 public class EnumFacilityTest extends NbTestCase {
36
37     JavaClass clazz;
38     JavaModelPackage pkg;
39
40     /** Creates a new instance of EnumFacilityTest */
41     public EnumFacilityTest() {
42         super("EnumFacilityTest");
43     }
44
45     public static NbTestSuite suite() {
46         NbTestSuite suite = new NbTestSuite(EnumFacilityTest.class);
47         return suite;
48     }
49
50     protected void setUp() {
51         clazz = Utility.findClass("org.netbeans.test.codegen.EnumFacilityName");
52         pkg = (JavaModelPackage) clazz.refImmediatePackage();
53     }
54     
55     public void testAddConst() throws java.io.IOException JavaDoc, FileStateInvalidException {
56         boolean fail = true;
57         Utility.beginTrans(true);
58         try {
59             MultipartId par = pkg.getMultipartId().createMultipartId("\"rebirth\"", null, null);
60             EnumConstant enumConst = pkg.getEnumConstant().createEnumConstant(
61                 "NASTASIYA",
62                 null, // annontations
63
0, // modifiers
64
null, // javadoc text
65
null, // javadoc
66
false, // isFinal
67
null, // typeName
68
0, // dimCount
69
par, // initialValue
70
null, // initialValueText
71
null // body
72
);
73             ((JavaEnum) clazz.getContents().get(0)).getConstants().add(4, enumConst);
74             fail = false;
75         }
76         finally {
77             Utility.endTrans(fail);
78         }
79         assertFile("File is not correctly generated.",
80             Utility.getFile(getDataDir(), "org/netbeans/test/codegen/EnumFacilityName.java"),
81             getGoldenFile("testAddConst_EnumFacilityName.pass"),
82             getWorkDir()
83         );
84     }
85     
86     public void testReorder() throws java.io.IOException JavaDoc, FileStateInvalidException {
87         boolean fail = true;
88         Utility.beginTrans(true);
89         try {
90             JavaEnum enumeration = (JavaEnum) clazz.getContents().get(0);
91             List JavaDoc constants = enumeration.getConstants();
92             Object JavaDoc constant = constants.remove(0);
93             constants.add(4, constant);
94             fail = false;
95         } finally {
96             Utility.endTrans(fail);
97         }
98         assertFile("File is not correctly generated.",
99             Utility.getFile(getDataDir(), "org/netbeans/test/codegen/EnumFacilityName.java"),
100             getGoldenFile("testReorder_EnumFacilityName.pass"),
101             getWorkDir()
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