Skip to content

Commit

Permalink
Migrate all tests in o.e.c.tests.resources.regression to JUnit 4 ecli…
Browse files Browse the repository at this point in the history
…pse-platform#903

* Replace the ResourceTest class hierarchy with WorkspaceTestRule
* Add @test annotations
* Replace hand-written assumption checks with assume*() statements

Contributes to
eclipse-platform#903
  • Loading branch information
HeikoKlare committed Dec 11, 2023
1 parent 977626d commit 95da62a
Show file tree
Hide file tree
Showing 49 changed files with 837 additions and 422 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,55 @@
* A suite that runs all regression tests.
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({ Bug_006708.class, Bug_025457.class, Bug_026294.class, Bug_027271.class, Bug_028981.class,
Bug_029116.class, Bug_029671.class, Bug_029851.class, Bug_032076.class, Bug_044106.class, Bug_092108.class,
Bug_097608.class, Bug_098740.class, Bug_126104.class, Bug_127562.class, Bug_132510.class, Bug_134364.class,
Bug_147232.class, Bug_160251.class, Bug_165892.class, Bug_192631.class, Bug_226264.class, Bug_231301.class,
Bug_233939.class, Bug_265810.class, Bug_264182.class, Bug_297635.class, Bug_288315.class, Bug_303517.class,
Bug_329836.class, Bug_331445.class, Bug_332543.class, Bug_378156.class,
IFileTest.class, IFolderTest.class, IProjectTest.class,
IResourceTest.class, IWorkspaceTest.class, LocalStoreRegressionTests.class, NLTest.class,
PR_1GEAB3C_Test.class,
PR_1GH2B0N_Test.class, PR_1GHOM0N_Test.class, Bug_530868.class, Bug_185247_recursiveLinks.class,
Bug_185247_LinuxTests.class })
@Suite.SuiteClasses({ //
Bug_006708.class, //
Bug_025457.class, //
Bug_026294.class, //
Bug_027271.class, //
Bug_028981.class, //
Bug_029116.class, //
Bug_029671.class, //
Bug_029851.class, //
Bug_032076.class, //
Bug_044106.class, //
Bug_079398.class, //
Bug_092108.class, //
Bug_097608.class, //
Bug_098740.class, //
Bug_126104.class, //
Bug_127562.class, //
Bug_132510.class, //
Bug_134364.class, //
Bug_147232.class, //
Bug_160251.class, //
Bug_165892.class, //
Bug_185247_LinuxTests.class, //
Bug_185247_recursiveLinks.class, //
Bug_192631.class, //
Bug_226264.class, //
Bug_231301.class, //
Bug_233939.class, //
Bug_264182.class, //
Bug_265810.class, //
Bug_288315.class, //
Bug_297635.class, //
Bug_303517.class, //
Bug_329836.class, //
Bug_331445.class, //
Bug_332543.class, //
Bug_378156.class, //
Bug_380386.class, //
Bug_530868.class, //
IFileTest.class, //
IFolderTest.class, //
IProjectTest.class, //
IResourceTest.class, //
IWorkspaceTest.class, //
LocalStoreRegressionTests.class, //
NLTest.class, //
PR_1GEAB3C_Test.class, //
PR_1GH2B0N_Test.class, //
PR_1GHOM0N_Test.class, //
})
public class AllRegressionTests {
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@
*******************************************************************************/
package org.eclipse.core.tests.resources.regression;

import static org.junit.Assert.assertFalse;

import java.io.ByteArrayInputStream;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.tests.resources.ResourceTest;
import org.eclipse.core.tests.resources.WorkspaceTestRule;
import org.junit.Rule;
import org.junit.Test;

public class Bug_006708 {

public class Bug_006708 extends ResourceTest {
@Rule
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();

@Test
public void testBug() throws CoreException {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject sourceProj = root.getProject("bug_6708");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor;
import static org.eclipse.core.tests.resources.ResourceTestUtil.isReadOnlySupported;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand All @@ -30,7 +32,9 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
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;

/**
* Tests regression of bug 25457. In this case, attempting to move a project
Expand All @@ -40,13 +44,15 @@
* Note: this is similar to Bug_32076, which deals with failure to move in
* the non case-change scenario.
*/
public class Bug_025457 extends ResourceTest {
public class Bug_025457 {

@Rule
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();

@Test
public void testFile() throws Exception {
//this test only works on windows
if (!OS.isWindows()) {
return;
}
assumeTrue("test only works on Windows", OS.isWindows());

IProject source = getWorkspace().getRoot().getProject("project");
IFile sourceFile = source.getFile("file.txt");
IFile destFile = source.getFile("File.txt");
Expand All @@ -70,12 +76,11 @@ public void testFile() throws Exception {
assertTrue("2.3", !destFile.exists());
}

@Test
public void testFolder() throws IOException, CoreException {
//this test only works on windows
//native code must also be present so move can detect the case change
if (!OS.isWindows() || !isReadOnlySupported()) {
return;
}
assumeTrue("test only works on Windows", OS.isWindows() && isReadOnlySupported());

IProject source = getWorkspace().getRoot().getProject("SourceProject");
IFolder sourceFolder = source.getFolder("folder");
IFile sourceFile = sourceFolder.getFile("Important.txt");
Expand All @@ -101,11 +106,10 @@ public void testFolder() throws IOException, CoreException {
}
}

@Test
public void testProject() throws IOException, CoreException {
//this test only works on windows
if (!OS.isWindows()) {
return;
}
assumeTrue("test only works on Windows", OS.isWindows());

IProject source = getWorkspace().getRoot().getProject("project");
IProject destination = getWorkspace().getRoot().getProject("Project");
IFile sourceFile = source.getFile("Important.txt");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import static org.eclipse.core.tests.resources.ResourceTestUtil.isReadOnlySupported;
import static org.eclipse.core.tests.resources.ResourceTestUtil.setReadOnly;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;

import java.io.InputStream;
import org.eclipse.core.resources.IFile;
Expand All @@ -34,23 +36,27 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
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;

/**
* A parent container (projects and folders) would become out-of-sync if any of
* its children could not be deleted for some reason. These platform-
* specific test cases ensure that it does not happen.
*/
public class Bug_026294 extends ResourceTest {
public class Bug_026294 {

@Rule
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();

/**
* Tries to delete an open project containing an unremovable file.
* Works only for Windows.
*/
@Test
public void testDeleteOpenProjectWindows() throws Exception {
if (!(OS.isWindows())) {
return;
}
assumeTrue("test only works on Windows", OS.isWindows());

IWorkspace workspace = getWorkspace();
IProject project = workspace.getRoot().getProject(createUniqueString());
Expand All @@ -62,7 +68,7 @@ public void testDeleteOpenProjectWindows() throws Exception {

createInWorkspace(new IResource[] { file1, file2, file3 });
IPath projectRoot = project.getLocation();
deleteOnTearDown(projectRoot);
workspaceRule.deleteOnTearDown(projectRoot);

assertExistsInFileSystem(file1);
assertExistsInFileSystem(file2);
Expand Down Expand Up @@ -116,13 +122,12 @@ public void testDeleteOpenProjectWindows() throws Exception {
}

/**
* Tries to delete an open project containing an irremovable file.
* Works only for Linux with natives.
* Tries to delete an open project containing an non-removable file. Works only
* for Linux with natives.
*/
@Test
public void testDeleteOpenProjectLinux() throws CoreException {
if (!(OS.isLinux() && isReadOnlySupported())) {
return;
}
assumeTrue("test only works on Linux", OS.isLinux() && isReadOnlySupported());

IWorkspace workspace = getWorkspace();
IProject project = workspace.getRoot().getProject(createUniqueString());
Expand All @@ -132,7 +137,7 @@ public void testDeleteOpenProjectLinux() throws CoreException {

createInWorkspace(new IResource[] { file1, file2 });
IPath projectRoot = project.getLocation();
deleteOnTearDown(projectRoot);
workspaceRule.deleteOnTearDown(projectRoot);

try {
// marks folder as read-only so its files cannot be deleted on Linux
Expand Down Expand Up @@ -165,13 +170,12 @@ public void testDeleteOpenProjectLinux() throws CoreException {
}

/**
* Tries to delete a closed project containing an unremovable file.
* Tries to delete a closed project containing a non-removable file.
* Works only for Windows.
*/
@Test
public void testDeleteClosedProjectWindows() throws Exception {
if (!OS.isWindows()) {
return;
}
assumeTrue("test only works on Windows", OS.isWindows());

IWorkspace workspace = getWorkspace();
IProject project = workspace.getRoot().getProject(createUniqueString());
Expand All @@ -183,7 +187,7 @@ public void testDeleteClosedProjectWindows() throws Exception {

createInWorkspace(new IResource[] { file1, file2, file3 });
IPath projectRoot = project.getLocation();
deleteOnTearDown(projectRoot);
workspaceRule.deleteOnTearDown(projectRoot);

// opens a file so it cannot be removed on Windows
try (InputStream input = file1.getContents()) {
Expand All @@ -204,15 +208,12 @@ public void testDeleteClosedProjectWindows() throws Exception {
}

/**
* Tries to delete a closed project containing an unremovable file.
* Works only for Linux with natives.
*
* TODO: enable this test once bug 48321 is fixed.
* Tries to delete a closed project containing an non-removable file. Works only
* for Linux with natives.
*/
@Test
public void testDeleteClosedProjectLinux() throws CoreException {
if (!OS.isLinux()) {
return;
}
assumeTrue("test only works on Linux", OS.isLinux());

IWorkspace workspace = getWorkspace();
IProject project = workspace.getRoot().getProject(createUniqueString());
Expand All @@ -223,7 +224,7 @@ public void testDeleteClosedProjectLinux() throws CoreException {

createInWorkspace(new IResource[] { file1, file2 });
IPath projectRoot = project.getLocation();
deleteOnTearDown(projectRoot);
workspaceRule.deleteOnTearDown(projectRoot);

try {
// marks folder as read-only so its files cannot be removed on Linux
Expand Down Expand Up @@ -252,13 +253,12 @@ public void testDeleteClosedProjectLinux() throws CoreException {
}

/**
* Tries to delete a folder containing an unremovable file.
* Works only for Windows.
* Tries to delete a folder containing a non-removable file. Works only for
* Windows.
*/
@Test
public void testDeleteFolderWindows() throws Exception {
if (!OS.isWindows()) {
return;
}
assumeTrue("test only works on Windows", OS.isWindows());

IWorkspace workspace = getWorkspace();
IProject project = workspace.getRoot().getProject(createUniqueString());
Expand All @@ -268,7 +268,7 @@ public void testDeleteFolderWindows() throws Exception {

createInWorkspace(new IResource[] { file1, file3 });
IPath projectRoot = project.getLocation();
deleteOnTearDown(projectRoot);
workspaceRule.deleteOnTearDown(projectRoot);

// opens a file so it cannot be removed on Windows
try (InputStream input = file1.getContents()) {
Expand All @@ -288,13 +288,12 @@ public void testDeleteFolderWindows() throws Exception {
}

/**
* Tries to delete a folder containing an irremovable file.
* Works only for Linux with natives.
* Tries to delete a folder containing a non-removable file. Works only for
* Linux with natives.
*/
@Test
public void testDeleteFolderLinux() throws CoreException {
if (!OS.isLinux()) {
return;
}
assumeTrue("test only works on Linux", OS.isLinux());

IWorkspace workspace = getWorkspace();
IProject project = workspace.getRoot().getProject(createUniqueString());
Expand All @@ -305,7 +304,7 @@ public void testDeleteFolderLinux() throws CoreException {

createInWorkspace(new IResource[] { file1, file3 });
IPath projectRoot = project.getLocation();
deleteOnTearDown(projectRoot);
workspaceRule.deleteOnTearDown(projectRoot);

try {
// marks sub-folder as read-only so its files cannot be removed on Linux
Expand Down
Loading

0 comments on commit 95da62a

Please sign in to comment.