KickJava   Java API By Example, From Geeks To Geeks.

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


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.lang.reflect.Modifier JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.List JavaDoc;
25 import org.netbeans.jmi.javamodel.Annotation;
26 import org.netbeans.jmi.javamodel.JavaClass;
27 import org.netbeans.jmi.javamodel.JavaModelPackage;
28 import org.netbeans.jmi.javamodel.Method;
29 import org.netbeans.jmi.javamodel.MultipartId;
30 import org.netbeans.jmi.javamodel.codegen.Utility;
31 import org.netbeans.junit.NbTestCase;
32 import org.netbeans.junit.NbTestSuite;
33 import org.openide.filesystems.FileStateInvalidException;
34
35 /**
36  *
37  * @author Pavel Flaska
38  */

39 public class AnnIndentTest2 extends NbTestCase {
40     
41     JavaClass clazz;
42     JavaModelPackage pkg;
43     
44     /** Creates a new instance of AnnIndentTest */
45     public AnnIndentTest2() {
46         super("AnnIndentTest2");
47     }
48     
49     public static NbTestSuite suite() {
50         NbTestSuite suite = new NbTestSuite(AnnIndentTest2.class);
51         return suite;
52     }
53     
54     protected void setUp() {
55         clazz = (JavaClass) Utility.findClass("org.netbeans.test.codegen.indent.AnnIndentClass2");
56         pkg = (JavaModelPackage) clazz.refImmediatePackage();
57     }
58     
59     public void testAddAnns() throws java.io.IOException JavaDoc, FileStateInvalidException {
60         boolean fail = true;
61         Utility.beginTrans(true);
62         try {
63             MultipartId type1 = pkg.getMultipartId().createMultipartId("Deprecated()", null, Collections.EMPTY_LIST);
64             MultipartId type2 = pkg.getMultipartId().createMultipartId("Deprecated2()", null, Collections.EMPTY_LIST);
65             Annotation ann1 = pkg.getAnnotation().createAnnotation(type1, Collections.EMPTY_LIST);
66             Annotation ann2 = pkg.getAnnotation().createAnnotation(type2, Collections.EMPTY_LIST);
67             clazz.getAnnotations().add(ann1);
68             clazz.getAnnotations().add(ann2);
69             Method m = pkg.getMethod().createMethod("newMethod", Collections.EMPTY_LIST, Modifier.PUBLIC, null, null, null, null, null, null, null,
70                     pkg.getMultipartId().createMultipartId("void", null, null), 0);
71             clazz.getContents().add(m);
72             fail = false;
73         } finally {
74             Utility.endTrans(fail);
75         }
76         fail = true;
77         Utility.beginTrans(true);
78         try {
79             Method m = (Method) clazz.getContents().get(1);
80             MultipartId type3 = pkg.getMultipartId().createMultipartId("Deprecated()", null, Collections.EMPTY_LIST);
81             Annotation ann3 = pkg.getAnnotation().createAnnotation(type3, Collections.EMPTY_LIST);
82             List JavaDoc annList = m.getAnnotations();
83             annList.add(ann3);
84             fail = false;
85         } finally {
86             Utility.endTrans(fail);
87         }
88         fail = true;
89         Utility.beginTrans(true);
90         try {
91             Method m = (Method) clazz.getContents().get(1);
92             MultipartId type4 = pkg.getMultipartId().createMultipartId("Deprecated2()", null, Collections.EMPTY_LIST);
93             Annotation ann4 = pkg.getAnnotation().createAnnotation(type4, Collections.EMPTY_LIST);
94             List JavaDoc annList = m.getAnnotations();
95             annList.add(ann4);
96             fail = false;
97         } finally {
98             Utility.endTrans(fail);
99         }
100         assertFile("File is not correctly generated.",
101             Utility.getFile(getDataDir(), "org/netbeans/test/codegen/indent/AnnIndentClass2.java"),
102             getGoldenFile("testAddAnns_AnnIndentTest2.pass"),
103             getWorkDir()
104         );
105     }
106     
107 }
108
Popular Tags