KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.netbeans.junit.NbTestSuite;
23 import org.netbeans.junit.NbTestCase;
24 import org.netbeans.jmi.javamodel.*;
25 import org.openide.filesystems.FileStateInvalidException;
26 import junit.textui.TestRunner;
27 import java.io.IOException JavaDoc;
28 import java.util.Arrays JavaDoc;
29
30 /**
31  * @author Martin Matula
32  */

33 public class GenericsTest extends NbTestCase {
34     public GenericsTest() {
35         super("GenericsTest");
36     }
37
38     public static NbTestSuite suite() {
39         NbTestSuite suite = new NbTestSuite(GenericsTest.class);
40         return suite;
41     }
42
43     JavaClass clazz;
44     JavaModelPackage pkg;
45
46     protected void setUp() {
47         clazz = (JavaClass) Utility.findClass("org.netbeans.test.codegen.Generics");
48         pkg = (JavaModelPackage) clazz.refImmediatePackage();
49     }
50
51     public void testAddBound() throws java.io.IOException JavaDoc, FileStateInvalidException {
52         boolean fail = true;
53         Utility.beginTrans(true);
54         try {
55             TypeParameter tp = (TypeParameter) clazz.getTypeParameters().get(0);
56             tp.getInterfaceNames().add(pkg.getMultipartId().createMultipartId("List", null, null));
57             fail = false;
58         }
59         finally {
60             Utility.endTrans(fail);
61         }
62         assertFile("File is not correctly generated.",
63                 getGoldenFile("Generics.pass"),
64                 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/Generics.java"),
65                 getWorkDir()
66         );
67     }
68
69     public void testAddTypeParamMethod() throws IOException JavaDoc, FileStateInvalidException {
70         JavaClass cls = (JavaClass) Utility.findClass("org.netbeans.test.codegen.GenericMethod");
71         boolean fail = true;
72         Utility.beginTrans(true);
73         try {
74             TypeParameter tp = pkg.getTypeParameter().createTypeParameter("Y", null, 0, null, null, null, null, Arrays.asList(new Object JavaDoc[] {pkg.getMultipartId().createMultipartId("Collection", null, null)}), null);
75             Method m = (Method) cls.getContents().get(0);
76             m.getTypeParameters().add(tp);
77             fail = false;
78         }
79         finally {
80             Utility.endTrans(fail);
81         }
82         assertFile("File is not correctly generated.",
83                 getGoldenFile("GenericMethod.pass"),
84                 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/GenericMethod.java"),
85                 getWorkDir()
86         );
87     }
88
89     /**
90      * @param args the command line arguments
91      */

92     public static void main(String JavaDoc[] args) {
93         TestRunner.run(suite());
94     }
95
96 }
97
Popular Tags