KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.IOException JavaDoc;
22 import org.netbeans.jmi.javamodel.JavaClass;
23 import org.netbeans.jmi.javamodel.JavaModelPackage;
24 import org.netbeans.jmi.javamodel.codegen.Utility;
25 import org.netbeans.junit.NbTestCase;
26 import org.netbeans.junit.NbTestSuite;
27 import org.netbeans.modules.javacore.jmiimpl.javamodel.MethodImpl;
28 import org.openide.filesystems.FileStateInvalidException;
29
30 /**
31  *
32  * @author Pavel Flaska
33  */

34 public class MoveElementsTest extends NbTestCase {
35
36     JavaClass sourceClass, destClass;
37     JavaModelPackage pkg;
38     
39     /** Creates a new instance of MoveElementsTest */
40     public MoveElementsTest(String JavaDoc s) {
41         super(s);
42     }
43     
44     public static NbTestSuite suite() {
45         NbTestSuite suite = new NbTestSuite();
46         suite.addTest(new MoveElementsTest("testMoveAlois"));
47         suite.addTest(new MoveElementsTest("testMoveLojza"));
48         suite.addTest(new MoveElementsTest("testMoveGianluigi"));
49         suite.addTest(new MoveElementsTest("testMoveCall"));
50         return suite;
51     }
52     
53     protected void setUp() {
54         sourceClass = (JavaClass) Utility.findClass("org.netbeans.test.codegen.indent.GarbageClass");
55         destClass = (JavaClass) Utility.findClass("org.netbeans.test.codegen.indent.TrashClass.FirstTrash");
56         pkg = (JavaModelPackage) sourceClass.refImmediatePackage();
57     }
58     
59     public void testMoveAlois() throws IOException JavaDoc, FileStateInvalidException {
60         boolean fail = true;
61         Utility.beginTrans(true);
62         try {
63             MethodImpl m = (MethodImpl) sourceClass.getContents().remove(0);
64             destClass.getContents().add(m);
65             m.fixImports(destClass, m);
66             fail = false;
67         }
68         finally {
69             Utility.endTrans(fail);
70         }
71         assertFile("File is not correctly generated.",
72             Utility.getFile(getDataDir(), "org/netbeans/test/codegen/indent/TrashClass.java"),
73                 getGoldenFile("testMoveAlois_MoveElementsTest.pass"),
74             getWorkDir()
75         );
76     }
77     
78     public void testMoveLojza() throws IOException JavaDoc, FileStateInvalidException {
79         boolean fail = true;
80         Utility.beginTrans(true);
81         try {
82             MethodImpl m = (MethodImpl) sourceClass.getContents().remove(0);
83             destClass.getContents().add(m);
84             m.fixImports(destClass, m);
85             fail = false;
86         }
87         finally {
88             Utility.endTrans(fail);
89         }
90         assertFile("File is not correctly generated.",
91             Utility.getFile(getDataDir(), "org/netbeans/test/codegen/indent/TrashClass.java"),
92                 getGoldenFile("testMoveLojza_MoveElementsTest.pass"),
93             getWorkDir()
94         );
95     }
96     
97     public void testMoveGianluigi() throws IOException JavaDoc, FileStateInvalidException {
98         boolean fail = true;
99         Utility.beginTrans(true);
100         try {
101             MethodImpl m = (MethodImpl) sourceClass.getContents().remove(0);
102             destClass.getContents().add(0, m);
103             m.fixImports(destClass, m);
104             fail = false;
105         }
106         finally {
107             Utility.endTrans(fail);
108         }
109         assertFile("File is not correctly generated.",
110             Utility.getFile(getDataDir(), "org/netbeans/test/codegen/indent/TrashClass.java"),
111                 getGoldenFile("testMoveGianluigi_MoveElementsTest.pass"),
112             getWorkDir()
113         );
114     }
115     
116     public void testMoveCall() throws IOException JavaDoc, FileStateInvalidException {
117         boolean fail = true;
118         Utility.beginTrans(true);
119         try {
120             MethodImpl m = (MethodImpl) sourceClass.getContents().remove(0);
121             destClass.getContents().add(m);
122             m.fixImports(destClass, m);
123             fail = false;
124         }
125         finally {
126             Utility.endTrans(fail);
127         }
128         assertFile("File is not correctly generated.",
129             Utility.getFile(getDataDir(), "org/netbeans/test/codegen/indent/TrashClass.java"),
130                 getGoldenFile("testMoveCall_MoveElementsTest.pass"),
131             getWorkDir()
132         );
133     }
134 }
135
Popular Tags