Skip to content

Commit

Permalink
Make WorkspaceSessionTests independent from ResourceTest #903
Browse files Browse the repository at this point in the history
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
#903
  • Loading branch information
HeikoKlare committed Dec 12, 2023
1 parent 2e6b059 commit f88efec
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
*/
Expand All @@ -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 <code>test*</code>
* method) has finished.
* <p>
Expand All @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit f88efec

Please sign in to comment.