From f88efec561e5ba17352d21e01efe789e055521cd Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Mon, 11 Dec 2023 14:07:39 +0100 Subject: [PATCH] Make WorkspaceSessionTests independent from ResourceTest #903 WorkspaceSessionTests currently inherit from ResourceTest and CoreTest. In order to remove the JUnit 3 inheritance hierarchy and migrate to JUnit 4, this change replaces the extension of ResourceTest with a usage of the WorkspaceTestRule and the extension of JUnit 3's TestCase. Due to the framework for running session tests relying on the test classes inheriting from JUnit 3's TestCase, this cannot be replaced yet. Contributes to https://github.com/eclipse-platform/eclipse.platform/issues/903 --- .../resources/WorkspacePreferencesTest.java | 1 + .../tests/resources/WorkspaceSessionTest.java | 28 +++++++++++-------- .../tests/resources/session/Bug_266907.java | 1 + .../resources/session/TestBug323833.java | 2 +- ...stCreateLinkedResourceInHiddenProject.java | 1 + ...estWorkspaceEncodingExistingWorkspace.java | 2 +- 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WorkspacePreferencesTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WorkspacePreferencesTest.java index ed7829f1cff..49ed2abe80e 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WorkspacePreferencesTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WorkspacePreferencesTest.java @@ -14,6 +14,7 @@ *******************************************************************************/ package org.eclipse.core.tests.internal.resources; +import static org.eclipse.core.tests.harness.FileSystemHelper.getRandomLocation; import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS; import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomString; import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromFileSystem; diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceSessionTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceSessionTest.java index 84382a3703f..706885a5cb4 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceSessionTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceSessionTest.java @@ -13,6 +13,9 @@ *******************************************************************************/ package org.eclipse.core.tests.resources; +import junit.framework.TestCase; +import org.junit.Rule; + /** * Workspace session tests function as follows: Each test class looks like a typical JUnit test, * except the platform is shutdown and restarted after each test method. The steps for each @@ -34,7 +37,11 @@ * * @see org.eclipse.core.tests.session.WorkspaceSessionTestSuite */ -public class WorkspaceSessionTest extends ResourceTest { +public class WorkspaceSessionTest extends TestCase { + + @Rule + public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + /** * Constructor for WorkspaceSessionTest. */ @@ -52,8 +59,14 @@ public WorkspaceSessionTest(String name) { super(name); } + @Override + protected void setUp() throws Exception { + workspaceRule.before(); + workspaceRule.setTestName(getName()); + } + /** - * Executes the cleanup functionality in {@link ResourceTest#tearDown()} after + * Executes the cleanup functionality in {@link WorkspaceTestRule#after()} after * the last of the session of this test class (i.e., the last test* * method) has finished. *

@@ -63,16 +76,7 @@ public WorkspaceSessionTest(String name) { * actual test methods. */ public void test___cleanup() throws Exception { - super.tearDown(); - } - - /** - * Cleanup is done after all sessions of this test class in - * {@link #test___cleanup()}. This method is overwritten to do nothing in order - * to not cleanup between the sessions. - */ - @Override - protected final void tearDown() throws Exception { + workspaceRule.after(); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/Bug_266907.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/Bug_266907.java index 1e9c7467028..0f52e4e2e3d 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/Bug_266907.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/Bug_266907.java @@ -14,6 +14,7 @@ package org.eclipse.core.tests.resources.session; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; +import static org.eclipse.core.tests.harness.FileSystemHelper.getTempDir; import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInputStream; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug323833.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug323833.java index 181f60979c5..6206298ed5f 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug323833.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug323833.java @@ -40,7 +40,7 @@ public void test1() throws Exception { return; } - IFileStore fileStore = getTempStore().getChild(createUniqueString()); + IFileStore fileStore = workspaceRule.getTempStore().getChild(createUniqueString()); createInFileSystem(fileStore); // set EFS.ATTRIBUTE_READ_ONLY which also sets EFS.IMMUTABLE on Mac diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestCreateLinkedResourceInHiddenProject.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestCreateLinkedResourceInHiddenProject.java index a5c14b94709..0f38fc37708 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestCreateLinkedResourceInHiddenProject.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestCreateLinkedResourceInHiddenProject.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.session; +import static org.eclipse.core.tests.harness.FileSystemHelper.getTempDir; import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import static org.eclipse.core.tests.resources.ResourceTestUtil.createUniqueString; diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestWorkspaceEncodingExistingWorkspace.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestWorkspaceEncodingExistingWorkspace.java index 89c9fa48749..5c5551a9c3e 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestWorkspaceEncodingExistingWorkspace.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestWorkspaceEncodingExistingWorkspace.java @@ -38,7 +38,7 @@ public static Test suite() { try { Files.createDirectories(projectsTree); } catch (IOException e) { - fail("Unable to create directories: " + projectsTree, e); + fail("Unable to create directories: " + projectsTree + System.lineSeparator() + e); } return suite; }