diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_006708.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_006708.java index 64a7348335d..45d3f53f74e 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_006708.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_006708.java @@ -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(); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_025457.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_025457.java index 3abc4ce5c87..82f9de04724 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_025457.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_025457.java @@ -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; @@ -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 @@ -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()); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_026294.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_026294.java index db4951e4351..17a7eb43e95 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_026294.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_026294.java @@ -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; @@ -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 isSynchronizedDepthInfinite = resource -> resource @@ -55,9 +56,6 @@ public class Bug_026294 { private static final Predicate 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. @@ -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); @@ -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 @@ -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()) { @@ -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 @@ -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()) { @@ -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 diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_027271.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_027271.java index e08045594cc..288b49df494 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_027271.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_027271.java @@ -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(); } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_028981.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_028981.java index 34b37089d6f..52e516f942c 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_028981.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_028981.java @@ -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; @@ -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"); @@ -77,7 +74,7 @@ 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)); @@ -85,17 +82,17 @@ public void testBug() throws CoreException { 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()); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_029116.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_029116.java index 00198c0b5b5..8eb40a7ead9 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_029116.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_029116.java @@ -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 diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_029671.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_029671.java index 1032f351477..2def854b3fe 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_029671.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_029671.java @@ -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"); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_029851.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_029851.java index 59063e88619..aa223f772ed 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_029851.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_029851.java @@ -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 createChildren(int breadth, int depth, IPath prefix) { ArrayList result = new ArrayList<>(); for (int i = 0; i < breadth; i++) { diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_032076.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_032076.java index b331ec8ada3..6e77f222fa7 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_032076.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_032076.java @@ -20,14 +20,19 @@ 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.createUniqueString; +import static org.eclipse.core.tests.resources.ResourceTestUtil.getFileStore; import static org.eclipse.core.tests.resources.ResourceTestUtil.isReadOnlySupported; +import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromFileSystem; import static org.eclipse.core.tests.resources.ResourceTestUtil.setReadOnly; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import java.io.File; +import java.io.IOException; import java.io.InputStream; +import java.nio.file.Path; import java.util.function.Predicate; import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.internal.resources.Resource; @@ -40,15 +45,17 @@ import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Platform.OS; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.WorkspaceResetExtension; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; /** * When moving a resource "x" from parent "a" to parent "b", if "x" or any of * its children can't be deleted, both "a" and "b" become out-of-sync and resource info is lost. */ +@ExtendWith(WorkspaceResetExtension.class) public class Bug_032076 { private static final Predicate isSynchronizedDepthInfinite = resource -> resource @@ -57,9 +64,6 @@ public class Bug_032076 { private static final Predicate isSynchronizedDepthZero = resource -> resource .isSynchronized(IResource.DEPTH_ZERO); - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - @Test public void testFileBugOnWindows() throws Exception { assumeTrue("only relevant on Windows", OS.isWindows()); @@ -71,9 +75,7 @@ public void testFileBugOnWindows() throws Exception { // this file will be made irremovable IFile sourceFile = sourceParent.getFile("file1.txt"); IFile destinationFile = destinationParent.getFile(sourceFile.getName()); - createInWorkspace(new IResource[] { sourceFile, destinationParent }); - workspaceRule.deleteOnTearDown(project.getLocation()); // add a marker to a file to ensure the move operation is not losing anything String attributeKey = createRandomString(); @@ -127,9 +129,7 @@ public void testFolderBugOnWindows() throws Exception { IFile file1 = folder.getFile("file1.txt"); // but not this one IFile file2 = folder.getFile("file2.txt"); - createInWorkspace(new IResource[] { file1, file2, destinationParent }); - workspaceRule.deleteOnTearDown(project.getLocation()); // add a marker to a file to ensure the move operation is not losing anything String attributeKey = createRandomString(); @@ -186,9 +186,8 @@ public void testProjectBugOnWindows() throws Exception { IFile file1 = sourceProject.getFile("file1.txt"); // but not this one IFile file2 = sourceProject.getFile("file2.txt"); - createInWorkspace(new IResource[] {file1, file2}); - workspaceRule.deleteOnTearDown(sourceProject.getLocation()); // Ensure project location is moved after test + File originalSourceProjectLocation = sourceProject.getLocation().toFile(); // add a marker to a file to ensure the move operation is not losing anything String attributeKey = createRandomString(); @@ -200,7 +199,6 @@ public void testProjectBugOnWindows() throws Exception { // opens a file so it (and its parent) cannot be removed on Windows try (InputStream input = file1.getContents()) { - assertThrows(CoreException.class, () -> sourceProject.move(destinationProject.getFullPath(), IResource.FORCE, createTestMonitor())); @@ -220,11 +218,13 @@ public void testProjectBugOnWindows() throws Exception { assertNotNull(marker); assertEquals(attributeValue, marker.getAttribute(attributeKey)); assertThat(workspace.getRoot()).matches(isSynchronizedDepthInfinite, "is synchronized"); + } finally { + removeFromFileSystem(originalSourceProjectLocation); } } @Test - @Ignore("test is currently failing and needs further investigation (bug 203078)") + @Disabled("test is currently failing and needs further investigation (bug 203078)") public void testFileBugOnLinux() throws CoreException { assumeTrue("only relevant on Linux", OS.isLinux() && isReadOnlySupported()); @@ -236,9 +236,7 @@ public void testFileBugOnLinux() throws CoreException { // this file will be made un-removable IFile sourceFile = roFolder.getFile("file.txt"); IFile destinationFile = destinationParent.getFile("file.txt"); - createInWorkspace(new IResource[] { sourceFile, destinationParent }); - workspaceRule.deleteOnTearDown(project.getLocation()); IFileStore roFolderStore = ((Resource) roFolder).getStore(); @@ -283,7 +281,7 @@ public void testFileBugOnLinux() throws CoreException { } @Test - @Ignore("test is currently failing and needs further investigation (bug 203078)") + @Disabled("test is currently failing and needs further investigation (bug 203078)") public void testFolderBugOnLinux() throws CoreException { assumeTrue("only relevant on Linux", OS.isLinux() && isReadOnlySupported()); @@ -296,9 +294,7 @@ public void testFolderBugOnLinux() throws CoreException { IFile file2 = folder.getFile("file2.txt"); IFolder destinationParent = project.getFolder("destination_parent"); IFolder destinationROFolder = destinationParent.getFolder(roFolder.getName()); - createInWorkspace(new IResource[] { file1, file2, destinationParent }); - workspaceRule.deleteOnTearDown(project.getLocation()); IFileStore roFolderLocation = ((Resource) roFolder).getStore(); IFileStore destinationROFolderLocation = ((Resource) destinationROFolder).getStore(); @@ -358,13 +354,13 @@ public void testFolderBugOnLinux() throws CoreException { } @Test - @Ignore("test is currently failing and needs further investigation (bug 203078)") - public void testProjectBugOnLinux() throws CoreException { + @Disabled("test is currently failing and needs further investigation (bug 203078)") + public void testProjectBugOnLinux(@TempDir Path tempDirectory) throws CoreException, IOException { assumeTrue("only relevant on Linux", OS.isLinux() && isReadOnlySupported()); IWorkspace workspace = getWorkspace(); IProject sourceProject = workspace.getRoot().getProject(createUniqueString() + ".source"); - IFileStore projectParentStore = workspaceRule.getTempStore(); + IFileStore projectParentStore = getFileStore(tempDirectory); IFileStore projectStore = projectParentStore.getChild(sourceProject.getName()); IProjectDescription sourceDescription = workspace.newProjectDescription(sourceProject.getName()); sourceDescription.setLocationURI(projectStore.toURI()); @@ -375,11 +371,11 @@ public void testProjectBugOnLinux() throws CoreException { // create and open the source project at a non-default location sourceProject.create(sourceDescription, createTestMonitor()); sourceProject.open(createTestMonitor()); - workspaceRule.deleteOnTearDown(sourceProject.getLocation()); IFile file1 = sourceProject.getFile("file1.txt"); createInWorkspace(new IResource[] { file1 }); + File originalSourceProjectLocation = sourceProject.getLocation().toFile(); // add a marker to a file to ensure the move operation is not losing anything String attributeKey = createRandomString(); @@ -395,7 +391,6 @@ public void testProjectBugOnLinux() throws CoreException { assertThrows(CoreException.class, () -> sourceProject.move(destinationDescription, IResource.FORCE, createTestMonitor())); - workspaceRule.deleteOnTearDown(destinationProject.getLocation()); // the source does not exist assertThat(sourceProject).matches(not(IResource::exists), "not exists"); @@ -416,6 +411,7 @@ public void testProjectBugOnLinux() throws CoreException { assertThat(workspace.getRoot()).matches(isSynchronizedDepthInfinite, "is synchronized"); } finally { setReadOnly(projectParentStore, false); + removeFromFileSystem(originalSourceProjectLocation); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_044106.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_044106.java index 1e2fcea714e..c274d546a88 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_044106.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_044106.java @@ -22,9 +22,11 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import static org.eclipse.core.tests.resources.ResourceTestUtil.createUniqueString; +import static org.eclipse.core.tests.resources.ResourceTestUtil.getFileStore; import static org.junit.Assume.assumeTrue; import java.io.IOException; +import java.nio.file.Path; import java.util.function.Predicate; import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.resources.IFile; @@ -32,9 +34,10 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; 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; +import org.junit.jupiter.api.io.TempDir; /** * Tests regression of bug 44106. In this case deleting a file which was a @@ -44,12 +47,12 @@ * Also tests bug 174492, which is a similar bug except the KEEP_HISTORY * flag is used when the resource is deleted from the workspace. */ +@ExtendWith(WorkspaceResetExtension.class) public class Bug_044106 { private static final Predicate exists = store -> store.fetchInfo().exists(); - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + private @TempDir Path tempDirectory; private void createSymLink(String target, String local) throws InterruptedException, IOException { Process p = Runtime.getRuntime().exec(new String[] { "/bin/ln", "-s", target, local }); @@ -62,7 +65,7 @@ private void createSymLink(String target, String local) throws InterruptedExcept */ private void doTestDeleteLinkedFile(int deleteFlags) throws Exception { // create the file/folder that we are going to link to - IFileStore linkDestFile = workspaceRule.getTempStore(); + IFileStore linkDestFile = getFileStore(tempDirectory).getChild(createUniqueString()); createInFileSystem(linkDestFile); assertThat(linkDestFile).matches(exists, "exists"); @@ -99,7 +102,7 @@ private void doTestDeleteLinkedFolder(IFolder linkedFolder, boolean deleteParent throws Exception { assumeTrue("only relevant on Linux", OS.isLinux()); - IFileStore linkDestLocation = workspaceRule.getTempStore(); + IFileStore linkDestLocation = getFileStore(tempDirectory); IFileStore linkDestFile = linkDestLocation.getChild(createUniqueString()); createInFileSystem(linkDestFile); assertThat(linkDestLocation).matches(exists, "exists"); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_079398.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_079398.java index 1adba848a90..289ff9df04f 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_079398.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_079398.java @@ -28,18 +28,16 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceDescription; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.WorkspaceResetExtension; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +@ExtendWith(WorkspaceResetExtension.class) public class Bug_079398 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - @Test - @Ignore("Bug 78398 needs to be fixed") + @Disabled("Bug 78398 needs to be fixed") public void testBug79398() throws Exception { IProject project = getWorkspace().getRoot().getProject("myproject"); IFile file1 = project.getFile("myFile.txt"); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_097608.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_097608.java index 5f65fa035d0..0b66705d81b 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_097608.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_097608.java @@ -14,7 +14,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.Arrays; import java.util.HashMap; @@ -22,19 +22,17 @@ import org.eclipse.core.resources.IMarker; 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; /** * Tests regression of bug 97608 - error restoring workspace * after writing marker with value that is too long. */ +@ExtendWith(WorkspaceResetExtension.class) public class Bug_097608 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - /** * Tests that creating a marker with very long value causes failure. */ diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_098740.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_098740.java index b23663a83ee..5965ed96cba 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_098740.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_098740.java @@ -16,26 +16,24 @@ 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.createTestMonitor; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceVisitor; 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; /** * 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_098740 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - @Test public void testBug() throws CoreException { IProject project = getWorkspace().getRoot().getProject("Bug98740"); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_126104.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_126104.java index 1a119076a5a..1748681ef35 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_126104.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_126104.java @@ -18,8 +18,11 @@ 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.createTestMonitor; +import static org.eclipse.core.tests.resources.ResourceTestUtil.getFileStore; import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromWorkspace; +import java.io.IOException; +import java.nio.file.Path; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.resources.IFile; @@ -27,25 +30,24 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; 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; +import org.junit.jupiter.api.io.TempDir; /** * Tests copying a file to a linked folder that does not exist on disk */ +@ExtendWith(WorkspaceResetExtension.class) public class Bug_126104 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - @Test - public void testBug() throws CoreException { + public void testBug(@TempDir Path tempDirectory) throws CoreException, IOException { IProject project = getWorkspace().getRoot().getProject("p1"); IFile source = project.getFile("source"); createInWorkspace(source); IFolder link = project.getFolder("link"); - IFileStore location = workspaceRule.getTempStore(); + IFileStore location = getFileStore(tempDirectory); link.createLink(location.toURI(), IResource.ALLOW_MISSING_LOCAL, createTestMonitor()); IFile destination = link.getFile(source.getName()); source.copy(destination.getFullPath(), IResource.NONE, createTestMonitor()); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_127562.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_127562.java index 4d5343f3ab4..b3fda8a5f8f 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_127562.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_127562.java @@ -22,19 +22,17 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRunnable; 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; /** * Changing a project description requires the workspace root * scheduling rule. */ +@ExtendWith(WorkspaceResetExtension.class) public class Bug_127562 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - @Test public void testBug() throws CoreException { final IProject project = getWorkspace().getRoot().getProject("Bug127562"); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_132510.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_132510.java index 1049fcf5b5d..c15e3dfe935 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_132510.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_132510.java @@ -19,18 +19,16 @@ import org.eclipse.core.internal.resources.LinkDescription; import org.eclipse.core.internal.resources.ProjectDescription; import org.eclipse.core.runtime.IPath; -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 concurrent modification of the project description link table. */ +@ExtendWith(WorkspaceResetExtension.class) public class Bug_132510 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - @Test public void testBug() { ProjectDescription desc = new ProjectDescription(); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_134364.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_134364.java index a3c132de629..1b25d7cf708 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_134364.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_134364.java @@ -27,9 +27,9 @@ import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.tests.internal.builders.SortBuilder; -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 an error that occurs when a thread tries to read the workspace @@ -39,11 +39,9 @@ * malformed state. The fix was to synchronize the routine that collapses * unused trees in ElementTree. */ +@ExtendWith(WorkspaceResetExtension.class) public class Bug_134364 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - /** * Creates a project with a builder attached */ diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_147232.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_147232.java index 8a68fbd9f1d..b65f3213d97 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_147232.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_147232.java @@ -19,7 +19,7 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.setAutoBuilding; import static org.eclipse.core.tests.resources.ResourceTestUtil.updateProjectDescription; import static org.eclipse.core.tests.resources.ResourceTestUtil.waitForBuild; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; @@ -28,21 +28,19 @@ import org.eclipse.core.resources.IResourceDelta; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.tests.internal.builders.ClearMarkersBuilder; -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 duplicate resource change events caused by a builder that makes * no changes. */ +@ExtendWith(WorkspaceResetExtension.class) public class Bug_147232 implements IResourceChangeListener { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - /** * Records the number of times we have seen the file creation delta */ @@ -64,13 +62,13 @@ public void resourceChanged(IResourceChangeEvent event) { } } - @Before + @BeforeEach public void setUp() throws Exception { // make the builder wait after running to all a POST_CHANGE event to occur before POST_BUILD ClearMarkersBuilder.pauseAfterBuild = true; } - @After + @AfterEach public void tearDown() throws Exception { getWorkspace().removeResourceChangeListener(this); ClearMarkersBuilder.pauseAfterBuild = false; diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_160251.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_160251.java index 9ab5da995c2..f812db2064d 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_160251.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_160251.java @@ -18,10 +18,13 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createInFileSystem; 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.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.eclipse.core.tests.resources.ResourceTestUtil.getFileStore; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import java.io.IOException; +import java.nio.file.Path; import java.util.function.Predicate; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; @@ -31,31 +34,32 @@ import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IResource; 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; +import org.junit.jupiter.api.io.TempDir; /** * Tests regression of bug 160251. In this case, attempting to move a project * to an existing directory on disk failed, but should succeed as long as * the destination directory is empty. */ +@ExtendWith(WorkspaceResetExtension.class) public class Bug_160251 { private static final Predicate isSynchronizedDepthInfinite = resource -> resource .isSynchronized(IResource.DEPTH_INFINITE); - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + private @TempDir Path tempDirectory; /** * The destination directory does not exist. */ @Test - public void testNonExistentDestination() throws CoreException { + public void testNonExistentDestination() throws CoreException, IOException { IProject source = getWorkspace().getRoot().getProject("project"); IFile sourceFile = source.getFile("Important.txt"); - IFileStore destination = workspaceRule.getTempStore(); + IFileStore destination = getFileStore(tempDirectory); IFileStore destinationFile = destination.getChild(sourceFile.getName()); createInWorkspace(source); createInWorkspace(sourceFile); @@ -77,10 +81,10 @@ public void testNonExistentDestination() throws CoreException { * The destination directory exists, but is empty */ @Test - public void testEmptyDestination() throws CoreException { + public void testEmptyDestination() throws CoreException, IOException { IProject source = getWorkspace().getRoot().getProject("project"); IFile sourceFile = source.getFile("Important.txt"); - IFileStore destination = workspaceRule.getTempStore(); + IFileStore destination = getFileStore(tempDirectory); IFileStore destinationFile = destination.getChild(sourceFile.getName()); createInWorkspace(source); createInWorkspace(sourceFile); @@ -106,7 +110,7 @@ public void testEmptyDestination() throws CoreException { public void testOccupiedDestination() throws Exception { IProject source = getWorkspace().getRoot().getProject("project"); IFile sourceFile = source.getFile("Important.txt"); - IFileStore destination = workspaceRule.getTempStore(); + IFileStore destination = getFileStore(tempDirectory); IFileStore destinationFile = destination.getChild(sourceFile.getName()); createInWorkspace(source); createInWorkspace(sourceFile); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_165892.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_165892.java index a779d0c76e6..f589e8e0d0e 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_165892.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_165892.java @@ -18,7 +18,7 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomContentsStream; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -26,9 +26,9 @@ import org.eclipse.core.resources.IResource; 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; /** * Tests regression of bug 165892. Copying a resource should perform a deep @@ -36,11 +36,9 @@ * properties on the destination resource should not affect the properties on the * source resource. */ +@ExtendWith(WorkspaceResetExtension.class) public class Bug_165892 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - /** * Tests copying a file */ diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_185247_LinuxTests.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_185247_LinuxTests.java index 2f8b7cdb216..274fe6913c9 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_185247_LinuxTests.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_185247_LinuxTests.java @@ -10,12 +10,11 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; -import static org.eclipse.core.tests.harness.FileSystemHelper.getRandomLocation; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; @@ -37,33 +36,32 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform.OS; import org.eclipse.core.runtime.URIUtil; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; +import org.eclipse.core.tests.resources.util.WorkspaceResetExtension; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; /** * Test cases for symbolic links in projects. */ +@ExtendWith(WorkspaceResetExtension.class) public class Bug_185247_LinuxTests { + private String testMethodName; - @Rule - public TestName testName = new TestName(); - - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + private @TempDir Path tempDirectory; private IPath testCasesLocation; - @Before - public void setUp() throws Exception { + @BeforeEach + public void setUp(TestInfo testInfo) throws Exception { assumeTrue("only relevant on Linux", OS.isLinux()); - IPath randomLocation = getRandomLocation(); - workspaceRule.deleteOnTearDown(randomLocation); + testMethodName = testInfo.getTestMethod().get().getName(); + IPath randomLocation = IPath.fromPath(tempDirectory); testCasesLocation = randomLocation.append("bug185247LinuxTests"); - assertTrue("failed to create test location: " + testCasesLocation, testCasesLocation.toFile().mkdirs()); + assertTrue(testCasesLocation.toFile().mkdirs(), "failed to create test location: " + testCasesLocation); extractTestCasesArchive(testCasesLocation); } @@ -72,7 +70,7 @@ private void extractTestCasesArchive(IPath outputLocation) throws Exception { .getEntry("resources/bug185247/bug185247_LinuxTests.zip"); URL archiveLocation = FileLocator.resolve(testCasesArchive); File archive = URIUtil.toFile(archiveLocation.toURI()); - assertNotNull("cannot find archive with test cases", archive); + assertNotNull(archive, "cannot find archive with test cases"); unzip(archive, outputLocation.toFile()); } @@ -103,7 +101,7 @@ public void test6_nonrecursive() throws Exception { private void runProjectTestCase() throws Exception { // refresh should hang, if bug 105554 re-occurs - importProjectAndRefresh(testName.getMethodName()); + importProjectAndRefresh(testMethodName); } private void importProjectAndRefresh(String projectName) throws Exception { @@ -119,7 +117,7 @@ private IProject importTestProject(String projectName) throws Exception { projectDescription.setLocationURI(URI.create(projectRoot)); testProject.create(projectDescription, createTestMonitor()); testProject.open(createTestMonitor()); - assertTrue("expected project to be open: " + projectName, testProject.isAccessible()); + assertTrue(testProject.isAccessible(), "expected project to be open: " + projectName); return testProject; } @@ -130,20 +128,20 @@ private static void unzip(File archive, File outputDirectory) throws Exception { } private static void executeCommand(String[] command, File outputDirectory) throws Exception { - assertTrue("output directory does not exist: " + outputDirectory, outputDirectory.exists()); + assertTrue(outputDirectory.exists(), "output directory does not exist: " + outputDirectory); ProcessBuilder processBuilder = new ProcessBuilder(command); File commandOutputFile = new File(outputDirectory, "commandOutput.txt"); if (!commandOutputFile.exists()) { - assertTrue("failed to create standard output and error file for unzip command", - commandOutputFile.createNewFile()); + assertTrue(commandOutputFile.createNewFile(), + "failed to create standard output and error file for unzip command"); } processBuilder.redirectOutput(commandOutputFile); processBuilder.redirectError(commandOutputFile); Process process = processBuilder.start(); int commandExitCode = process.waitFor(); String output = formatCommandOutput(command, commandOutputFile); - assertTrue("Failed to delete command output file. " + output, commandOutputFile.delete()); - assertEquals("Failed to execute commmand. " + output, 0, commandExitCode); + assertTrue(commandOutputFile.delete(), "Failed to delete command output file. " + output); + assertEquals(0, commandExitCode, "Failed to execute commmand. " + output); } private static String formatCommandOutput(String[] command, File commandOutputFile) throws IOException { diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_185247_recursiveLinks.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_185247_recursiveLinks.java index 7f3b8fd9b2d..34487877e93 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_185247_recursiveLinks.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_185247_recursiveLinks.java @@ -12,15 +12,15 @@ import static org.eclipse.core.tests.harness.FileSystemHelper.canCreateSymLinks; import static org.eclipse.core.tests.harness.FileSystemHelper.createSymLink; -import static org.eclipse.core.tests.harness.FileSystemHelper.getRandomLocation; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; -import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; +import java.nio.file.Path; import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.internal.resources.ProjectDescription; import org.eclipse.core.resources.IProject; @@ -28,26 +28,27 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; +import org.eclipse.core.tests.resources.util.WorkspaceResetExtension; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; /** * Tests for recursive symbolic links in projects. */ +@ExtendWith(WorkspaceResetExtension.class) public class Bug_185247_recursiveLinks { - @Rule - public TestName testName = new TestName(); + private @TempDir Path tempDirectory; - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + private String testMethodName; - @Before - public void requireCanCreateSymlinks() throws IOException { + @BeforeEach + public void requireCanCreateSymlinks(TestInfo testInfo) throws IOException { assumeTrue("only relevant for platforms supporting symbolic links", canCreateSymLinks()); + testMethodName = testInfo.getTestMethod().get().getName(); } /** @@ -177,9 +178,8 @@ public void test5_linkParentDirectoyTwiceWithAbsolutePath() throws Exception { } private void runTest(CreateTestProjectStructure createSymlinks) throws MalformedURLException, Exception { - String projectName = testName.getMethodName(); - IPath testRoot = getRandomLocation(); - workspaceRule.deleteOnTearDown(testRoot); + String projectName = testMethodName; + IPath testRoot = IPath.fromPath(tempDirectory); IPath projectRoot = testRoot.append("bug185247recursive").append(projectName); File directory = projectRoot.append("directory").toFile(); createDirectory(directory); @@ -193,11 +193,11 @@ private void runTest(CreateTestProjectStructure createSymlinks) throws Malformed } private static void createDirectory(File directory) { - assertTrue("failed to create test directory: " + directory, directory.mkdirs()); + assertTrue(directory.mkdirs(), "failed to create test directory: " + directory); } void createSymlink(File directory, String linkName, String linkTarget) throws IOException { - assertTrue("symlinks not supported by platform", canCreateSymLinks()); + assertTrue(canCreateSymLinks(), "symlinks not supported by platform"); boolean isDir = true; createSymLink(directory, linkName, linkTarget, isDir); } @@ -214,7 +214,7 @@ private IProject importTestProject(String projectName, URI projectRootLocation) projectDescription.setLocationURI(projectRootLocation); testProject.create(projectDescription, createTestMonitor()); testProject.open(createTestMonitor()); - assertTrue("expected project to be open: " + projectName, testProject.isAccessible()); + assertTrue(testProject.isAccessible(), "expected project to be open: " + projectName); return testProject; } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_192631.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_192631.java index bb581689cf8..6a641f4d449 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_192631.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_192631.java @@ -16,7 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.net.URI; import java.net.URISyntaxException; @@ -33,20 +33,18 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.tests.internal.filesystem.ram.MemoryTree; import org.eclipse.core.tests.internal.filesystem.remote.RemoteFileSystem; -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; /** * Test for bug 192631 */ +@ExtendWith(WorkspaceResetExtension.class) public class Bug_192631 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - private static final String USER_A = "userA"; private static final String USER_B = "userB"; private static final String HOST_A = "hostA.example.com"; @@ -58,12 +56,12 @@ public class Bug_192631 { private static final String FOLDER_A = "/common/folderA"; private static final String FOLDER_B = "/common/folderB"; - @Before + @BeforeEach public void setUp() { MemoryTree.TREE.deleteAll(); } - @After + @AfterEach public void tearDown() { MemoryTree.TREE.deleteAll(); } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_226264.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_226264.java index be5c1f03d37..f1b8cb8a85d 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_226264.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_226264.java @@ -26,15 +26,13 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -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_226264 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - @Test public void testBug() throws CoreException, InterruptedException { IWorkspace workspace = ResourcesPlugin.getWorkspace(); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_231301.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_231301.java index 0881c109780..14ce5dcde9c 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_231301.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_231301.java @@ -27,15 +27,13 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -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_231301 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - @Test public void testBug() throws CoreException, InterruptedException { IWorkspace workspace = ResourcesPlugin.getWorkspace(); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_233939.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_233939.java index 0be2ede790f..70ca21c6fd9 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_233939.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_233939.java @@ -22,10 +22,12 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import static org.eclipse.core.tests.resources.ResourceTestUtil.createUniqueString; +import static org.eclipse.core.tests.resources.ResourceTestUtil.getFileStore; import static org.junit.Assume.assumeTrue; import java.io.IOException; import java.net.URI; +import java.nio.file.Path; import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.internal.utils.FileUtil; @@ -37,17 +39,16 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -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.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; +@ExtendWith(WorkspaceResetExtension.class) public class Bug_233939 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - - @Before + @BeforeEach public void requireCanCreateSymlinks() throws IOException { assumeTrue("only relevant for platforms supporting symbolic links", canCreateSymLinks()); } @@ -75,7 +76,7 @@ protected boolean isSameLocation(IFile file, IFileStore store) { } @Test - public void testBug() throws Exception { + public void testBug(@TempDir Path tempDirectory) throws Exception { String fileName = "file.txt"; IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); @@ -87,7 +88,7 @@ public void testBug() throws Exception { project.open(createTestMonitor()); // create a file: getTempStore() will be cleaned up in tearDown() - IFileStore tempFileStore = workspaceRule.getTempStore().getChild(fileName); + IFileStore tempFileStore = getFileStore(tempDirectory).getChild(fileName); createInFileSystem(tempFileStore); IPath fileInTempDirPath = URIUtil.toPath(tempFileStore.toURI()); @@ -104,9 +105,9 @@ public void testBug() throws Exception { } @Test - public void testMultipleLinksToFolder() throws Exception { + public void testMultipleLinksToFolder(@TempDir Path tempDirectory) throws Exception { // create a folder: getTempStore() will be cleaned up in tearDown() - IFileStore tempStore = workspaceRule.getTempStore(); + IFileStore tempStore = getFileStore(tempDirectory); createInFileSystem(tempStore.getChild("foo.txt")); IPath tempFolderPath = URIUtil.toPath(tempStore.toURI()); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_264182.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_264182.java index 9a14b6f8055..2c9be1269b7 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_264182.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_264182.java @@ -17,9 +17,11 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.assertDoesNotExistInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInFileSystem; import static org.eclipse.core.tests.resources.ResourceTestUtil.createUniqueString; +import static org.eclipse.core.tests.resources.ResourceTestUtil.getFileStore; import static org.eclipse.core.tests.resources.ResourceTestUtil.setReadOnly; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; +import java.nio.file.Path; import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; @@ -27,21 +29,20 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; -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; +import org.junit.jupiter.api.io.TempDir; +@ExtendWith(WorkspaceResetExtension.class) public class Bug_264182 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - IProject project; IFile dotProject; - @Before + @BeforeEach public void setUp() throws Exception { // create a project project = getWorkspace().getRoot().getProject(createUniqueString()); @@ -53,17 +54,17 @@ public void setUp() throws Exception { setReadOnly(dotProject, true); } - @After + @AfterEach public void tearDown() throws Exception { // make the description writable setReadOnly(dotProject, false); } @Test - public void testBug() throws Exception { + public void testBug(@TempDir Path tempDirectory) throws Exception { // create a linked resource final IFile file = project.getFile(createUniqueString()); - IFileStore tempFileStore = workspaceRule.getTempStore(); + IFileStore tempFileStore = getFileStore(tempDirectory).getChild("temp"); createInFileSystem(tempFileStore); assertThrows(CoreException.class, () -> file.createLink(tempFileStore.toURI(), IResource.NONE, new NullProgressMonitor())); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_265810.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_265810.java index ff5cc5ed2fe..5e437e8829a 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_265810.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_265810.java @@ -15,15 +15,15 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; -import static org.eclipse.core.tests.harness.FileSystemHelper.getRandomLocation; import static org.eclipse.core.tests.resources.ResourceTestUtil.assertDoesNotExistInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInputStream; import static org.eclipse.core.tests.resources.ResourceTestUtil.createUniqueString; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicReference; @@ -35,22 +35,22 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.function.ThrowingRunnable; +import org.eclipse.core.tests.resources.util.WorkspaceResetExtension; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.function.Executable; +import org.junit.jupiter.api.io.TempDir; +@ExtendWith(WorkspaceResetExtension.class) public class Bug_265810 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + private @TempDir Path tempDirectory; List resourceDeltas = new ArrayList<>(); public IPath createFolderAtRandomLocation() throws IOException { - IPath path = getRandomLocation(); + IPath path = IPath.fromPath(tempDirectory).append(createUniqueString()); path.toFile().createNewFile(); - workspaceRule.deleteOnTearDown(path); return path; } @@ -80,7 +80,7 @@ public void testBug() throws Throwable { // save the .project [2] content byte[] dotProject2 = storeDotProject(project); - final AtomicReference listenerInMainThreadCallback = new AtomicReference<>(() -> { + final AtomicReference listenerInMainThreadCallback = new AtomicReference<>(() -> { }); IResourceChangeListener listener = event -> { @@ -116,7 +116,7 @@ public void testBug() throws Throwable { getWorkspace().removeResourceChangeListener(listener); } - listenerInMainThreadCallback.get().run(); + listenerInMainThreadCallback.get().execute(); // create newFile as a non-linked resource newFile.create(createInputStream("content"), IResource.NONE, new NullProgressMonitor()); @@ -135,7 +135,7 @@ public void testBug() throws Throwable { getWorkspace().removeResourceChangeListener(listener); } - listenerInMainThreadCallback.get().run(); + listenerInMainThreadCallback.get().execute(); } private byte[] storeDotProject(IProject project) throws Exception { diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_288315.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_288315.java index ea0c18365d4..d6ef32b8063 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_288315.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_288315.java @@ -13,25 +13,23 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.Arrays; import org.eclipse.core.resources.IMarker; 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; /** * Tests regression of bug 288315 - MarkerInfo.setAttributes(Map map) calls * checkValidAttribute which throws IllegalArgumentException. */ +@ExtendWith(WorkspaceResetExtension.class) public class Bug_288315 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - /** * Tests that creating a marker with very long value causes failure. */ diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_297635.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_297635.java index 1406bd521a4..426d5485c06 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_297635.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_297635.java @@ -29,12 +29,12 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Platform; import org.eclipse.core.tests.harness.BundleTestingHelper; -import org.eclipse.core.tests.resources.WorkspaceTestRule; import org.eclipse.core.tests.resources.content.ContentTypeTest; -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; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; @@ -42,18 +42,16 @@ /** * Tests regression of bug 297635 */ +@ExtendWith(WorkspaceResetExtension.class) public class Bug_297635 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - - @Before + @BeforeEach public void setUp() throws Exception { BundleWithSaveParticipant.install(); saveFull(); } - @After + @AfterEach public void tearDown() throws BundleException { BundleWithSaveParticipant.uninstall(); } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_303517.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_303517.java index df4c2cdb968..7d06525e888 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_303517.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_303517.java @@ -21,8 +21,8 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import static org.eclipse.core.tests.resources.ResourceTestUtil.touchInFilesystem; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.File; import java.io.InputStream; @@ -36,21 +36,19 @@ 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.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 that, when the workspace discovery a resource is out-of-sync * it brings the resource back into sync in a timely manner. */ +@ExtendWith(WorkspaceResetExtension.class) public class Bug_303517 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - private static final Predicate isSynchronizedDepthInfinite = resource -> resource .isSynchronized(IResource.DEPTH_INFINITE); @@ -61,7 +59,7 @@ public class Bug_303517 { "/Bug303517/Folder/Resource", }; private boolean originalRefreshSetting; - @Before + @BeforeEach public void setUp() throws Exception { IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES); originalRefreshSetting = prefs.getBoolean(ResourcesPlugin.PREF_AUTO_REFRESH, false); @@ -71,7 +69,7 @@ public void setUp() throws Exception { createInWorkspace(resources); } - @After + @AfterEach public void tearDown() throws Exception { IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES); prefs.putBoolean(ResourcesPlugin.PREF_AUTO_REFRESH, originalRefreshSetting); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_329836.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_329836.java index a3ed7d4f892..bf2fd91d97d 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_329836.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_329836.java @@ -18,30 +18,31 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createInFileSystem; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import static org.eclipse.core.tests.resources.ResourceTestUtil.createUniqueString; +import static org.eclipse.core.tests.resources.ResourceTestUtil.getFileStore; import static org.eclipse.core.tests.resources.ResourceTestUtil.isAttributeSupported; import static org.junit.Assume.assumeTrue; +import java.nio.file.Path; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileInfo; import org.eclipse.core.filesystem.IFileStore; 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; +import org.junit.jupiter.api.io.TempDir; /** * Test for bug 329836 */ +@ExtendWith(WorkspaceResetExtension.class) public class Bug_329836 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - @Test - public void testBug() throws Exception { + public void testBug(@TempDir Path tempDirectory) throws Exception { assumeTrue("only relevant on Mac", OS.isMac()); - IFileStore fileStore = workspaceRule.getTempStore().getChild(createUniqueString()); + IFileStore fileStore = getFileStore(tempDirectory).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/regression/Bug_331445.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_331445.java index 6b00520fa27..921b9a1cbe3 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_331445.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_331445.java @@ -16,8 +16,8 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import static org.eclipse.core.tests.resources.ResourceTestUtil.createUniqueString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import java.net.URI; import java.net.URISyntaxException; @@ -28,15 +28,13 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -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_331445 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - @Test public void testBug() throws CoreException, URISyntaxException { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_332543.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_332543.java index 33968f03c5c..9c14b652aa7 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_332543.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_332543.java @@ -16,7 +16,7 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createInFileSystem; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import static org.eclipse.core.tests.resources.ResourceTestUtil.createUniqueString; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; @@ -37,20 +37,18 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.tests.internal.filesystem.wrapper.WrapperFileStore; import org.eclipse.core.tests.internal.filesystem.wrapper.WrapperFileSystem; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.After; -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.Test; +import org.junit.jupiter.api.extension.ExtendWith; /** * This tests that I/O Exception on OuptuStream#close() after IFile#setContents * is correctly reported. */ +@ExtendWith(WorkspaceResetExtension.class) public class Bug_332543 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - /** * Wrapper FS which throws an IOException when someone closes an output * stream... @@ -77,7 +75,7 @@ public void close() throws java.io.IOException { } } - @After + @AfterEach public void tearDown() { WrapperFileSystem.setCustomFileStore(null); } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_378156.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_378156.java index 578d559a4b2..524c79084f4 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_378156.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_378156.java @@ -35,20 +35,18 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Status; -import org.eclipse.core.tests.resources.WorkspaceTestRule; import org.eclipse.core.tests.resources.usecase.SignaledBuilder; -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 a timing problem where a canceled waiting thread could cause a change * in another thread to skip building. */ +@ExtendWith(WorkspaceResetExtension.class) public class Bug_378156 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - class ModifyFileJob extends WorkspaceJob { private boolean cancel; private final IFile jobFile; diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_380386.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_380386.java index 36373b936c5..667a5a1a086 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_380386.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_380386.java @@ -13,27 +13,25 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.eclipse.core.resources.IPathVariableManager; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.WorkspaceResetExtension; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; /** * Test for Bug 380386 */ +@ExtendWith(WorkspaceResetExtension.class) public class Bug_380386 { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - @Test - @Ignore("This regression test has to be rewritten in a proper way") + @Disabled("This regression test has to be rewritten in a proper way") public void testBug() throws Exception { String path = "C:\\temp"; java.net.URI value = new java.io.File(path).toURI(); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_530868.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_530868.java index 93811549c2d..2d51993317d 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_530868.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_530868.java @@ -15,8 +15,8 @@ import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; -import static org.junit.Assert.assertNotEquals; import static org.junit.Assume.assumeFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import java.io.ByteArrayInputStream; import org.eclipse.core.filesystem.provider.FileInfo; @@ -25,33 +25,28 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Platform.OS; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; +import org.eclipse.core.tests.resources.util.WorkspaceResetExtension; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.extension.ExtendWith; /** * Test for Bug 530868: millisecond resolution of file timestamps with native * provider. */ +@ExtendWith(WorkspaceResetExtension.class) public class Bug_530868 { - @Rule - public TestName testName = new TestName(); - - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - private IProject testProject; private IFile testFile; - @Before - public void setUp() throws Exception { + @BeforeEach + public void setUp(TestInfo testInfo) throws Exception { testProject = getWorkspace().getRoot().getProject(Bug_530868.class + "TestProject"); testProject.create(createTestMonitor()); testProject.open(createTestMonitor()); - testFile = testProject.getFile(testName.getMethodName()); + testFile = testProject.getFile(testInfo.getTestMethod().get().getName()); } @@ -74,8 +69,8 @@ public void testMillisecondResolution() throws Exception { long timestamp3 = modifyTestFileAndFetchTimestamp("some contents 3"); String failMessage = "expected different timestamps for modifications in quick succession"; - assertNotEquals(failMessage, timestamp1, timestamp2); - assertNotEquals(failMessage, timestamp2, timestamp3); + assertNotEquals(timestamp1, timestamp2, failMessage); + assertNotEquals(timestamp2, timestamp3, failMessage); } finally { LocalFileNativesManager.reset(); } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFileTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFileTest.java index f75eb601202..0c333a57054 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFileTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFileTest.java @@ -19,10 +19,10 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomContentsStream; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import static org.eclipse.core.tests.resources.ResourceTestUtil.isReadOnlySupported; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -32,23 +32,21 @@ import org.eclipse.core.resources.IResourceStatus; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Platform.OS; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.WorkspaceResetExtension; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +@ExtendWith(WorkspaceResetExtension.class) public class IFileTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - /** * Bug states that the error code in the CoreException which is thrown when * you try to create a file in a read-only folder on Linux should be * ERROR_WRITE. */ @Test - @Ignore("This test is no longer valid since the error code is dependent on whether or not the parent folder is marked as read-only. We need to write a different test to make the file.create fail.") + @Disabled("This test is no longer valid since the error code is dependent on whether or not the parent folder is marked as read-only. We need to write a different test to make the file.create fail.") public void testBug25658() throws CoreException { // We need to know whether or not we can unset the read-only flag // in order to perform this test. diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFolderTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFolderTest.java index d9e37be6d53..4eae448b887 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFolderTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFolderTest.java @@ -20,9 +20,9 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import static org.eclipse.core.tests.resources.ResourceTestUtil.isReadOnlySupported; -import static org.junit.Assert.assertEquals; -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.util.function.Predicate; import org.eclipse.core.filesystem.EFS; @@ -35,15 +35,13 @@ import org.eclipse.core.resources.IWorkspaceRoot; 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; +@ExtendWith(WorkspaceResetExtension.class) public class IFolderTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - /** * Bug requests that if a failed folder creation occurs on Linux that we check * the immediate parent to see if it is read-only so we can return a better diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IProjectTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IProjectTest.java index 5888ea0f0db..79512c730e0 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IProjectTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IProjectTest.java @@ -23,7 +23,7 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createUniqueString; import static org.eclipse.core.tests.resources.ResourceTestUtil.touchInFilesystem; import static org.eclipse.core.tests.resources.ResourceTestUtil.waitForBuild; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import org.eclipse.core.resources.ICommand; import org.eclipse.core.resources.IFile; @@ -37,16 +37,14 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Platform; -import org.eclipse.core.tests.resources.WorkspaceTestRule; import org.eclipse.core.tests.resources.usecase.SignaledBuilder; -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 IProjectTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - @Test public void test_1G0XIMA() throws CoreException { /* common objects */ diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IResourceTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IResourceTest.java index f8b2a8140a8..03491d8988e 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IResourceTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IResourceTest.java @@ -26,12 +26,12 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.ensureOutOfSync; import static org.eclipse.core.tests.resources.ResourceTestUtil.isAttributeSupported; import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromWorkspace; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.FileOutputStream; import java.io.InputStream; @@ -60,17 +60,15 @@ import org.eclipse.core.runtime.Platform.OS; import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.tests.resources.ResourceDeltaVerifier; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.function.ThrowingRunnable; +import org.eclipse.core.tests.resources.util.WorkspaceResetExtension; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.function.Executable; +@ExtendWith(WorkspaceResetExtension.class) public class IResourceTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - /** * 1G9RBH5: ITPCORE:WIN98 - IFile.appendContents might lose data */ @@ -170,7 +168,7 @@ public boolean visit(IResourceDelta aDelta) { } } - final AtomicReference listenerInMainThreadCallback = new AtomicReference<>(() -> { + final AtomicReference listenerInMainThreadCallback = new AtomicReference<>(() -> { }); IResourceChangeListener listener = event -> { IResourceDelta delta = event.getDelta(); @@ -201,7 +199,7 @@ public boolean visit(IResourceDelta aDelta) { } finally { getWorkspace().removeResourceChangeListener(listener); } - listenerInMainThreadCallback.get().run(); + listenerInMainThreadCallback.get().execute(); } /** @@ -252,7 +250,7 @@ public void testCopy_1GA6QJP() throws CoreException, InterruptedException { long actual = destination.getLocation().toFile().lastModified(); // java.io.File.lastModified() has only second accuracy on some OSes long difference = Math.abs(expected - actual); - assertTrue("time difference>1000ms: " + difference, difference <= 1000); + assertTrue(difference <= 1000, "time difference>1000ms: " + difference); } /** @@ -275,9 +273,9 @@ public void testCreate_1FW87XF() throws Throwable { assertThat(file).matches(IFile::exists, "exists"); IFile anotherFile = project.getFile("File"); - ThrowingRunnable forcedFileCreation = () -> anotherFile.create(createRandomContentsStream(), true, null); + Executable forcedFileCreation = () -> anotherFile.create(createRandomContentsStream(), true, null); if (caseSensitive) { - forcedFileCreation.run(); + forcedFileCreation.execute(); } else { assertThrows(CoreException.class, forcedFileCreation); } @@ -286,17 +284,17 @@ public void testCreate_1FW87XF() throws Throwable { anotherFile.delete(true, false, null); // force = false - ThrowingRunnable fileCreation = () -> anotherFile.create(createRandomContentsStream(), false, null); + Executable fileCreation = () -> anotherFile.create(createRandomContentsStream(), false, null); if (caseSensitive) { - fileCreation.run(); + fileCreation.execute(); } else { assertThrows(CoreException.class, fileCreation); } // test refreshLocal - ThrowingRunnable refresh = () -> anotherFile.refreshLocal(IResource.DEPTH_ZERO, createTestMonitor()); + Executable refresh = () -> anotherFile.refreshLocal(IResource.DEPTH_ZERO, createTestMonitor()); if (caseSensitive) { - refresh.run(); + refresh.execute(); } else { assertThrows(CoreException.class, refresh); } @@ -356,7 +354,7 @@ public void testCreate_1GD7CSU() throws Exception { * OS and file system. */ @Test - @Ignore("This test cannot be done automatically because we don't know in that file system we are running. Will leave test here in case it needs to be run it in a special environment.") + @Disabled("This test cannot be done automatically because we don't know in that file system we are running. Will leave test here in case it needs to be run it in a special environment.") public void testDelete_1GD3ZUZ() throws CoreException { IProject project = getWorkspace().getRoot().getProject("MyProject"); IFile file = project.getFile("MyFile"); @@ -470,7 +468,7 @@ public void testGetContents_1GBZD4S() throws Throwable { createInputStream(newContents).transferTo(output); } - final AtomicReference listenerInMainThreadCallback = new AtomicReference<>(() -> { + final AtomicReference listenerInMainThreadCallback = new AtomicReference<>(() -> { }); IResourceChangeListener listener = event -> { listenerInMainThreadCallback.set(() -> { @@ -484,7 +482,7 @@ public void testGetContents_1GBZD4S() throws Throwable { } finally { getWorkspace().removeResourceChangeListener(listener); } - listenerInMainThreadCallback.get().run(); + listenerInMainThreadCallback.get().execute(); CoreException exception = assertThrows(CoreException.class, () -> { try (InputStream is = target.getContents(false)) { diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IWorkspaceTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IWorkspaceTest.java index 06469b3e7ed..257e568fb2d 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IWorkspaceTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IWorkspaceTest.java @@ -15,11 +15,13 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; -import static org.eclipse.core.tests.harness.FileSystemHelper.getRandomLocation; import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomContentsStream; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import org.eclipse.core.internal.resources.Workspace; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFileState; @@ -30,15 +32,14 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; -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; +import org.junit.jupiter.api.io.TempDir; +@ExtendWith(WorkspaceResetExtension.class) public class IWorkspaceTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - /** * 1GDKIHD: ITPCORE:WINNT - API - IWorkspace.move needs to keep history */ @@ -140,11 +141,11 @@ public void testMultiDelete_1GDGRIZ() throws CoreException { } @Test - public void test_8974() throws CoreException { + public void test_8974(@TempDir Path tempDirectory) throws CoreException, IOException { IProject one = getWorkspace().getRoot().getProject("One"); - IPath oneLocation = getRandomLocation().append(one.getName()); - oneLocation.toFile().mkdirs(); - workspaceRule.deleteOnTearDown(oneLocation.removeLastSegments(1)); + Path oneTempDirectory = tempDirectory.toRealPath().resolve(one.getName()); + IPath oneLocation = IPath.fromPath(oneTempDirectory); + Files.createDirectories(oneTempDirectory); IProjectDescription oneDescription = getWorkspace().newProjectDescription(one.getName()); oneDescription.setLocation(oneLocation); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/LocalStoreRegressionTests.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/LocalStoreRegressionTests.java index 718d0b5ad90..571aa6bb0f2 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/LocalStoreRegressionTests.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/LocalStoreRegressionTests.java @@ -20,7 +20,7 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromFileSystem; import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromWorkspace; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.DataInputStream; import java.io.DataOutputStream; @@ -35,15 +35,13 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; -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 LocalStoreRegressionTests { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - /** * 1FU4PJA: ITPCORE:ALL - refreshLocal for new file with depth zero doesn't work */ @@ -86,7 +84,6 @@ public void test_1FU4TW7() throws Throwable { public void test_1G65KR1() throws IOException { /* evaluate test environment */ IPath root = getWorkspace().getRoot().getLocation().append("" + new Date().getTime()); - workspaceRule.deleteOnTearDown(root); File temp = root.toFile(); temp.mkdirs(); @@ -94,17 +91,21 @@ public void test_1G65KR1() throws IOException { Workspace.clear(target); // make sure there was nothing here before assertThat(target).matches(not(File::exists), "not exists"); - // write chunks - try (SafeChunkyOutputStream output = new SafeChunkyOutputStream(target); - DataOutputStream dos = new DataOutputStream(output)) { - dos.writeLong(1234567890l); - output.succeed(); - } + try { + // write chunks + try (SafeChunkyOutputStream output = new SafeChunkyOutputStream(target); + DataOutputStream dos = new DataOutputStream(output)) { + dos.writeLong(1234567890l); + output.succeed(); + } - // read chunks - try (SafeChunkyInputStream input = new SafeChunkyInputStream(target); - DataInputStream dis = new DataInputStream(input)) { - assertEquals(dis.readLong(), 1234567890l); + // read chunks + try (SafeChunkyInputStream input = new SafeChunkyInputStream(target); + DataInputStream dis = new DataInputStream(input)) { + assertEquals(dis.readLong(), 1234567890l); + } + } finally { + removeFromFileSystem(temp); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/NLTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/NLTest.java index 5a8ede97d76..f763611afce 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/NLTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/NLTest.java @@ -28,15 +28,13 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; 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 NLTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - public void getFileNames(List list, char begin, char end) { char current = begin; int index = 0; diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GEAB3C_Test.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GEAB3C_Test.java index 806abf8ea88..30b24bee878 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GEAB3C_Test.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GEAB3C_Test.java @@ -30,17 +30,15 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.core.tests.resources.ResourceDeltaVerifier; -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; +@ExtendWith(WorkspaceResetExtension.class) public class PR_1GEAB3C_Test { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - ResourceDeltaVerifier verifier; protected static final String VERIFIER_NAME = "TestListener"; @@ -49,7 +47,7 @@ public class PR_1GEAB3C_Test { * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. */ - @Before + @BeforeEach public void setUp() { //ensure background work is done before adding verifier waitForBuild(); @@ -62,7 +60,7 @@ public void setUp() { * Tears down the fixture, for example, close a network connection. * This method is called after a test is executed. */ - @After + @AfterEach public void tearDown() { getWorkspace().removeResourceChangeListener(verifier); } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GH2B0N_Test.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GH2B0N_Test.java index d665a6dc57f..94f49be7b85 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GH2B0N_Test.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GH2B0N_Test.java @@ -16,29 +16,26 @@ import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.harness.FileSystemHelper.getTempDir; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; -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 PR_1GH2B0N_Test { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - @Test public void test_1GH2B0N() throws CoreException { IPath path = getTempDir().append("1GH2B0N"); IProject project = getWorkspace().getRoot().getProject("MyProject"); IProjectDescription description = getWorkspace().newProjectDescription("MyProject"); IPath projectLocation = path.append(project.getName()); - workspaceRule.deleteOnTearDown(projectLocation); description.setLocation(projectLocation); project.create(description, createTestMonitor()); project.open(createTestMonitor()); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GHOM0N_Test.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GHOM0N_Test.java index c394f387e7d..caa2ee94173 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GHOM0N_Test.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GHOM0N_Test.java @@ -24,15 +24,13 @@ import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.IncrementalProjectBuilder; 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 PR_1GHOM0N_Test { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - /* * Ensure that we get ADDED and OPEN in the delta when we create and open * a project in a workspace runnable. diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug202384.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug202384.java index d3d3156d2ba..3200302b522 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug202384.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug202384.java @@ -16,9 +16,9 @@ import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; -import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import org.eclipse.core.resources.IProject; diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/util/WorkspaceResetExtension.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/util/WorkspaceResetExtension.java index fd502617e85..937eeb73c1b 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/util/WorkspaceResetExtension.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/util/WorkspaceResetExtension.java @@ -15,7 +15,7 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import static org.eclipse.core.tests.resources.ResourceTestUtil.waitForBuild; import static org.eclipse.core.tests.resources.ResourceTestUtil.waitForRefresh; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.File; import java.util.ArrayList; @@ -41,7 +41,7 @@ public void beforeEach(ExtensionContext context) throws Exception { // Wait for any pending refresh operation, in particular from startup waitForRefresh(); TestUtil.log(IStatus.INFO, context.getDisplayName(), "setUp"); - assertNotNull("Workspace was not set up", getWorkspace()); + assertNotNull(getWorkspace(), "Workspace was not set up"); FreezeMonitor.expectCompletionInAMinute(); waitForRefresh(); }