1 19 package org.netbeans.jmi.javamodel.codegen; 20 21 import java.lang.reflect.Modifier ; 22 import java.util.Iterator ; 23 import junit.textui.TestRunner; 24 import org.netbeans.jmi.javamodel.*; 25 import org.netbeans.junit.NbTestCase; 26 import org.netbeans.junit.NbTestSuite; 27 import org.openide.filesystems.FileStateInvalidException; 28 29 33 public class EnumTest extends NbTestCase { 34 35 public EnumTest() { 36 super("EnumTest"); 37 } 38 39 public static NbTestSuite suite() { 40 NbTestSuite suite = new NbTestSuite(EnumTest.class); 41 return suite; 42 } 43 44 JavaEnum clazz; 45 JavaModelPackage pkg; 46 47 protected void setUp() { 48 clazz = (JavaEnum) Utility.findClass("org.netbeans.test.codegen.EnumTest"); 49 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 50 } 51 52 public void testAddConstant() throws java.io.IOException , FileStateInvalidException { 53 boolean fail = true; 54 Utility.beginTrans(true); 55 try { 56 EnumConstant literal = pkg.getEnumConstant().createEnumConstant("LITERAL4", null, 0, null, null, false, null, 0, null, null, null); 57 clazz.getConstants().add(literal); 58 fail = false; 59 } 60 finally { 61 Utility.endTrans(fail); 62 } 63 assertFile("File is not correctly generated.", 64 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/EnumTest.java"), 65 getGoldenFile("EnumTest.pass"), 66 getWorkDir() 67 ); 68 } 69 70 public void testNewEnum() throws java.io.IOException , FileStateInvalidException { 71 boolean fail = true; 72 Utility.beginTrans(true); 73 try { 74 JavaEnum javaEnum = pkg.getJavaEnum().createJavaEnum( 75 "InnerEnum", null, Modifier.PUBLIC, null, null, null, null, null, null, null ); 86 EnumConstant literal = pkg.getEnumConstant().createEnumConstant( 87 "FIRST_CONSTANT", 88 null, 89 0, 90 null, 91 null, 92 false, 93 null, 94 0, 95 null, 96 null, 97 null 98 ); 99 clazz.getContents().add(javaEnum); 100 javaEnum.getConstants().add(literal); 101 fail = false; 102 } 103 finally { 104 Utility.endTrans(fail); 105 } 106 assertFile("File is not correctly generated.", 107 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/EnumTest.java"), 108 getGoldenFile("testNewEnum_EnumTest.pass"), 109 getWorkDir() 110 ); 111 } 112 113 public void testNewEmptyEnum() throws java.io.IOException , FileStateInvalidException { 114 boolean fail = true; 115 Utility.beginTrans(true); 116 try { 117 JavaEnum javaEnum = pkg.getJavaEnum().createJavaEnum( 118 "InnerOriginallyEmptyEnum", null, Modifier.PUBLIC, null, null, null, null, null, null, null ); 129 clazz.getContents().add(javaEnum); 130 fail = false; 131 } 132 finally { 133 Utility.endTrans(fail); 134 } 135 assertFile("File is not correctly generated.", 136 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/EnumTest.java"), 137 getGoldenFile("testNewEmptyEnum_EnumTest.pass"), 138 getWorkDir() 139 ); 140 } 141 142 public void testAddConstantToEmptyEnum() throws java.io.IOException , FileStateInvalidException { 143 boolean fail = true; 144 Utility.beginTrans(true); 145 try { 146 JavaEnum javaEnum = (JavaEnum) clazz.getContents().get(1); 147 EnumConstant literal = pkg.getEnumConstant().createEnumConstant( 148 null, 149 null, 150 0, 151 null, 152 null, 153 false, 154 null, 155 0, 156 null, 157 null, 158 null 159 ); 160 literal.setName("TO_NEW_ENUM_CONSTANT"); 161 javaEnum.getConstants().add(literal); 162 fail = false; 163 } 164 finally { 165 Utility.endTrans(fail); 166 } 167 assertFile("File is not correctly generated.", 168 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/EnumTest.java"), 169 getGoldenFile("testAddConstantToEmptyEnum_EnumTest.pass"), 170 getWorkDir() 171 ); 172 } 173 174 177 public static void main(String [] args) { 178 TestRunner.run(suite()); 179 } 180 181 } 182 | Popular Tags |