KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > jmi > javamodel > codegen > indent > BlenderTest


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.indent;
20
21 import org.netbeans.jmi.javamodel.Assignment;
22 import org.netbeans.jmi.javamodel.Constructor;
23 import org.netbeans.jmi.javamodel.Expression;
24 import org.netbeans.jmi.javamodel.InitialValue;
25 import org.netbeans.jmi.javamodel.JavaClass;
26 import org.netbeans.jmi.javamodel.JavaModelPackage;
27 import org.netbeans.jmi.javamodel.LocalVarDeclaration;
28 import org.netbeans.jmi.javamodel.LocalVariable;
29 import org.netbeans.jmi.javamodel.OperatorEnum;
30 import org.netbeans.jmi.javamodel.TryStatement;
31 import org.netbeans.jmi.javamodel.VariableAccess;
32 import org.netbeans.jmi.javamodel.codegen.Utility;
33 import org.netbeans.junit.NbTestCase;
34 import org.netbeans.junit.NbTestSuite;
35 import org.openide.filesystems.FileStateInvalidException;
36
37 /**
38  *
39  * @author Pavel Flaska
40  */

41 public class BlenderTest extends NbTestCase {
42     
43     JavaClass clazz;
44     JavaModelPackage pkg;
45     
46     /** Creates a new instance of BlenderTest */
47     public BlenderTest() {
48         super("BlenderTest");
49     }
50     public static NbTestSuite suite() {
51         NbTestSuite suite = new NbTestSuite(BlenderTest.class);
52         return suite;
53     }
54     
55     protected void setUp() {
56         clazz = (JavaClass) Utility.findClass("org.netbeans.test.codegen.indent.Blender");
57         pkg = (JavaModelPackage) clazz.refImmediatePackage();
58     }
59
60     public void testMixStatements() throws java.io.IOException JavaDoc, FileStateInvalidException {
61         boolean fail = true;
62         Utility.beginTrans(true);
63         try {
64             Constructor constructor = (Constructor) clazz.getContents().get(0);
65             TryStatement tryStmt = (TryStatement) constructor.getBody().getStatements().get(1);
66             LocalVarDeclaration lvd = (LocalVarDeclaration) tryStmt.getBody().getStatements().remove(0);
67             LocalVariable lv = (LocalVariable) lvd.getVariables().get(0);
68             InitialValue iv = lv.getInitialValue();
69             lv.setInitialValue(null);
70             VariableAccess va = (VariableAccess) pkg.getVariableAccess().createVariableAccess(lv.getName(), null, false);
71             Assignment a = pkg.getAssignment().createAssignment(va, OperatorEnum.ASSIGN, (Expression) iv);
72             constructor.getBody().getStatements().add(1, lvd);
73             tryStmt.getBody().getStatements().add(0, pkg.getExpressionStatement().createExpressionStatement(a));
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/indent/Blender.java"),
81             getGoldenFile("testMixStatements_BlenderTest.pass"),
82             getWorkDir()
83         );
84     }
85 }
86
Popular Tags