KickJava   Java API By Example, From Geeks To Geeks.

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


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

36 public class ParDimCountTest extends NbTestCase {
37     
38     JavaClass clazz;
39     JavaModelPackage pkg;
40     List JavaDoc/*<Parameters>*/ parameters;
41     
42     /** Creates a new instance of ParDimCountTest */
43     public ParDimCountTest() {
44         super("ParDimCountTest");
45     }
46     
47     public static NbTestSuite suite() {
48         NbTestSuite suite = new NbTestSuite(ParDimCountTest.class);
49         return suite;
50     }
51     
52     protected void setUp() {
53         clazz = (JavaClass) Utility.findClass("org.netbeans.test.codegen.ParDimCount");
54         pkg = (JavaModelPackage) clazz.refImmediatePackage();
55         parameters = ((Constructor) clazz.getContents().get(0)).getParameters();
56     }
57     
58     public void testParDim1To2() throws java.io.IOException JavaDoc, FileStateInvalidException {
59         boolean fail = true;
60         Utility.beginTrans(true);
61         try {
62             ((Parameter) parameters.get(0)).setDimCount(2);
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/ParDimCount.java"),
70             getGoldenFile("testParDim1To2_ParDimCountTest.pass"),
71             getWorkDir()
72         );
73     }
74     
75     public void testParDim1To0() throws java.io.IOException JavaDoc, FileStateInvalidException {
76         boolean fail = true;
77         Utility.beginTrans(true);
78         try {
79             ((Parameter) parameters.get(1)).setDimCount(0);
80             fail = false;
81         }
82         finally {
83             Utility.endTrans(fail);
84         }
85         assertFile("File is not correctly generated.",
86             Utility.getFile(getDataDir(), "org/netbeans/test/codegen/ParDimCount.java"),
87             getGoldenFile("testParDim1To0_ParDimCountTest.pass"),
88             getWorkDir()
89         );
90     }
91     
92     public void testCreateDimPar() throws java.io.IOException JavaDoc, FileStateInvalidException {
93         boolean fail = true;
94         Utility.beginTrans(true);
95         try {
96             MultipartId id = pkg.getMultipartId().createMultipartId("java.util.List", null, null);
97             parameters.add(pkg.getParameter().createParameter("l", null, false, id, 2, false));
98             fail = false;
99         }
100         finally {
101             Utility.endTrans(fail);
102         }
103         assertFile("File is not correctly generated.",
104             Utility.getFile(getDataDir(), "org/netbeans/test/codegen/ParDimCount.java"),
105             getGoldenFile("testCreateDimPar_ParDimCountTest.pass"),
106             getWorkDir()
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