Bug 349706 - PreferencesTests rely on test ordering
diff --git a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/tests/AbstractApiTest.java b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/tests/AbstractApiTest.java
index ba2b9b0..ec9774a 100644
--- a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/tests/AbstractApiTest.java
+++ b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/tests/AbstractApiTest.java
@@ -79,6 +79,7 @@
*/
protected IApiComponent getProjectApiComponent(String projectname) {
IJavaProject project = getTestingJavaProject(projectname);
+ assertNotNull("the project " + projectname + " must exist", project);
IApiBaseline profile = ApiPlugin.getDefault().getApiBaselineManager().getWorkspaceBaseline();
assertNotNull("the workspace profile must exist", profile);
return profile.getApiComponent(project.getElementName());
diff --git a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/util/tests/ApiDescriptionProcessorTests.java b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/util/tests/ApiDescriptionProcessorTests.java
index be1560a..b0d1cfa 100644
--- a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/util/tests/ApiDescriptionProcessorTests.java
+++ b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/util/tests/ApiDescriptionProcessorTests.java
@@ -22,6 +22,7 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.AST;
@@ -40,6 +41,8 @@
import org.eclipse.pde.api.tools.internal.util.Signatures;
import org.eclipse.pde.api.tools.model.tests.TestSuiteHelper;
import org.eclipse.pde.api.tools.tests.AbstractApiTest;
+import org.eclipse.pde.api.tools.tests.util.FileUtils;
+import org.eclipse.pde.api.tools.tests.util.ProjectUtils;
import org.eclipse.pde.api.tools.ui.internal.ApiUIPlugin;
import org.eclipse.pde.api.tools.ui.internal.wizards.ApiToolingSetupRefactoring;
import org.eclipse.pde.api.tools.ui.internal.wizards.WizardMessages;
@@ -57,6 +60,14 @@
public class ApiDescriptionProcessorTests extends AbstractApiTest {
/**
+ * The source directory for the javadoc updating test source
+ */
+ private static String JAVADOC_SRC_DIR = null;
+ static {
+ JAVADOC_SRC_DIR = TestSuiteHelper.getPluginDirectoryPath().append("test-source").append("javadoc").toOSString();
+ }
+
+ /**
* Visitor used to inspect the 'after' class files once they have had tags
* added to ensure the tags as specified in the component.xml file were
* added.
@@ -176,7 +187,40 @@
private static IPath ROOT_PATH = TestSuiteHelper.getPluginDirectoryPath().append("test-source").append("javadoc");
private static File componentxml = new File(ROOT_PATH.append("component.xml").toOSString());
- private static IJavaProject project = null;
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ createProject(TESTING_PROJECT_NAME, null);
+ IJavaProject project = getTestingJavaProject(TESTING_PROJECT_NAME);
+ assertNotNull("The java project must have been created", project);
+ IPackageFragmentRoot srcroot = ProjectUtils.addSourceContainer(project, ProjectUtils.SRC_FOLDER);
+ assertNotNull("the src root must have been created", srcroot);
+
+ File src = new File(JAVADOC_SRC_DIR);
+ assertTrue("the source dir must exist", src.exists());
+ assertTrue("the source dir must be a directory", src.isDirectory());
+ assertNotNull("the srcroot for the test java project must not be null", srcroot);
+ FileUtils.importFilesFromDirectory(src, srcroot.getPath().append("javadoc"), new NullProgressMonitor());
+
+ ApiToolingSetupRefactoring refactoring = new ApiToolingSetupRefactoring();
+ CompositeChange change = new CompositeChange("Test");
+ createTagChanges(change, project, componentxml);
+ refactoring.addChange(change);
+ performRefactoring(refactoring);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ deleteProject(TESTING_PROJECT_NAME);
+ }
/**
* Tests that the component.xml file is parsed if it is provided in one of
@@ -197,31 +241,6 @@
}
/**
- * Tests getting the java project to use with these tests
- */
- public void testGetTestingProject() {
- project = getTestingJavaProject(TESTING_PROJECT_NAME);
- assertNotNull("the testing project must not be null", project);
- assertNotNull("the testing project must exist", project.exists());
- }
-
- /**
- * Tests the actual updating process, it should not fail
- */
- public void testProcessUpdate() {
- try {
- ApiToolingSetupRefactoring refactoring = new ApiToolingSetupRefactoring();
- CompositeChange change = new CompositeChange("Test");
- createTagChanges(change, project, componentxml);
- refactoring.addChange(change);
- performRefactoring(refactoring);
- }
- catch (CoreException e) {
- fail(e.getMessage());
- }
- }
-
- /**
* Creates all of the text edit changes collected from the processor. The collected edits are arranged as multi-edits
* for the one file that they belong to
* @param projectchange
@@ -270,8 +289,9 @@
* @param signature the signature of the member
* @param the tags we expect to see
*/
- protected void processUpdatedItem(String typename, String innertypename, String membername, String signature, String[] expectedtags) {
+ protected void processUpdatedItem(String typename, String innertypename, String membername, String signature, String[] expectedtags) throws Exception{
try {
+ IJavaProject project = getTestingJavaProject(TESTING_PROJECT_NAME);
IType type = project.findType("javadoc", typename);
assertNotNull("the type for javadoc." + typename + " must exist", type);
ASTParser parser = ASTParser.newParser(AST.JLS4);
@@ -289,7 +309,7 @@
* Tests the addition of a javadoc tag to a class. Uses
* <code>JavadocTestClass1</code>
*/
- public void testProcessClassAddition() {
+ public void testProcessClassAddition() throws Exception {
processUpdatedItem("JavadocTestClass1", null, null, null, new String[] {"@noinstantiate"});
}
@@ -297,7 +317,7 @@
* Tests the addition of a javadoc tag to a class that does not have a
* javadoc section yet Uses <code>JavadocTestClass7</code>
*/
- public void testProcessClassAdditionNoDocElement() {
+ public void testProcessClassAdditionNoDocElement() throws Exception {
processUpdatedItem("JavadocTestClass7", null, null, null, new String[] {"@noextend", "@noinstantiate"});
}
@@ -305,7 +325,7 @@
* Tests the addition of a javadoc tag to a method that does not have a
* javadoc section yet Uses <code>JavadocTestClass7</code>
*/
- public void testProcessMethodAdditionNoDocElement() {
+ public void testProcessMethodAdditionNoDocElement() throws Exception {
processUpdatedItem("JavadocTestClass7", null, "m1", "()V", new String[] {"@nooverride"});
}
@@ -313,7 +333,7 @@
* Tests the addition of a javadoc tag to a field that does not have a
* javadoc section yet Uses <code>JavadocTestClass7</code>
*/
- public void testProcessFieldAdditionNoDocElement() {
+ public void testProcessFieldAdditionNoDocElement() throws Exception {
processUpdatedItem("JavadocTestClass7", null, "f1", null, new String[] {"@noreference"});
}
@@ -321,7 +341,7 @@
* Tests the addition of a javadoc tag to an inner class. Uses
* <code>JavadocTestClass2</code>
*/
- public void testProcessInnerClassAddition() {
+ public void testProcessInnerClassAddition() throws Exception {
processUpdatedItem("JavadocTestClass2", "Inner", null, null, new String[] {"@noinstantiate"});
}
@@ -329,7 +349,7 @@
* Tests the addition of a javadoc tags to methods. Uses
* <code>JavadocTestClass3</code>
*/
- public void testProcessMethodAddition() {
+ public void testProcessMethodAddition() throws Exception {
processUpdatedItem("JavadocTestClass3", null, "m1", "()V", new String[] {"@nooverride"});
processUpdatedItem("JavadocTestClass3", null, "m2", "()V", new String[] {"@noreference"});
}
@@ -338,7 +358,7 @@
* Tests the addition of a javadoc tags to fields. Uses
* <code>JavadocTestClass4</code>
*/
- public void testProcessFieldAddition() {
+ public void testProcessFieldAddition() throws Exception {
processUpdatedItem("JavadocTestClass4", null, "f1", null, new String[] {"@noreference"});
processUpdatedItem("JavadocTestClass4", null, "f2", null, new String[] {"@noreference"});
}
@@ -347,7 +367,7 @@
* Tests the addition of a javadoc tags to methods in inner classes. Uses
* <code>JavadocTestClass6</code>
*/
- public void testProcessInnerMethodAddition() {
+ public void testProcessInnerMethodAddition() throws Exception {
processUpdatedItem("JavadocTestClass6", "Inner2", "m1", "()V", new String[] {"@nooverride"});
processUpdatedItem("JavadocTestClass6", "Inner2", "m2", "()V", new String[] {"@noreference"});
}
@@ -356,7 +376,7 @@
* Tests the addition of a javadoc tags to fields in inner classes. Uses
* <code>JavadocTestClass5</code>
*/
- public void testProcessInnerFieldAddition() {
+ public void testProcessInnerFieldAddition() throws Exception {
processUpdatedItem("JavadocTestClass5", "Inner2", "f1", null, new String[] {"@noreference"});
processUpdatedItem("JavadocTestClass5", "Inner2", "f2", null, new String[] {"@noreference"});
}
@@ -366,7 +386,7 @@
* Tests the case of bug 210786 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=210786)
* Uses <code>JavadocTestClass8</code>
*/
- public void testProcessSubclassAttribute() {
+ public void testProcessSubclassAttribute() throws Exception {
processUpdatedItem("JavadocTestClass8", null, null, null, new String[] {"@noextend"});
}
}
diff --git a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/util/tests/PreferencesTests.java b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/util/tests/PreferencesTests.java
index 15a0ad5..21f5cc0 100644
--- a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/util/tests/PreferencesTests.java
+++ b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/util/tests/PreferencesTests.java
@@ -26,11 +26,13 @@
*/
public class PreferencesTests extends AbstractApiTest {
- /**
- * Sets up a variety of preferences, including adding project specific preferences
- * to the test project
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
*/
- public void testSetupSettings() {
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
IEclipsePreferences inode = InstanceScope.INSTANCE.getNode(ApiPlugin.PLUGIN_ID);
assertNotNull("The instance node must exist", inode);
inode.put(IApiProblemTypes.ILLEGAL_INSTANTIATE, ApiPlugin.VALUE_ERROR);
@@ -40,7 +42,10 @@
fail(e1.getMessage());
}
+ createProject(TESTING_PROJECT_NAME, null);
+
IJavaProject project = getTestingJavaProject(TESTING_PROJECT_NAME);
+ assertNotNull("the testing project must not be null", project);
ProjectScope scope = new ProjectScope(project.getProject());
IEclipsePreferences eprefs = scope.getNode(ApiPlugin.PLUGIN_ID);
assertNotNull("The ApiPlugin section for project settings should be available", eprefs);
@@ -52,6 +57,15 @@
}
}
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ deleteProject(TESTING_PROJECT_NAME);
+ }
+
/**
* tests that the default preferences are set of the ApiPlugin
*/
diff --git a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/util/tests/ProjectCreationTests.java b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/util/tests/ProjectCreationTests.java
index 13e39f1..1ed7d44 100644
--- a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/util/tests/ProjectCreationTests.java
+++ b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/util/tests/ProjectCreationTests.java
@@ -14,7 +14,6 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -51,28 +50,27 @@
JAVADOC_SRC_DIR = getSourceDirectory("javadoc");
JAVADOC_READ_SRC_DIR = getSourceDirectory(new Path("a").append("b").append("c"));
}
-
- private static IJavaProject project = null;
- private static IPackageFragmentRoot srcroot = null;
-
- /**
- * Tests creating a new {@link IJavaProject} for the plugin test suite
- *
- * @throws Exception
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
*/
- public void testProjectCreation() throws Exception {
- // delete any pre-existing project
- IProject pro = ResourcesPlugin.getWorkspace().getRoot().getProject(TESTING_PROJECT_NAME);
- if (pro.exists()) {
- pro.delete(true, true, null);
- }
- // create project and import source
- project = ProjectUtils.createJavaProject(TESTING_PROJECT_NAME, null);
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ createProject(TESTING_PROJECT_NAME, null);
+ IJavaProject project = getTestingJavaProject(TESTING_PROJECT_NAME);
assertNotNull("The java project must have been created", project);
- srcroot = ProjectUtils.addSourceContainer(project, ProjectUtils.SRC_FOLDER);
- assertNotNull("the src root must have been created", srcroot);
}
-
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ deleteProject(TESTING_PROJECT_NAME);
+ }
+
/**
* Tests importing the java source for the Javadoc tag update tests
*/
@@ -81,29 +79,10 @@
File dest = new File(JAVADOC_SRC_DIR);
assertTrue("the source dir must exist", dest.exists());
assertTrue("the source dir must be a directory", dest.isDirectory());
+ IJavaProject project = getTestingJavaProject(TESTING_PROJECT_NAME);
+ IPackageFragmentRoot srcroot = project.getPackageFragmentRoot(ProjectUtils.SRC_FOLDER);
assertNotNull("the srcroot for the test java project must not be null", srcroot);
- FileUtils.importFilesFromDirectory(dest, srcroot.getPath().append("javadoc"), new NullProgressMonitor());
- //try to look up a file to test if it worked
- IType type = project.findType("javadoc.JavadocTestClass1", new NullProgressMonitor());
- assertNotNull("the JavadocTestClass1 type should exist in the javadoc package", type);
- }
- catch (Exception e) {
- fail(e.getMessage());
- }
- }
-
- /**
- * Tests importing the java source for the Javadoc tag update tests to compare
- * against. These source files are copies of originals prior to tag updating used for verification
- * that tags have been updated correctly.
- */
- public void testImportJavadocTestSourceOriginal() {
- try {
- File dest = new File(JAVADOC_SRC_DIR);
- assertTrue("the original source dir must exist", dest.exists());
- assertTrue("the original source dir must be a directory", dest.isDirectory());
- assertNotNull("the srcroot for the test java project must not be null", srcroot);
- FileUtils.importFilesFromDirectory(dest, srcroot.getPath().append("javadoc").append("orig"), new NullProgressMonitor());
+ FileUtils.importFilesFromDirectory(dest, project.getPath().append(srcroot.getPath()).append("javadoc"), new NullProgressMonitor());
//try to look up a file to test if it worked
IType type = project.findType("javadoc.JavadocTestClass1", new NullProgressMonitor());
assertNotNull("the JavadocTestClass1 type should exist in the javadoc package", type);
@@ -121,8 +100,10 @@
File dest = new File(JAVADOC_READ_SRC_DIR);
assertTrue("the source dir must exist", dest.exists());
assertTrue("the source dir must be a directory", dest.isDirectory());
+ IJavaProject project = getTestingJavaProject(TESTING_PROJECT_NAME);
+ IPackageFragmentRoot srcroot = project.getPackageFragmentRoot(ProjectUtils.SRC_FOLDER);
assertNotNull("the srcroot for the test java project must not be null", srcroot);
- FileUtils.importFilesFromDirectory(dest, srcroot.getPath().append("a").append("b").append("c"), new NullProgressMonitor());
+ FileUtils.importFilesFromDirectory(dest, project.getPath().append(srcroot.getPath()).append("a").append("b").append("c"), new NullProgressMonitor());
}
catch (Exception e) {
fail(e.getMessage());
@@ -134,7 +115,7 @@
*/
public void testCreatePluginProject() {
try {
- IJavaProject jproject = createPluginProject("test_plugin_project");
+ IJavaProject jproject = getTestingJavaProject(TESTING_PROJECT_NAME);
IProject project = jproject.getProject();
assertTrue("project must have the PDE nature", project.hasNature(PDE.PLUGIN_NATURE));
assertTrue("project must have the java nature", project.hasNature(JavaCore.NATURE_ID));
@@ -149,28 +130,7 @@
}
}
- /**
- * Proxy to creating a plugin project, which deletes any existing projects with the same name first
- * @param name
- * @return a new {@link IJavaProject} with the given name
- */
- private IJavaProject createPluginProject(String name) {
- IJavaProject jproject = null;
- try {
- // delete any pre-existing project
- IProject pro = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
- if (pro.exists()) {
- pro.delete(true, true, new NullProgressMonitor());
- }
- jproject = ProjectUtils.createPluginProject(name, new String[] {ApiPlugin.NATURE_ID});
- }
- catch(Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- return jproject;
- }
-
+
/**
* Finds the specified package export.
*
@@ -211,7 +171,7 @@
*/
public void testAddRawExportedPackage() throws CoreException {
String packagename = "org.eclipse.apitools.test";
- IJavaProject jproject = createPluginProject("test_plugin_project");
+ IJavaProject jproject = getTestingJavaProject(TESTING_PROJECT_NAME);
IProject project = jproject.getProject();
ProjectUtils.addExportedPackage(project, packagename, false, null);
IPackageExportDescription[] exports = ProjectUtils.getExportedPackages(project);
@@ -223,7 +183,7 @@
*/
public void testAddInternalExportedPackage() throws CoreException {
String packagename = "org.eclipse.apitools.test.internal";
- IJavaProject jproject = createPluginProject("test_plugin_project");
+ IJavaProject jproject = getTestingJavaProject(TESTING_PROJECT_NAME);
IProject project = jproject.getProject();
ProjectUtils.addExportedPackage(project, packagename, true, null);
IPackageExportDescription[] exports = ProjectUtils.getExportedPackages(project);
@@ -235,7 +195,7 @@
*/
public void testAddExternalPackageWithFriends() throws CoreException {
String packagename = "org.eclipse.apitools.test.4friends";
- IJavaProject jproject = createPluginProject("test_plugin_project");
+ IJavaProject jproject = getTestingJavaProject(TESTING_PROJECT_NAME);
IProject project = jproject.getProject();
ProjectUtils.addExportedPackage(project, packagename, false, new String[] {"F1", "F2", "F3", "F4"});
IPackageExportDescription[] exports = ProjectUtils.getExportedPackages(project);
@@ -246,7 +206,7 @@
* Tests adding more than one exported package
*/
public void testAddMultipleExportedPackages() throws CoreException {
- IJavaProject jproject = createPluginProject("test_plugin_project");
+ IJavaProject jproject = getTestingJavaProject(TESTING_PROJECT_NAME);
IProject project = jproject.getProject();
ProjectUtils.addExportedPackage(project, "org.eclipse.apitools.test.multi.friends", false, new String[] {"F1", "F2", "F3", "F4"});
ProjectUtils.addExportedPackage(project, "org.eclipse.apitools.test.multi.internal", true, null);
@@ -259,7 +219,7 @@
* Tests removing an exported package
*/
public void testRemoveExistingExportedPackage() throws CoreException {
- IJavaProject jproject = createPluginProject("test_plugin_project");
+ IJavaProject jproject = getTestingJavaProject(TESTING_PROJECT_NAME);
IProject project = jproject.getProject();
ProjectUtils.addExportedPackage(project, "org.eclipse.apitools.test.remove1", false, new String[] {"F1"});
ProjectUtils.addExportedPackage(project, "org.eclipse.apitools.test.remove2", true, null);
@@ -276,7 +236,7 @@
* Tests trying to remove a package that does not exist in the header
*/
public void testRemoveNonExistingExportedPackage() throws CoreException {
- IJavaProject jproject = createPluginProject("test_plugin_project");
+ IJavaProject jproject = getTestingJavaProject(TESTING_PROJECT_NAME);
IProject project = jproject.getProject();
ProjectUtils.addExportedPackage(project, "org.eclipse.apitools.test.removeA", false, new String[] {"F1"});
IPackageExportDescription[] exports = ProjectUtils.getExportedPackages(project);