1 19 20 package org.netbeans.jmi.javamodel.codegen; 21 22 import java.util.Collections ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 import junit.textui.TestRunner; 26 import org.netbeans.jmi.javamodel.*; 27 import org.netbeans.junit.NbTestCase; 28 import org.netbeans.junit.NbTestSuite; 29 import org.openide.filesystems.FileStateInvalidException; 30 31 35 public class EnumFacilityTest extends NbTestCase { 36 37 JavaClass clazz; 38 JavaModelPackage pkg; 39 40 41 public EnumFacilityTest() { 42 super("EnumFacilityTest"); 43 } 44 45 public static NbTestSuite suite() { 46 NbTestSuite suite = new NbTestSuite(EnumFacilityTest.class); 47 return suite; 48 } 49 50 protected void setUp() { 51 clazz = Utility.findClass("org.netbeans.test.codegen.EnumFacilityName"); 52 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 53 } 54 55 public void testAddConst() throws java.io.IOException , FileStateInvalidException { 56 boolean fail = true; 57 Utility.beginTrans(true); 58 try { 59 MultipartId par = pkg.getMultipartId().createMultipartId("\"rebirth\"", null, null); 60 EnumConstant enumConst = pkg.getEnumConstant().createEnumConstant( 61 "NASTASIYA", 62 null, 0, null, null, false, null, 0, par, null, null ); 73 ((JavaEnum) clazz.getContents().get(0)).getConstants().add(4, enumConst); 74 fail = false; 75 } 76 finally { 77 Utility.endTrans(fail); 78 } 79 assertFile("File is not correctly generated.", 80 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/EnumFacilityName.java"), 81 getGoldenFile("testAddConst_EnumFacilityName.pass"), 82 getWorkDir() 83 ); 84 } 85 86 public void testReorder() throws java.io.IOException , FileStateInvalidException { 87 boolean fail = true; 88 Utility.beginTrans(true); 89 try { 90 JavaEnum enumeration = (JavaEnum) clazz.getContents().get(0); 91 List constants = enumeration.getConstants(); 92 Object constant = constants.remove(0); 93 constants.add(4, constant); 94 fail = false; 95 } finally { 96 Utility.endTrans(fail); 97 } 98 assertFile("File is not correctly generated.", 99 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/EnumFacilityName.java"), 100 getGoldenFile("testReorder_EnumFacilityName.pass"), 101 getWorkDir() 102 ); 103 } 104 105 108 public static void main(String [] args) { 109 TestRunner.run(suite()); 110 } 111 } 112 | Popular Tags |