From 4709fe24c6da85971c7c8218c401497c28cf0396 Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Fri, 8 Dec 2023 17:02:31 +0100 Subject: [PATCH] Migrate all tests in o.e.c.tests.internal.resources to JUnit 4 #903 * Remove ResourceTest class hierarchy * Add @Test annotations * Remove obsolete assertion methods Contributes to https://github.com/eclipse-platform/eclipse.platform/issues/903 --- .../resources/AllInternalResourcesTests.java | 14 +++-- .../internal/resources/Bug544975Test.java | 14 ++++- .../ModelObjectReaderWriterTest.java | 56 +++++++++++++------ .../resources/ProjectBuildConfigsTest.java | 19 +++++-- .../ProjectDynamicReferencesTest.java | 25 ++++++--- .../resources/ProjectPreferencesTest.java | 51 +++++++++++++++-- .../resources/ProjectReferencesTest.java | 20 +++++-- .../internal/resources/ResourceInfoTest.java | 56 +++++-------------- .../resources/WorkspaceConcurrencyTest.java | 14 ++++- 9 files changed, 183 insertions(+), 86 deletions(-) diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/AllInternalResourcesTests.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/AllInternalResourcesTests.java index 971fbb0db01..7d2c5a0367a 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/AllInternalResourcesTests.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/AllInternalResourcesTests.java @@ -22,9 +22,15 @@ * in this test package. */ @RunWith(Suite.class) -@Suite.SuiteClasses({ ModelObjectReaderWriterTest.class, ProjectPreferencesTest.class, - ResourceInfoTest.class, - WorkspaceConcurrencyTest.class, WorkspacePreferencesTest.class, ProjectReferencesTest.class, - ProjectDynamicReferencesTest.class, ProjectBuildConfigsTest.class, Bug544975Test.class, }) +@Suite.SuiteClasses({ // + Bug544975Test.class, // + ModelObjectReaderWriterTest.class, // + ProjectBuildConfigsTest.class, // + ProjectDynamicReferencesTest.class, // + ProjectPreferencesTest.class, // + ProjectReferencesTest.class, // + ResourceInfoTest.class, // + WorkspaceConcurrencyTest.class, // + WorkspacePreferencesTest.class, }) public class AllInternalResourcesTests { } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/Bug544975Test.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/Bug544975Test.java index b5ecb647b7b..18993a65d0f 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/Bug544975Test.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/Bug544975Test.java @@ -15,6 +15,8 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.nio.file.Files; @@ -30,10 +32,16 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; -import org.eclipse.core.tests.resources.ResourceTest; +import org.eclipse.core.tests.resources.WorkspaceTestRule; +import org.junit.Rule; +import org.junit.Test; -public class Bug544975Test extends ResourceTest { +public class Bug544975Test { + @Rule + public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + + @Test public void testBug544975ProjectOpenBackgroundRefresh() throws Exception { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject("Bug544975"); @@ -73,6 +81,7 @@ public void testBug544975ProjectOpenBackgroundRefresh() throws Exception { } } + @Test public void testBug544975ProjectOpenWithoutBackgroundRefresh() throws Exception { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject("Bug544975"); @@ -111,4 +120,5 @@ private IFile createFile(IProject project, String fileName, String initialConten file.setContents(stream, IResource.FORCE, new NullProgressMonitor()); return file; } + } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ModelObjectReaderWriterTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ModelObjectReaderWriterTest.java index def12ee3143..a1bfce30d46 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ModelObjectReaderWriterTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ModelObjectReaderWriterTest.java @@ -16,6 +16,8 @@ package org.eclipse.core.tests.internal.resources; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; +import static org.eclipse.core.tests.harness.FileSystemHelper.getRandomLocation; +import static org.eclipse.core.tests.harness.FileSystemHelper.getTempDir; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInputStream; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromFileSystem; @@ -57,10 +59,16 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform.OS; -import org.eclipse.core.tests.resources.ResourceTest; +import org.eclipse.core.tests.resources.WorkspaceTestRule; +import org.junit.Rule; +import org.junit.Test; import org.xml.sax.InputSource; -public class ModelObjectReaderWriterTest extends ResourceTest { +public class ModelObjectReaderWriterTest { + + @Rule + public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + static final IPath LONG_LOCATION = IPath.fromOSString("/eclipse/dev/i0218/eclipse/pffds/fds//fds///fdsfsdfsd///fdsfdsf/fsdfsdfsd/lugi/dsds/fsd//f/ffdsfdsf/fsdfdsfsd/fds//fdsfdsfdsf/fdsfdsfds/fdsfdsfdsf/fdsfdsfdsds/ns/org.eclipse.help.ui_2.1.0/contexts.xml").setDevice(OS.isWindows() ? "D:" : null); static final URI LONG_LOCATION_URI = LONG_LOCATION.toFile().toURI(); private static final String PATH_STRING = IPath.fromOSString("/abc/def").setDevice(OS.isWindows() ? "D:" : null).toString(); @@ -282,6 +290,7 @@ private ProjectDescription readDescription(IFileStore store) throws CoreExceptio * Verifies that project description file is written in a consistent way. * (bug 177148) */ + @Test public void testConsistentWrite() throws Throwable { String locationA = getTempDir().append("testPath1").toPortableString(); String locationB = getTempDir().append("testPath1").toPortableString(); @@ -289,7 +298,7 @@ public void testConsistentWrite() throws Throwable { String expected = "" + newline + "" + newline + " MyProjectDescription" + newline + " " + newline + " " + newline + " " + newline + " " + newline + " " + newline + " MyCommand" + newline + " " + newline + " " + newline + " aA" + newline + " 2 x ARGH!" + newline + " " + newline + " " + newline + " b" + newline + " ARGH!" + newline + " " + newline + " " + newline + " " + newline + " " + newline + " " + newline + " " + newline + " " + newline + " " + newline + " pathA" + newline + " 2" + newline + " " + locationA + "" + newline + " " + newline + " " + newline + " pathB" + newline + " 2" + newline + " " + locationB + "" + newline + " " + newline + " " + newline + "" + newline; - IFileStore tempStore = getTempStore(); + IFileStore tempStore = workspaceRule.getTempStore(); URI location = tempStore.toURI(); ProjectDescription description = new ProjectDescription(); @@ -320,13 +329,14 @@ public void testConsistentWrite() throws Throwable { assertThat(result, is(expected)); } + @Test public void testInvalidProjectDescription1() throws Throwable { String invalidProjectDescription = "\n" + "\n" + " abc\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " org.eclipse.jdt.core.javabuilder\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " org.eclipse.jdt.core.javanature\n" + " \n" + " \n" + " \n" + " newLink\n" + " 2\n" + " " + PATH_STRING + "\n" + " \n" + " \n" + ""; IWorkspace workspace = getWorkspace(); IPath root = workspace.getRoot().getLocation(); IPath location = root.append("ModelObjectReaderWriterTest.txt"); - deleteOnTearDown(location); + workspaceRule.deleteOnTearDown(location); ProjectDescriptionReader reader = new ProjectDescriptionReader(workspace); // Write out the project description file @@ -338,10 +348,11 @@ public void testInvalidProjectDescription1() throws Throwable { assertThat(projDesc, nullValue()); } + @Test public void testInvalidProjectDescription2() throws Throwable { String invalidProjectDescription = "\n" + "\n" + " abc\n" + ""; - IFileStore store = getTempStore(); + IFileStore store = workspaceRule.getTempStore(); // Write out the project description file try (OutputStream output = store.openOutputStream(EFS.NONE, null)) { createInputStream(invalidProjectDescription).transferTo(output); @@ -357,10 +368,11 @@ public void testInvalidProjectDescription2() throws Throwable { assertThat(projDesc.getLinks(), nullValue()); } + @Test public void testInvalidProjectDescription3() throws Throwable { String invalidProjectDescription = "\n" + "\n" + " abc\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " org.eclipse.jdt.core.javabuilder\n" + " \n" + " \n" + " \n" + " \n" + ""; - IFileStore store = getTempStore(); + IFileStore store = workspaceRule.getTempStore(); // Write out the project description file try (OutputStream output = store.openOutputStream(EFS.NONE, null)) { createInputStream(invalidProjectDescription).transferTo(output); @@ -377,10 +389,11 @@ public void testInvalidProjectDescription3() throws Throwable { assertThat(projDesc.getLinks(), nullValue()); } + @Test public void testInvalidProjectDescription4() throws Throwable { String invalidProjectDescription = "\n" + "\n" + " abc\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " newLink\n" + " foobar\n" + " " + PATH_STRING + "\n" + " \n" + " \n" + ""; - IFileStore store = getTempStore(); + IFileStore store = workspaceRule.getTempStore(); // Write out the project description file try (OutputStream output = store.openOutputStream(EFS.NONE, null)) { createInputStream(invalidProjectDescription).transferTo(output); @@ -401,11 +414,12 @@ public void testInvalidProjectDescription4() throws Throwable { /** * Tests a project description with a very long local location for a linked resource. */ + @Test public void testLongProjectDescription() throws Throwable { String longProjectDescription = getLongDescription(); IPath location = getRandomLocation(); - deleteOnTearDown(location); + workspaceRule.deleteOnTearDown(location); ProjectDescriptionReader reader = new ProjectDescriptionReader(getWorkspace()); // Write out the project description file @@ -424,10 +438,11 @@ public void testLongProjectDescription() throws Throwable { /** * Tests a project description with a very long URI location for linked resource. */ + @Test public void testLongProjectDescriptionURI() throws Throwable { String longProjectDescription = getLongDescriptionURI(); IPath location = getRandomLocation(); - deleteOnTearDown(location); + workspaceRule.deleteOnTearDown(location); ProjectDescriptionReader reader = new ProjectDescriptionReader(ResourcesPlugin.getWorkspace()); // Write out the project description file @@ -443,6 +458,7 @@ public void testLongProjectDescriptionURI() throws Throwable { } } + @Test public void testMultiLineCharFields() throws Throwable { String multiLineProjectDescription = "\n" + "\n" + " \n" + " abc\n" + " \n" + " \n" + " ISO-8859-1\n" + " \n" + " This is the comment.\n" + " \n" + " \n" + " org.eclipse.core.boot\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " org.eclipse.jdt.core.javabuilder\n" + " \n" + " \n" + " thisIsTheKey\n" + " thisIsTheValue\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " org.eclipse.jdt.core.javanature\n" + " \n" + " \n" + " \n" + " \n" + " " + "newLink" + "\n" + " \n" + " 2\n" + " \n" + " " + PATH_STRING + "\n" + " \n" + " \n" + ""; @@ -453,9 +469,9 @@ public void testMultiLineCharFields() throws Throwable { IWorkspace workspace = getWorkspace(); IPath root = workspace.getRoot().getLocation(); IPath multiLocation = root.append("multiLineTest.txt"); - deleteOnTearDown(multiLocation); + workspaceRule.deleteOnTearDown(multiLocation); IPath singleLocation = root.append("singleLineTest.txt"); - deleteOnTearDown(singleLocation); + workspaceRule.deleteOnTearDown(singleLocation); ProjectDescriptionReader reader = new ProjectDescriptionReader(workspace); // Write out the project description file @@ -472,6 +488,7 @@ public void testMultiLineCharFields() throws Throwable { compareProjectDescriptions(1, multiDesc, singleDesc); } + @Test public void testMultipleProjectDescriptions() throws Throwable { URL whereToLook = Platform.getBundle("org.eclipse.core.tests.resources").getEntry("MultipleProjectTestFiles/"); String[] members = {"abc.project", "def.project", "org.apache.lucene.project", "org.eclipse.ant.core.project"}; @@ -489,9 +506,9 @@ public void testMultipleProjectDescriptions() throws Throwable { } } + @Test public void testProjectDescription() throws Throwable { - - IFileStore tempStore = getTempStore(); + IFileStore tempStore = workspaceRule.getTempStore(); URI location = tempStore.toURI(); /* test write */ ProjectDescription description = new ProjectDescription(); @@ -532,13 +549,14 @@ public void testProjectDescription() throws Throwable { assertThat(commands2[0].getArguments().get("EmptyArg"), emptyString()); } + @Test public void testProjectDescription2() throws Throwable { // Use ModelObject2 to read the project description /* initialize common objects */ ModelObjectWriter writer = new ModelObjectWriter(); ProjectDescriptionReader reader = new ProjectDescriptionReader(getWorkspace()); - IFileStore tempStore = getTempStore(); + IFileStore tempStore = workspaceRule.getTempStore(); URI location = tempStore.toURI(); /* test write */ ProjectDescription description = new ProjectDescription(); @@ -589,8 +607,9 @@ public void testProjectDescription2() throws Throwable { } // see bug 274437 + @Test public void testProjectDescription3() throws Throwable { - IFileStore tempStore = getTempStore(); + IFileStore tempStore = workspaceRule.getTempStore(); URI location = tempStore.toURI(); /* test write */ ProjectDescription description = new ProjectDescription(); @@ -615,9 +634,9 @@ public void testProjectDescription3() throws Throwable { assertThat(commands2[0].getArguments(), anEmptyMap()); } + @Test public void testProjectDescriptionWithSpaces() throws Throwable { - - IFileStore store = getTempStore(); + IFileStore store = workspaceRule.getTempStore(); IPath path = IPath.fromOSString("link"); URI location = store.toURI(); URI locationWithSpaces = store.getChild("With some spaces").toURI(); @@ -650,6 +669,7 @@ private void writeDescription(IFileStore store, ProjectDescription description) } // Regression for Bug 300669 + @Test public void testProjectDescriptionWithFiltersAndNullProject() throws Exception { String projectDescription = "\n" + // "\n" + // @@ -679,7 +699,7 @@ public void testProjectDescriptionWithFiltersAndNullProject() throws Exception { IPath root = getWorkspace().getRoot().getLocation(); IPath location = root.append("ModelObjectReaderWriterTest.txt"); - deleteOnTearDown(location); + workspaceRule.deleteOnTearDown(location); ProjectDescriptionReader reader = new ProjectDescriptionReader(getWorkspace()); // Write out the project description file diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectBuildConfigsTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectBuildConfigsTest.java index 5881195eac7..d2f0d511a0d 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectBuildConfigsTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectBuildConfigsTest.java @@ -25,12 +25,18 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.tests.resources.ResourceTest; +import org.eclipse.core.tests.resources.WorkspaceTestRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; /** * Tests configuration project build configuration on the project description */ -public class ProjectBuildConfigsTest extends ResourceTest { +public class ProjectBuildConfigsTest { + + @Rule + public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); private IProject project; private static final String variantId0 = "Variant0"; @@ -41,9 +47,8 @@ public class ProjectBuildConfigsTest extends ResourceTest { private IBuildConfiguration variant2; private IBuildConfiguration defaultVariant; - @Override + @Before public void setUp() throws Exception { - super.setUp(); project = getWorkspace().getRoot().getProject("ProjectBuildConfigsTest_Project"); createInWorkspace(new IProject[] {project}); variant0 = new BuildConfiguration(project, variantId0); @@ -52,6 +57,7 @@ public void setUp() throws Exception { defaultVariant = new BuildConfiguration(project, IBuildConfiguration.DEFAULT_CONFIG_NAME); } + @Test public void testBasics() throws CoreException { IProjectDescription desc = project.getDescription(); String[] configs = new String[] {variantId0, variantId1}; @@ -84,6 +90,7 @@ public void testBasics() throws CoreException { assertThat(variant.getName(), is(variantId0)); } + @Test public void testDuplicates() throws CoreException { IProjectDescription desc = project.getDescription(); desc.setBuildConfigs(new String[] {variantId0, variantId1, variantId0}); @@ -91,6 +98,7 @@ public void testDuplicates() throws CoreException { assertThat(project.getBuildConfigs(), arrayContaining(variant0, variant1)); } + @Test public void testDefaultVariant() throws CoreException { IProjectDescription desc = project.getDescription(); desc.setBuildConfigs(new String[] {}); @@ -107,6 +115,7 @@ public void testDefaultVariant() throws CoreException { assertThat(project.getActiveBuildConfig(), is(defaultVariant)); } + @Test public void testRemoveActiveVariant() throws CoreException { IProjectDescription desc = project.getDescription(); desc.setBuildConfigs(new String[0]); @@ -127,6 +136,7 @@ public void testRemoveActiveVariant() throws CoreException { /** * Tests that build configuration references are correct after moving a project */ + @Test public void testProjectMove() throws CoreException { IProjectDescription desc = project.getDescription(); IBuildConfiguration[] configs = new IBuildConfiguration[] {variant0, variant1}; @@ -148,4 +158,5 @@ public void testProjectMove() throws CoreException { assertThat("unexpected project name at index " + i, newConfigs[i].getName(), is(configs[i].getName())); } } + } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectDynamicReferencesTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectDynamicReferencesTest.java index 9e339e6ffb4..03bf61a1bf7 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectDynamicReferencesTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectDynamicReferencesTest.java @@ -36,23 +36,30 @@ import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.tests.resources.ResourceTest; +import org.eclipse.core.tests.resources.WorkspaceTestRule; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; /** * Test project dynamic references provided by extension point * org.eclipse.core.resources.builders and dynamicReference * {@link IDynamicReferenceProvider} */ -public class ProjectDynamicReferencesTest extends ResourceTest { +public class ProjectDynamicReferencesTest { + + @Rule + public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + private static final String PROJECT_0_NAME = "ProjectDynamicReferencesTest_p0"; private IProject project0; private IProject project1; private IProject project2; - @Override + @Before public void setUp() throws Exception { - super.setUp(); project0 = getWorkspace().getRoot().getProject(PROJECT_0_NAME); project1 = getWorkspace().getRoot().getProject("ProjectDynamicReferencesTest_p1"); project2 = getWorkspace().getRoot().getProject("ProjectDynamicReferencesTest_p2"); @@ -62,12 +69,12 @@ public void setUp() throws Exception { updateProjectDescription(project2).addingCommand(Builder.NAME).apply(); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { DynamicReferenceProvider.clear(); } + @Test public void testReferencedProjects() throws CoreException { assertThat("Project0 must not have referenced projects", project0.getReferencedProjects(), emptyArray()); assertThat("Project1 must not have referenced projects", project1.getReferencedProjects(), emptyArray()); @@ -111,6 +118,7 @@ public void testReferencedProjects() throws CoreException { assertThat("Project2 must not have referenced projects", project2.getReferencedProjects(), emptyArray()); } + @Test public void testReferencedBuildConfigs() throws CoreException { assertThat("Project0 must not have referenced projects", project0.getReferencedBuildConfigs(IBuildConfiguration.DEFAULT_CONFIG_NAME, false), emptyArray()); @@ -136,6 +144,7 @@ public void testReferencedBuildConfigs() throws CoreException { project2.getReferencedBuildConfigs(IBuildConfiguration.DEFAULT_CONFIG_NAME, false), emptyArray()); } + @Test public void testReferencingProjects() throws CoreException { assertThat("Project0 must not have referencing projects", project0.getReferencingProjects(), emptyArray()); assertThat("Project1 must not have referencing projects", project1.getReferencingProjects(), emptyArray()); @@ -186,6 +195,7 @@ public void testReferencingProjects() throws CoreException { arrayContaining(project0, project1)); } + @Test public void testComputeProjectOrder() throws CoreException { IProject[] allProjects = new IProject[] { project0, project1, project2 }; @@ -217,6 +227,7 @@ public void testComputeProjectOrder() throws CoreException { assertThat("Project order should not have cycles: " + projectOrder, !projectOrder.hasCycles); } + @Test public void testBug543776() throws Exception { IFile projectFile = project0.getFile(IProjectDescription.DESCRIPTION_FILE_NAME); String projectDescription = readStringInFileSystem(projectFile); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectPreferencesTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectPreferencesTest.java index 29fc0000df3..c313cf14879 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectPreferencesTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectPreferencesTest.java @@ -25,6 +25,12 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -65,14 +71,19 @@ import org.eclipse.core.runtime.preferences.IPreferencesService; import org.eclipse.core.runtime.preferences.IScopeContext; import org.eclipse.core.runtime.preferences.InstanceScope; -import org.eclipse.core.tests.resources.ResourceTest; +import org.eclipse.core.tests.resources.WorkspaceTestRule; +import org.junit.Rule; +import org.junit.Test; import org.osgi.service.prefs.BackingStoreException; import org.osgi.service.prefs.Preferences; /** * @since 3.0 */ -public class ProjectPreferencesTest extends ResourceTest { +public class ProjectPreferencesTest { + + @Rule + public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); private static final String DIR_NAME = ".settings"; private static final String FILE_EXTENSION = "prefs"; @@ -120,6 +131,7 @@ public void preferenceChange(PreferenceChangeEvent event) { } } + @Test public void testSimple() throws CoreException { IProject project = getProject("foo"); String qualifier = "org.eclipse.core.tests.resources"; @@ -212,6 +224,7 @@ public void testSimple() throws CoreException { } } + @Test public void testListener() throws Exception { // setup IProject project = getProject(createUniqueString()); @@ -270,6 +283,7 @@ public void testListener() throws Exception { /** * Regression test for bug 60896 - Project preferences remains when deleting/creating project */ + @Test public void testProjectDelete() throws Exception { // create the project IProject project = getProject(createUniqueString()); @@ -298,6 +312,7 @@ public void testProjectDelete() throws Exception { } /** See bug 91244, bug 93398 and bug 211006. */ + @Test public void testProjectMove() throws Exception { IProject project1 = getProject(createUniqueString()); IProject project2 = getProject(createUniqueString()); @@ -336,6 +351,7 @@ public void testProjectMove() throws Exception { * directly to disk. We need to convert to use Resource APIs so changes * show up in the workspace immediately. */ + @Test public void test_60925() throws Exception { // setup IProject project = getProject(createUniqueString()); @@ -367,6 +383,7 @@ public void test_60925() throws Exception { * * Problems with a dot "." as a key name */ + @Test public void test_55410() throws Exception { IProject project1 = getProject(createUniqueString()); createInWorkspace(project1); @@ -397,6 +414,7 @@ public void test_55410() throws Exception { * Investigate what happens with project preferences when the * project is moved. */ + @Test public void test_61277a() throws Exception { IProject project = getProject(createUniqueString()); IProject destProject = getProject(createUniqueString()); @@ -427,6 +445,7 @@ public void test_61277a() throws Exception { * Investigate what happens with project preferences when the * project is moved. */ + @Test public void test_61277b() throws Exception { IProject project1 = getProject(createUniqueString()); IProject project2 = getProject(createUniqueString()); @@ -451,6 +470,7 @@ public void test_61277b() throws Exception { * * Problems with a key which is the empty string. */ + @Test public void test_61277c() throws Exception { IProject project1 = getProject(createUniqueString()); createInWorkspace(project1); @@ -481,6 +501,7 @@ public void test_61277c() throws Exception { * The project preferences are being accessing (for the first time) from * within a resource change listener reacting to a change in the workspace. */ + @Test public void test_61843() throws Exception { // create the project and manually give it a settings file final String qualifier = createUniqueString(); @@ -526,6 +547,7 @@ public void test_61843() throws Exception { * Bug 65068 - When the preferences file is deleted, the corresponding preferences * should be forgotten. */ + @Test public void test_65068() throws Exception { IProject project = getProject(createUniqueString()); createInWorkspace(project); @@ -545,6 +567,7 @@ public void test_65068() throws Exception { /* * Bug 95052 - external property removals are not detected. */ + @Test public void test_95052() throws Exception { IProject project = getProject(createUniqueString()); createInWorkspace(project); @@ -588,6 +611,7 @@ public void test_95052() throws Exception { /* * Bug 579372 - property removals are not detected. */ + @Test public void test_579372() throws Exception { IProject project = getProject(createUniqueString()); createInWorkspace(project); @@ -655,6 +679,7 @@ public void test_579372() throws Exception { * Bug 256900 - When the preferences file is copied between projects, the corresponding preferences * should be updated. */ + @Test public void test_256900() throws Exception { IProject project = getProject(createUniqueString()); createInWorkspace(project); @@ -689,6 +714,7 @@ public void test_256900() throws Exception { * Bug 325000 Project properties not sorted on IBM VMs * Creates property file with various characters on front and verifies that they are written in alphabetical order. */ + @Test public void test_325000() throws Exception { IProject project1 = getProject(createUniqueString()); createInWorkspace(project1); @@ -737,6 +763,7 @@ public void test_325000() throws Exception { } } + @Test public void test_335591() throws Exception { String projectName = createUniqueString(); String nodeName = "node"; @@ -798,6 +825,7 @@ public void test_335591() throws Exception { assertEquals("NEW_VALUE", node.get("NEW_KEY", null)); } + @Test public void test_384151() throws BackingStoreException, CoreException { // make sure each line separator is different String systemValue = System.lineSeparator(); @@ -882,6 +910,7 @@ public void test_384151() throws BackingStoreException, CoreException { } } + @Test public void test_336211() throws BackingStoreException, CoreException, IOException { String projectName = createUniqueString(); String nodeName = "node"; @@ -912,6 +941,7 @@ public void test_336211() throws BackingStoreException, CoreException, IOExcepti assertEquals("VALUE", node.get("KEY", null)); } + @Test public void testProjectOpenClose() throws Exception { IProject project = getProject(createUniqueString()); createInWorkspace(project); @@ -929,6 +959,7 @@ public void testProjectOpenClose() throws Exception { assertEquals("2.1", value, node.get(key, null)); } + @Test public void testContentType() { IContentType prefsType = Platform.getContentTypeManager().getContentType(ResourcesPlugin.PI_RESOURCES + ".preferences"); assertNotNull("1.0", prefsType); @@ -936,6 +967,7 @@ public void testContentType() { assertEquals("1.1", prefsType, associatedType); } + @Test public void testListenerOnChangeFile() throws Exception { // setup IProject project = getProject(createUniqueString()); @@ -1006,8 +1038,8 @@ private static File getFileInFilesystem(IProject project, String qualifier) { * Test to ensure that discovering a new pref file (e.g. loading from a repo) * is the same as doing an import. (ensure the modify listeners are called) */ + @Test public void testLoadIsImport() throws Exception { - // setup IProject project = getProject(createUniqueString()); createInWorkspace(project); @@ -1085,6 +1117,7 @@ private boolean isNodeCleared(Preferences node, String[] childrenNames) throws B return true; } + @Test public void testChildrenNamesAgainstInitialize() throws BackingStoreException, CoreException { String nodeA = "nodeA"; String nodeB = "nodeB"; @@ -1124,6 +1157,7 @@ public void testChildrenNamesAgainstInitialize() throws BackingStoreException, C project2.delete(true, createTestMonitor()); } + @Test public void testChildrenNamesAgainstLoad() throws BackingStoreException, CoreException { String nodeA = "nodeA"; String nodeB = "nodeB"; @@ -1159,6 +1193,7 @@ public void testChildrenNamesAgainstLoad() throws BackingStoreException, CoreExc project2.delete(true, createTestMonitor()); } + @Test public void testClear() throws BackingStoreException, CoreException { String nodeA = "nodeA"; String nodeB = "nodeB"; @@ -1194,6 +1229,7 @@ public void testClear() throws BackingStoreException, CoreException { project2.delete(true, createTestMonitor()); } + @Test public void testGet() throws BackingStoreException, CoreException { String nodeA = "nodeA"; String nodeB = "nodeB"; @@ -1227,6 +1263,7 @@ public void testGet() throws BackingStoreException, CoreException { project2.delete(true, createTestMonitor()); } + @Test public void testKeys() throws BackingStoreException, CoreException { String nodeA = "nodeA"; String nodeB = "nodeB"; @@ -1262,6 +1299,7 @@ public void testKeys() throws BackingStoreException, CoreException { project2.delete(true, createTestMonitor()); } + @Test public void testNodeExistsAgainstInitialize() throws BackingStoreException, CoreException { String nodeA = "nodeA"; String nodeB = "nodeB"; @@ -1297,6 +1335,7 @@ public void testNodeExistsAgainstInitialize() throws BackingStoreException, Core project2.delete(true, createTestMonitor()); } + @Test public void testNodeExistsAgainstLoad() throws BackingStoreException, CoreException { String nodeA = "nodeA"; String nodeB = "nodeB"; @@ -1330,6 +1369,7 @@ public void testNodeExistsAgainstLoad() throws BackingStoreException, CoreExcept project2.delete(true, createTestMonitor()); } + @Test public void testPut() throws BackingStoreException, CoreException { String nodeA = "nodeA"; String nodeB = "nodeB"; @@ -1365,6 +1405,7 @@ public void testPut() throws BackingStoreException, CoreException { project2.delete(true, createTestMonitor()); } + @Test public void testRemove() throws BackingStoreException, CoreException { String nodeA = "nodeA"; String nodeB = "nodeB"; @@ -1399,6 +1440,7 @@ public void testRemove() throws BackingStoreException, CoreException { project2.delete(true, createTestMonitor()); } + @Test public void testDeleteOnFilesystemAndLoad() throws CoreException, BackingStoreException { String nodeA = "nodeA"; String key = "key"; @@ -1426,6 +1468,7 @@ public void testDeleteOnFilesystemAndLoad() throws CoreException, BackingStoreEx ProjectPreferences.updatePreferences(prefsFile); } + @Test public void testSettingsFolderCreatedOutsideWorkspace() throws CoreException, BackingStoreException, IOException { String nodeA = "nodeA"; String key = "key"; @@ -1451,6 +1494,6 @@ public void testSettingsFolderCreatedOutsideWorkspace() throws CoreException, Ba prefs1.put(key, value); prefs1.flush(); assertEquals(value, prefs1.get(key, null)); - } + } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectReferencesTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectReferencesTest.java index 4d79a3eed73..06a11bf0007 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectReferencesTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectReferencesTest.java @@ -27,12 +27,18 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.tests.resources.ResourceTest; +import org.eclipse.core.tests.resources.WorkspaceTestRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; /** * Test project variant references */ -public class ProjectReferencesTest extends ResourceTest { +public class ProjectReferencesTest { + + @Rule + public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); private IProject project0; private IProject project1; @@ -49,9 +55,8 @@ public class ProjectReferencesTest extends ResourceTest { private static final String bc1 = "Variant1"; private static final String nonExistentBC = "foo"; - @Override + @Before public void setUp() throws Exception { - super.setUp(); project0 = getWorkspace().getRoot().getProject("ProjectReferencesTest_p0"); project1 = getWorkspace().getRoot().getProject("ProjectReferencesTest_p1"); project2 = getWorkspace().getRoot().getProject("ProjectReferencesTest_p2"); @@ -86,6 +91,7 @@ private void setUpVariants(IProject project) throws CoreException { project.setDescription(desc, createTestMonitor()); } + @Test public void testAddReferencesToNonExistantConfigs() throws CoreException { IProjectDescription desc = project0.getDescription(); @@ -108,6 +114,7 @@ public void testAddReferencesToNonExistantConfigs() throws CoreException { * * Removing a build configuration removes associated build configuration references */ + @Test public void testChangingBuildConfigurations() throws CoreException { IProjectDescription desc = project0.getDescription(); IBuildConfiguration[] refs = new IBuildConfiguration[] {project0v1, project1v0}; @@ -149,6 +156,7 @@ public void testChangingBuildConfigurations() throws CoreException { * Tests that setting build configuration level dynamic references * trumps the project level dynamic references when it comes to order. */ + @Test public void testMixedProjectAndBuildConfigRefs() throws CoreException { // Set project variant references IProjectDescription desc = project0.getDescription(); @@ -182,6 +190,7 @@ public void testMixedProjectAndBuildConfigRefs() throws CoreException { arrayContaining(project1.getActiveBuildConfig(), project3.getActiveBuildConfig())); } + @Test public void testSetAndGetProjectReferences() throws CoreException { // Set project references IProjectDescription desc = project0.getDescription(); @@ -216,6 +225,7 @@ public void testSetAndGetProjectReferences() throws CoreException { arrayContaining(project3v0, project1v0, project2v0)); } + @Test public void testSetAndGetProjectConfigReferences() throws CoreException { // Set project variant references IProjectDescription desc = project0.getDescription(); @@ -254,6 +264,7 @@ public void testSetAndGetProjectConfigReferences() throws CoreException { project2v0, project1.getActiveBuildConfig(), project3.getActiveBuildConfig())); } + @Test public void testReferencesToActiveConfigs() throws CoreException { IProjectDescription desc = project0.getDescription(); desc.setBuildConfigReferences(bc0, new IBuildConfiguration[] {getRef(project1)}); @@ -263,4 +274,5 @@ public void testReferencesToActiveConfigs() throws CoreException { assertThat(project0.getReferencedBuildConfigs(project0v0.getName(), true), arrayContaining(project1v0)); } + } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ResourceInfoTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ResourceInfoTest.java index 03a4a4a39fd..9a7d9072f46 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ResourceInfoTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ResourceInfoTest.java @@ -14,58 +14,30 @@ *******************************************************************************/ package org.eclipse.core.tests.internal.resources; +import static org.junit.Assert.assertTrue; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; -import java.util.Map; import org.eclipse.core.internal.resources.ResourceInfo; import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.core.tests.resources.ResourceTest; +import org.eclipse.core.tests.resources.WorkspaceTestRule; +import org.junit.Rule; +import org.junit.Test; -public class ResourceInfoTest extends ResourceTest { +public class ResourceInfoTest { - static public void assertEquals(String message, byte[] expected, byte[] actual) { - if (expected == null && actual == null) { - return; - } - if (expected == null || actual == null) { - assertTrue(message, false); - } - assertEquals(message, expected.length, actual.length); - for (int i = 0; i < expected.length; i++) { - assertEquals(message, expected[i], actual[i]); - } - } + @Rule + public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - static public void assertEquals(String message, Map expected, Map actual) { + static public void assertEquals(ResourceInfo expected, ResourceInfo actual) { if (expected == null && actual == null) { return; } if (expected == null || actual == null) { - assertTrue(message, false); - } - assertEquals(message, expected.size(), actual.size()); - for (Map.Entry entry : expected.entrySet()) { - Object key = entry.getKey(); - assertTrue(message, actual.containsKey(key)); - Object expectedValue = entry.getValue(); - Object actualValue = actual.get(key); - if (expectedValue instanceof byte[] expectedB && actualValue instanceof byte[] actualB) { - assertEquals(message, expectedB, actualB); - } else { - assertEquals(message, expectedValue, actualValue); - } - } - } - - static public void assertEquals(String message, ResourceInfo expected, ResourceInfo actual) { - if (expected == null && actual == null) { - return; - } - if (expected == null || actual == null) { - assertTrue(message, false); + assertTrue(false); } boolean different = false; different &= expected.getFlags() == actual.getFlags(); @@ -77,10 +49,11 @@ static public void assertEquals(String message, ResourceInfo expected, ResourceI // assertEquals(message, expected.getSyncInfo(false), actual.getSyncInfo(false)); different &= expected.getMarkerGenerationCount() == actual.getMarkerGenerationCount(); if (different) { - assertTrue(message, false); + assertTrue(false); } } + @Test public void testSerialization() throws IOException { ByteArrayInputStream input = null; ByteArrayOutputStream output = null; @@ -92,7 +65,7 @@ public void testSerialization() throws IOException { info.writeTo(new DataOutputStream(output)); input = new ByteArrayInputStream(output.toByteArray()); newInfo.readFrom(0, new DataInputStream(input)); - assertEquals("1.2", info, newInfo); + assertEquals(info, newInfo); // write and info with syncinfo set info = new ResourceInfo(); @@ -109,6 +82,7 @@ public void testSerialization() throws IOException { newInfo = new ResourceInfo(); input = new ByteArrayInputStream(output.toByteArray()); newInfo.readFrom(0, new DataInputStream(input)); - assertEquals("2.2", info, newInfo); + assertEquals(info, newInfo); } + } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WorkspaceConcurrencyTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WorkspaceConcurrencyTest.java index 664a9b12396..59357886f7e 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WorkspaceConcurrencyTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WorkspaceConcurrencyTest.java @@ -17,6 +17,7 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicIntegerArray; @@ -39,12 +40,17 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.tests.harness.CancelingProgressMonitor; import org.eclipse.core.tests.harness.TestBarrier2; -import org.eclipse.core.tests.resources.ResourceTest; +import org.eclipse.core.tests.resources.WorkspaceTestRule; +import org.junit.Rule; +import org.junit.Test; /** * Tests concurrency issues when dealing with operations on the workspace */ -public class WorkspaceConcurrencyTest extends ResourceTest { +public class WorkspaceConcurrencyTest { + + @Rule + public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); private void sleep(long duration) { try { @@ -54,6 +60,7 @@ private void sleep(long duration) { } } + @Test public void testEndRuleInWorkspaceOperation() { final IProject project = getWorkspace().getRoot().getProject("testEndRuleInWorkspaceOperation"); assertThrows(RuntimeException.class, @@ -65,6 +72,7 @@ public void testEndRuleInWorkspaceOperation() { * Tests that it is possible to cancel a workspace operation when it is blocked * by activity in another thread. This is a regression test for bug 56118. */ + @Test public void testCancelOnBlocked() throws Throwable { //create a dummy project createInWorkspace(getWorkspace().getRoot().getProject("P1")); @@ -131,6 +139,7 @@ public void testCancelOnBlocked() throws Throwable { * Tests calling IWorkspace.run with a non-workspace rule. This should be * allowed. This is a regression test for bug 60114. */ + @Test public void testRunnableWithOtherRule() throws CoreException { ISchedulingRule rule = new ISchedulingRule() { @Override @@ -159,6 +168,7 @@ public boolean isConflicting(ISchedulingRule schedulingRule) { * will not be available and it will fail. * This is a regression test for bug 62927. */ + @Test public void testRunWhileBuilding() throws Throwable { final IWorkspace workspace = ResourcesPlugin.getWorkspace(); //create a POST_BUILD listener that will touch a project