1 19 24 25 package org.netbeans.jmi.javamodel.codegen; 26 27 import java.io.IOException ; 28 import java.lang.reflect.Modifier ; 29 import java.util.ArrayList ; 30 import java.util.List ; 31 import org.netbeans.jmi.javamodel.Field; 32 import org.netbeans.jmi.javamodel.FieldGroup; 33 import org.netbeans.jmi.javamodel.JavaClass; 34 import org.netbeans.jmi.javamodel.JavaModelPackage; 35 import org.netbeans.jmi.javamodel.MultipartId; 36 import org.netbeans.junit.NbTestCase; 37 import org.netbeans.junit.NbTestSuite; 38 import org.openide.filesystems.FileStateInvalidException; 39 40 44 public class GroupTest2 extends NbTestCase { 45 46 47 public GroupTest2() { 48 super("GroupTest2"); 49 } 50 51 public static NbTestSuite suite() { 52 NbTestSuite suite = new NbTestSuite(GroupTest2.class); 53 return suite; 54 } 55 56 JavaClass clazz; 57 JavaModelPackage pkg; 58 59 protected void setUp() { 60 clazz = Utility.findClass("org.netbeans.test.codegen.GroupTest2Class"); 61 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 62 } 63 64 68 public void testGroupCreation() throws IOException , FileStateInvalidException { 69 boolean fail = true; 70 Utility.beginTrans(true); 71 try { 72 List fields = new ArrayList (4); 73 String [] fieldNames = { "chicco", "lego", "fisherPrice", "disney" }; 74 String [] fieldInitials = { null, null, "\"nice\"", null }; 75 for (int i = 0; i < 4; i++) { 76 MultipartId id = pkg.getMultipartId().createMultipartId("String", null, null); 77 fields.add(pkg.getField().createField( 78 fieldNames[i], 79 null, 80 Modifier.PUBLIC, 81 null, 82 null, 83 false, 84 id, 85 0, 86 null, 87 fieldInitials[i] 88 )); 89 }; 90 MultipartId id = pkg.getMultipartId().createMultipartId("String", null, null); 91 clazz.getContents().add(pkg.getFieldGroup().createFieldGroup( 92 null, 93 null, 94 Modifier.PUBLIC, 95 null, 96 null, 97 id, 98 fields 99 )); 100 fail = false; 101 } 102 finally { 103 Utility.endTrans(fail); 104 } 105 assertFile("File is not correctly generated.", 106 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/GroupTest2Class.java"), 107 getGoldenFile("testGroupCreation_GroupTest2Class.pass"), 108 getWorkDir() 109 ); 110 } 111 112 116 public void testGroupSplit1() throws IOException , FileStateInvalidException { 117 boolean fail = true; 118 Utility.beginTrans(true); 119 try { 120 FieldGroup group = (FieldGroup) clazz.getContents().get(1); 121 ((Field) group.getFields().get(2)).setModifiers(Modifier.PRIVATE); 122 fail = false; 123 } 124 finally { 125 Utility.endTrans(fail); 126 } 127 assertFile("File is not correctly generated.", 128 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/GroupTest2Class.java"), 129 getGoldenFile("testGroupSplit1_GroupTest2Class.pass"), 130 getWorkDir() 131 ); 132 } 133 134 137 public void testGroupSplit2() throws IOException , FileStateInvalidException { 138 boolean fail = true; 139 Utility.beginTrans(true); 140 try { 141 MultipartId id = pkg.getMultipartId().createMultipartId("long", null, null); 142 FieldGroup group = (FieldGroup) clazz.getContents().get(0); 143 ((Field) group.getFields().get(2)).setTypeName(id); 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/GroupTest2Class.java"), 151 getGoldenFile("testGroupSplit2_GroupTest2Class.pass"), 152 getWorkDir() 153 ); 154 } 155 156 159 public static void main(String [] args) { 160 } 161 162 } 163 | Popular Tags |