/* | |
* (c) Copyright IBM Corp. 2000, 2001. | |
* All Rights Reserved. | |
*/ | |
package org.eclipse.jdt.testplugin.test; | |
import junit.extensions.TestSetup; | |
import junit.framework.Test; | |
import junit.framework.TestCase; | |
import junit.framework.TestSuite; | |
import org.eclipse.core.runtime.Path; | |
import org.eclipse.jdt.core.ICompilationUnit; | |
import org.eclipse.jdt.core.IJavaProject; | |
import org.eclipse.jdt.core.IMethod; | |
import org.eclipse.jdt.core.IPackageFragment; | |
import org.eclipse.jdt.core.IPackageFragmentRoot; | |
import org.eclipse.jdt.core.IType; | |
import org.eclipse.jdt.testplugin.JavaProjectHelper; | |
import org.eclipse.jdt.testplugin.TestPluginLauncher; | |
public class JavaTestCase extends TestCase { | |
private IJavaProject fJavaProject; | |
public JavaTestCase(String name) { | |
super(name); | |
} | |
public static void main(String[] args) { | |
TestPluginLauncher.run(TestPluginLauncher.getLocationFromProperties(), JavaTestCase.class, args); | |
} | |
public static Test suite() { | |
TestSuite suite= new TestSuite(); | |
suite.addTest(new JavaTestCase("doTest1")); | |
return suite; | |
} | |
/** | |
* Creates a new test Java project. | |
*/ | |
protected void setUp() throws Exception { | |
fJavaProject= JavaProjectHelper.createJavaProject("HelloWorldProject", "bin"); | |
IPackageFragmentRoot root= JavaProjectHelper.addSourceContainer(fJavaProject, "src"); | |
IPackageFragment pack= root.createPackageFragment("ibm.util", true, null); | |
ICompilationUnit cu= pack.getCompilationUnit("A.java"); | |
IType type= cu.createType("public class A {\n}\n", null, true, null); | |
type.createMethod("public void a() {}\n", null, true, null); | |
type.createMethod("public void b(java.util.Vector v) {}\n", null, true, null); | |
} | |
/** | |
* Removes the test java project. | |
*/ | |
protected void tearDown () throws Exception { | |
JavaProjectHelper.delete(fJavaProject); | |
} | |
/* | |
* Basic test: Checks for created methods. | |
*/ | |
public void doTest1() throws Exception { | |
String name= "ibm/util/A.java"; | |
ICompilationUnit cu= (ICompilationUnit) fJavaProject.findElement(new Path(name)); | |
assertTrue("A.java must exist", cu != null); | |
IType type= cu.getType("A"); | |
assertTrue("Type A must exist", type != null); | |
System.out.println("methods of A"); | |
IMethod[] methods= type.getMethods(); | |
for (int i= 0; i < methods.length; i++) { | |
System.out.println(methods[i].getElementName()); | |
} | |
assertTrue("Should contain 2 methods", methods.length == 2); | |
} | |
} |