1 19 package org.netbeans.jmi.javamodel.codegen.indent; 20 21 import java.lang.reflect.Modifier ; 22 import java.util.ArrayList ; 23 import java.util.Collections ; 24 import java.util.List ; 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 40 public class AnnIndentTest extends NbTestCase { 41 42 JavaClass clazz; 43 JavaModelPackage pkg; 44 45 46 public AnnIndentTest() { 47 super("AnnIndentTest"); 48 } 49 50 public static NbTestSuite suite() { 51 NbTestSuite suite = new NbTestSuite(AnnIndentTest.class); 52 return suite; 53 } 54 55 protected void setUp() { 56 clazz = (JavaClass) Utility.findClass("org.netbeans.test.codegen.indent.AnnIndentClass"); 57 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 58 } 59 60 public void testAddAnnotations() throws java.io.IOException , FileStateInvalidException { 61 boolean fail = true; 62 Utility.beginTrans(true); 63 try { 64 Method m = (Method) clazz.getContents().get(1); 65 MultipartId type1 = pkg.getMultipartId().createMultipartId("Deprecated()", null, Collections.EMPTY_LIST); 66 MultipartId type2 = pkg.getMultipartId().createMultipartId("Deprecated2()", null, Collections.EMPTY_LIST); 67 Annotation ann1 = pkg.getAnnotation().createAnnotation(type1, Collections.EMPTY_LIST); 68 Annotation ann2 = pkg.getAnnotation().createAnnotation(type2, Collections.EMPTY_LIST); 69 m.getAnnotations().add(ann1); 70 m.getAnnotations().add(ann2); 71 fail = false; 72 } 73 finally { 74 Utility.endTrans(fail); 75 } 76 assertFile("File is not correctly generated.", 77 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/indent/AnnIndentClass.java"), 78 getGoldenFile("testAddAnnotations_AnnIndentTest.pass"), 79 getWorkDir() 80 ); 81 } 82 83 public void testAddAnnotationsToClass() throws java.io.IOException , FileStateInvalidException { 84 boolean fail = true; 85 Utility.beginTrans(true); 86 try { 87 MultipartId type1 = pkg.getMultipartId().createMultipartId("Deprecated()", null, Collections.EMPTY_LIST); 88 MultipartId type2 = pkg.getMultipartId().createMultipartId("Deprecated2()", null, Collections.EMPTY_LIST); 89 Annotation ann1 = pkg.getAnnotation().createAnnotation(type1, Collections.EMPTY_LIST); 90 Annotation ann2 = pkg.getAnnotation().createAnnotation(type2, Collections.EMPTY_LIST); 91 clazz.getAnnotations().add(ann1); 92 clazz.getAnnotations().add(ann2); 93 fail = false; 94 } 95 finally { 96 Utility.endTrans(fail); 97 } 98 assertFile("File is not correctly generated.", 99 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/indent/AnnIndentClass.java"), 100 getGoldenFile("testAddAnnotationsToClass_AnnIndentTest.pass"), 101 getWorkDir() 102 ); 103 } 104 105 public void testAddAnnotationWithMethod() throws java.io.IOException , FileStateInvalidException { 106 boolean fail = true; 107 Utility.beginTrans(true); 108 try { 109 MultipartId type1 = pkg.getMultipartId().createMultipartId("Deprecated()", null, Collections.EMPTY_LIST); 110 MultipartId type2 = pkg.getMultipartId().createMultipartId("Deprecated2()", null, Collections.EMPTY_LIST); 111 Annotation ann1 = pkg.getAnnotation().createAnnotation(type1, Collections.EMPTY_LIST); 112 Annotation ann2 = pkg.getAnnotation().createAnnotation(type2, Collections.EMPTY_LIST); 113 List annList = new ArrayList (); 114 annList.add(ann1); 115 annList.add(ann2); 116 Method m = pkg.getMethod().createMethod("newMethod", annList, Modifier.PUBLIC, null, null, null, null, null, null, null, 117 pkg.getMultipartId().createMultipartId("void", null, null), 0); 118 clazz.getContents().add(m); 119 fail = false; 120 } 121 finally { 122 Utility.endTrans(fail); 123 } 124 assertFile("File is not correctly generated.", 125 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/indent/AnnIndentClass.java"), 126 getGoldenFile("testAddAnnotationWithMethod_AnnIndentTest.pass"), 127 getWorkDir() 128 ); 129 } 130 131 public void testAddAnnotationWithClass() throws java.io.IOException , FileStateInvalidException { 132 boolean fail = true; 133 Utility.beginTrans(true); 134 try { 135 MultipartId type1 = pkg.getMultipartId().createMultipartId("Deprecated()", null, Collections.EMPTY_LIST); 136 MultipartId type2 = pkg.getMultipartId().createMultipartId("Deprecated2()", null, Collections.EMPTY_LIST); 137 Annotation ann1 = pkg.getAnnotation().createAnnotation(type1, Collections.EMPTY_LIST); 138 Annotation ann2 = pkg.getAnnotation().createAnnotation(type2, Collections.EMPTY_LIST); 139 List annList = new ArrayList (); 140 annList.add(ann1); 141 annList.add(ann2); 142 JavaClass javaClass = pkg.getJavaClass().createJavaClass("SecondTop", annList, 0, null, null, Collections.EMPTY_LIST, null, Collections.EMPTY_LIST, Collections.EMPTY_LIST); 143 clazz.getResource().getClassifiers().add(javaClass); 144 fail = false; 145 } 146 finally { 147 Utility.endTrans(fail); 148 } 149 assertFile("File is not correctly generated.", 150 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/indent/AnnIndentClass.java"), 151 getGoldenFile("testAddAnnotationWithClass_AnnIndentTest.pass"), 152 getWorkDir() 153 ); 154 } 155 156 } 157 | Popular Tags |