1 19 20 package org.netbeans.jmi.javamodel.codegen; 21 22 import org.netbeans.junit.NbTestCase; 23 import org.netbeans.junit.NbTestSuite; 24 import org.netbeans.jmi.javamodel.JavaModelPackage; 25 import org.netbeans.jmi.javamodel.Import; 26 import org.netbeans.jmi.javamodel.Resource; 27 import org.netbeans.jmi.javamodel.JavaClass; 28 import java.io.IOException ; 29 import java.util.Iterator ; 30 import junit.textui.TestRunner; 31 import org.openide.filesystems.FileStateInvalidException; 32 33 39 public class StaticImportTest extends NbTestCase { 40 41 42 public StaticImportTest() { 43 super("StaticImportTest"); 44 } 45 46 public static NbTestSuite suite() { 47 NbTestSuite suite = new NbTestSuite(StaticImportTest.class); 48 return suite; 49 } 50 51 JavaModelPackage pkg; 52 JavaClass clazz; 53 Import arraysImport; 54 55 protected void setUp() { 56 clazz = Utility.findClass("org.netbeans.test.codegen.StaticImport"); 57 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 58 for (Iterator it = clazz.getResource().getImports().iterator(); it.hasNext(); ) { 59 arraysImport = (Import) it.next(); 60 } 61 } 62 63 public void testCreation() throws IOException , FileStateInvalidException { 64 boolean fail = true; 65 Utility.beginTrans(true); 66 try { 67 Resource res = clazz.getResource(); 68 Import i = pkg.getImport().createImport("java.util.Collections", null, true, false); 69 res.getImports().add(i); 70 fail = false; 71 } finally { 72 Utility.endTrans(fail); 73 } 74 assertFile("File is not correctly generated.", 75 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/StaticImport.java"), 76 getGoldenFile("testCreation_StaticImport.pass"), 77 getWorkDir() 78 ); 79 } 80 81 public void testCreation2() throws IOException , FileStateInvalidException { 82 boolean fail = true; 83 Utility.beginTrans(true); 84 try { 85 Resource res = clazz.getResource(); 86 arraysImport = pkg.getImport().createImport("java.util.Arrays", null, false, false); 87 res.getImports().add(arraysImport); 88 fail = false; 89 } finally { 90 Utility.endTrans(fail); 91 } 92 assertFile("File is not correctly generated.", 93 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/StaticImport.java"), 94 getGoldenFile("testCreation2_StaticImport.pass"), 95 getWorkDir() 96 ); 97 } 98 99 public void testSetStatic() throws IOException , FileStateInvalidException { 100 boolean fail = true; 101 Utility.beginTrans(true); 102 try { 103 arraysImport.setStatic(true); 104 fail = false; 105 } finally { 106 Utility.endTrans(fail); 107 } 108 assertFile("File is not correctly generated.", 109 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/StaticImport.java"), 110 getGoldenFile("testSetStatic_StaticImport.pass"), 111 getWorkDir() 112 ); 113 } 114 115 118 public static void main(String [] args) { 119 TestRunner.run(suite()); 120 } 121 } 122 | Popular Tags |