KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > jmi > javamodel > codegen > trywrapper > TryWrapper1Test


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.trywrapper;
20
21 import java.util.Collections JavaDoc;
22 import org.netbeans.jmi.javamodel.Constructor;
23 import org.netbeans.jmi.javamodel.JavaClass;
24 import org.netbeans.jmi.javamodel.JavaModelPackage;
25 import org.netbeans.jmi.javamodel.codegen.Utility;
26 import org.netbeans.junit.NbTestCase;
27 import org.netbeans.junit.NbTestSuite;
28 import org.netbeans.modules.javacore.TryWrapper;
29 import org.openide.filesystems.FileStateInvalidException;
30
31 /**
32  *
33  * @author Pavel Flaska
34  */

35 public class TryWrapper1Test extends NbTestCase {
36
37     JavaClass[] clazz = new JavaClass[2];
38     JavaModelPackage pkg;
39     
40     /** Creates a new instance of TryWrapper1Test */
41     public TryWrapper1Test() {
42         super("TryWrapper1Test");
43     }
44     
45     public static NbTestSuite suite() {
46         NbTestSuite suite = new NbTestSuite(TryWrapper1Test.class);
47         return suite;
48     }
49     
50     protected void setUp() {
51         clazz[0] = (JavaClass) Utility.findClass("org.netbeans.test.codegen.trywrapper.TryWrapper1Class");
52         clazz[1] = (JavaClass) Utility.findClass("org.netbeans.test.codegen.trywrapper.TryWrapper2Class");
53         pkg = (JavaModelPackage) clazz[0].refImmediatePackage();
54     }
55     
56     public void testWrapSingle1() throws java.io.IOException JavaDoc, FileStateInvalidException {
57         boolean fail = true;
58         Utility.beginTrans(true);
59         try {
60             Object JavaDoc o = ((Constructor) clazz[0].getContents().get(0)).getBody().getStatements().get(0);
61             TryWrapper tewecko = new TryWrapper(Collections.singletonList(o));
62             tewecko.wrap();
63             fail = false;
64         }
65         finally {
66             Utility.endTrans(fail);
67         }
68         assertFile("File is not correctly generated.",
69             Utility.getFile(getDataDir(), "org/netbeans/test/codegen/trywrapper/TryWrapper1Class.java"),
70             getGoldenFile("testWrapSingle1.pass"),
71             getWorkDir()
72         );
73     }
74     
75     public void testWrapMoreVars() throws java.io.IOException JavaDoc, FileStateInvalidException {
76         boolean fail = true;
77         Utility.beginTrans(true);
78         try {
79             Object JavaDoc o = ((Constructor) clazz[1].getContents().get(0)).getBody().getStatements().get(0);
80             TryWrapper tewecko = new TryWrapper(Collections.singletonList(o));
81             tewecko.wrap();
82             fail = false;
83         }
84         finally {
85             Utility.endTrans(fail);
86         }
87         assertFile("File is not correctly generated.",
88             Utility.getFile(getDataDir(), "org/netbeans/test/codegen/trywrapper/TryWrapper2Class.java"),
89             getGoldenFile("testWrapMoreVars.pass"),
90             getWorkDir()
91         );
92     }
93    
94 }
95
Popular Tags