1 19 package org.netbeans.jmi.javamodel.codegen.indent; 20 21 import java.io.IOException ; 22 import org.netbeans.jmi.javamodel.JavaClass; 23 import org.netbeans.jmi.javamodel.JavaModelPackage; 24 import org.netbeans.jmi.javamodel.codegen.Utility; 25 import org.netbeans.junit.NbTestCase; 26 import org.netbeans.junit.NbTestSuite; 27 import org.netbeans.modules.javacore.jmiimpl.javamodel.MethodImpl; 28 import org.openide.filesystems.FileStateInvalidException; 29 30 34 public class MoveElementsTest extends NbTestCase { 35 36 JavaClass sourceClass, destClass; 37 JavaModelPackage pkg; 38 39 40 public MoveElementsTest(String s) { 41 super(s); 42 } 43 44 public static NbTestSuite suite() { 45 NbTestSuite suite = new NbTestSuite(); 46 suite.addTest(new MoveElementsTest("testMoveAlois")); 47 suite.addTest(new MoveElementsTest("testMoveLojza")); 48 suite.addTest(new MoveElementsTest("testMoveGianluigi")); 49 suite.addTest(new MoveElementsTest("testMoveCall")); 50 return suite; 51 } 52 53 protected void setUp() { 54 sourceClass = (JavaClass) Utility.findClass("org.netbeans.test.codegen.indent.GarbageClass"); 55 destClass = (JavaClass) Utility.findClass("org.netbeans.test.codegen.indent.TrashClass.FirstTrash"); 56 pkg = (JavaModelPackage) sourceClass.refImmediatePackage(); 57 } 58 59 public void testMoveAlois() throws IOException , FileStateInvalidException { 60 boolean fail = true; 61 Utility.beginTrans(true); 62 try { 63 MethodImpl m = (MethodImpl) sourceClass.getContents().remove(0); 64 destClass.getContents().add(m); 65 m.fixImports(destClass, m); 66 fail = false; 67 } 68 finally { 69 Utility.endTrans(fail); 70 } 71 assertFile("File is not correctly generated.", 72 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/indent/TrashClass.java"), 73 getGoldenFile("testMoveAlois_MoveElementsTest.pass"), 74 getWorkDir() 75 ); 76 } 77 78 public void testMoveLojza() throws IOException , FileStateInvalidException { 79 boolean fail = true; 80 Utility.beginTrans(true); 81 try { 82 MethodImpl m = (MethodImpl) sourceClass.getContents().remove(0); 83 destClass.getContents().add(m); 84 m.fixImports(destClass, m); 85 fail = false; 86 } 87 finally { 88 Utility.endTrans(fail); 89 } 90 assertFile("File is not correctly generated.", 91 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/indent/TrashClass.java"), 92 getGoldenFile("testMoveLojza_MoveElementsTest.pass"), 93 getWorkDir() 94 ); 95 } 96 97 public void testMoveGianluigi() throws IOException , FileStateInvalidException { 98 boolean fail = true; 99 Utility.beginTrans(true); 100 try { 101 MethodImpl m = (MethodImpl) sourceClass.getContents().remove(0); 102 destClass.getContents().add(0, m); 103 m.fixImports(destClass, m); 104 fail = false; 105 } 106 finally { 107 Utility.endTrans(fail); 108 } 109 assertFile("File is not correctly generated.", 110 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/indent/TrashClass.java"), 111 getGoldenFile("testMoveGianluigi_MoveElementsTest.pass"), 112 getWorkDir() 113 ); 114 } 115 116 public void testMoveCall() throws IOException , FileStateInvalidException { 117 boolean fail = true; 118 Utility.beginTrans(true); 119 try { 120 MethodImpl m = (MethodImpl) sourceClass.getContents().remove(0); 121 destClass.getContents().add(m); 122 m.fixImports(destClass, m); 123 fail = false; 124 } 125 finally { 126 Utility.endTrans(fail); 127 } 128 assertFile("File is not correctly generated.", 129 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/indent/TrashClass.java"), 130 getGoldenFile("testMoveCall_MoveElementsTest.pass"), 131 getWorkDir() 132 ); 133 } 134 } 135 | Popular Tags |