Skip to content

Commit

Permalink
Migrate resources regression tests to JUnit 5
Browse files Browse the repository at this point in the history
Migrates the tests in org.eclipse.core.tests.resources.regresison to
JUnit 5.
- Exchange JUnit test annotations
- Replace JUnit 4 WorkspaceTestRule with JUnit 5 WorkspaceResetExtension
- Replace JUnit 4 assertions with JUnit 5 assertions
- Replace resource cleanup via WorkspaceTestRule with usage of temp
  directories or explicit cleanups

Contributes to
eclipse-platform#903
  • Loading branch information
HeikoKlare committed Sep 5, 2024
1 parent a4eb5f3 commit 70607f3
Show file tree
Hide file tree
Showing 49 changed files with 416 additions and 495 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.tests.resources.WorkspaceTestRule;
import org.junit.Rule;
import org.junit.Test;
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(WorkspaceResetExtension.class)
public class Bug_006708 {

@Rule
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();

@Test
public void testBug() throws CoreException {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomString;
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.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -32,9 +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.WorkspaceTestRule;
import org.junit.Rule;
import org.junit.Test;
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

/**
* Tests regression of bug 25457. In this case, attempting to move a project
Expand All @@ -44,11 +44,9 @@
* Note: this is similar to Bug_32076, which deals with failure to move in
* the non case-change scenario.
*/
@ExtendWith(WorkspaceResetExtension.class)
public class Bug_025457 {

@Rule
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();

@Test
public void testFile() throws Exception {
assumeTrue("only relevant on Windows", OS.isWindows());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import static org.eclipse.core.tests.resources.ResourceTestUtil.createUniqueString;
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.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.InputStream;
import java.util.function.Predicate;
Expand All @@ -38,15 +38,16 @@
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.WorkspaceTestRule;
import org.junit.Rule;
import org.junit.Test;
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

/**
* 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.
*/
@ExtendWith(WorkspaceResetExtension.class)
public class Bug_026294 {

private static final Predicate<IResource> isSynchronizedDepthInfinite = resource -> resource
Expand All @@ -55,9 +56,6 @@ public class Bug_026294 {
private static final Predicate<IResource> isSynchronizedDepthZero = resource -> resource
.isSynchronized(IResource.DEPTH_ZERO);

@Rule
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();

/**
* Tries to delete an open project containing an unremovable file.
* Works only for Windows.
Expand All @@ -76,7 +74,6 @@ public void testDeleteOpenProjectWindows() throws Exception {

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

assertExistsInFileSystem(file1);
assertExistsInFileSystem(file2);
Expand Down Expand Up @@ -145,7 +142,6 @@ public void testDeleteOpenProjectLinux() throws CoreException {

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

try {
// marks folder as read-only so its files cannot be deleted on Linux
Expand Down Expand Up @@ -195,7 +191,6 @@ public void testDeleteClosedProjectWindows() throws Exception {

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

// opens a file so it cannot be removed on Windows
try (InputStream input = file1.getContents()) {
Expand Down Expand Up @@ -229,10 +224,8 @@ public void testDeleteClosedProjectLinux() throws CoreException {
IFile file1 = folder.getFile("file1.txt");
IFile file2 = project.getFile("file2.txt");
IFile projectFile = project.getFile(IPath.fromOSString(".project"));

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

try {
// marks folder as read-only so its files cannot be removed on Linux
Expand Down Expand Up @@ -273,10 +266,7 @@ public void testDeleteFolderWindows() throws Exception {
IFolder folder = project.getFolder("a_folder");
IFile file1 = folder.getFile("file1.txt");
IFile file3 = folder.getFile("file3.txt");

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

// opens a file so it cannot be removed on Windows
try (InputStream input = file1.getContents()) {
Expand Down Expand Up @@ -309,10 +299,7 @@ public void testDeleteFolderLinux() throws CoreException {
IFolder subFolder = folder.getFolder("sub-folder");
IFile file1 = subFolder.getFile("file1.txt");
IFile file3 = folder.getFile("file3.txt");

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

try {
// marks sub-folder as read-only so its files cannot be removed on Linux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,35 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace;
import static org.junit.Assert.assertFalse;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;

import org.eclipse.core.resources.IPathVariableManager;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform.OS;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.tests.resources.WorkspaceTestRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

/**
* Tests how changes in the underlying preference store may affect the path
* variable manager.
*/

@ExtendWith(WorkspaceResetExtension.class)
public class Bug_027271 {

@Rule
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();

static final String VARIABLE_PREFIX = "pathvariable."; //$NON-NLS-1$

@Before
@BeforeEach
public void setUp() {
clearPathVariablesProperties();
}

@After
@AfterEach
public void tearDown() {
clearPathVariablesProperties();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomString;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
Expand All @@ -31,19 +31,16 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.tests.resources.ResourceVisitorVerifier;
import org.eclipse.core.tests.resources.WorkspaceTestRule;
import org.junit.Rule;
import org.junit.Test;
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

/**
* Resource#accept doesn't obey member flags for the traversal entry point.
*/

@ExtendWith(WorkspaceResetExtension.class)
public class Bug_028981 {

@Rule
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();

@Test
public void testBug() throws CoreException {
final QualifiedName partner = new QualifiedName("org.eclipse.core.tests.resources", "myTarget");
Expand Down Expand Up @@ -77,25 +74,25 @@ public void testBug() throws CoreException {
verifier.addExpected(settings);
verifier.addExpected(prefs);
project.accept(verifier);
assertTrue(verifier.getMessage(), verifier.isValid());
assertTrue(verifier.isValid(), verifier.getMessage());

verifier.reset();
assertThrows(CoreException.class, () -> phantomFile.accept(verifier));

verifier.reset();
verifier.addExpected(phantomFile);
phantomFile.accept(verifier, IResource.DEPTH_INFINITE, IContainer.INCLUDE_PHANTOMS);
assertTrue(verifier.getMessage(), verifier.isValid());
assertTrue(verifier.isValid(), verifier.getMessage());

verifier.reset();
// no resources should be visited
teamPrivateFile.accept(verifier);
assertTrue(verifier.getMessage(), verifier.isValid());
assertTrue(verifier.isValid(), verifier.getMessage());

verifier.reset();
verifier.addExpected(teamPrivateFile);
teamPrivateFile.accept(verifier, IResource.DEPTH_INFINITE, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
assertTrue(verifier.getMessage(), verifier.isValid());
assertTrue(verifier.isValid(), verifier.getMessage());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.tests.resources.WorkspaceTestRule;
import org.junit.Rule;
import org.junit.Test;
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

/**
* Test regression of bug 29116. In this bug, triggering a builder during
* installation of a nature caused an assertion failure.
*/
@ExtendWith(WorkspaceResetExtension.class)
public class Bug_029116 {

@Rule
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();

@Test
public void testBug() throws CoreException {
// Create some resource handles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,16 @@
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.tests.resources.WorkspaceTestRule;
import org.junit.Rule;
import org.junit.Test;
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

/**
* When a container was moved, its children were not added to phantom space.
*/
@ExtendWith(WorkspaceResetExtension.class)
public class Bug_029671 {

@Rule
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();

@Test
public void testBug() throws CoreException {
final QualifiedName partner = new QualifiedName("org.eclipse.core.tests.resources", "myTarget");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,18 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.tests.resources.WorkspaceTestRule;
import org.junit.Rule;
import org.junit.Test;
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

/**
* Tests regression of bug 25457. In this case, attempting to move a project
* that is only a case change, where the move fails due to another handle being
* open on a file in the hierarchy, would cause deletion of the source.
*/
@ExtendWith(WorkspaceResetExtension.class)
public class Bug_029851 {

@Rule
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();

private Collection<String> createChildren(int breadth, int depth, IPath prefix) {
ArrayList<String> result = new ArrayList<>();
for (int i = 0; i < breadth; i++) {
Expand Down
Loading

0 comments on commit 70607f3

Please sign in to comment.