diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/CharsetTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/CharsetTest.java index 508388197b4..141b46adfff 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/CharsetTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/CharsetTest.java @@ -34,6 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.FileWriter; import java.io.IOException; @@ -1389,7 +1390,7 @@ public void verifyDelta(IResourceDelta delta) { * This verifier succeeds if either all expected changes are received in a * single delta, or if each expected change is received in a delta of its own. */ - private class MultipleDeltasCharsetVerifier extends org.junit.Assert implements IResourceChangeListener { + private class MultipleDeltasCharsetVerifier implements IResourceChangeListener { private final int flags; private final CharsetVerifier singleDeltaVerifier; @@ -1482,7 +1483,7 @@ void assertExpectedDeltasWereReceived() { failMessage.append(deltaVerifier.getMessage()); failMessage.append(System.lineSeparator()); } - assertTrue(failMessage.toString(), validDeltas); + assertTrue(validDeltas, failMessage.toString()); } } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/FilteredResourceTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/FilteredResourceTest.java index 4ec51a988fa..f0091da68d0 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/FilteredResourceTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/FilteredResourceTest.java @@ -22,7 +22,7 @@ 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.removeFromWorkspace; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.ByteArrayOutputStream; import java.io.File; @@ -49,9 +49,12 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.FileStoreAutoDeleteExtension; +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.extension.RegisterExtension; /** * Tests the following API methods: @@ -61,12 +64,14 @@ * This test tests resource filters with projects, folders, linked resource folders, * and moving those resources to different parents. */ +@ExtendWith(WorkspaceResetExtension.class) public class FilteredResourceTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - private static final String REGEX_FILTER_PROVIDER = "org.eclipse.core.resources.regexFilterMatcher"; + + @RegisterExtension + private final FileStoreAutoDeleteExtension fileStoreExtension = new FileStoreAutoDeleteExtension(); + protected String childName = "File.txt"; protected IProject closedProject; protected IFile existingFileInExistingProject; @@ -106,7 +111,7 @@ protected URI resolve(URI uri) { return uri; } - @Before + @BeforeEach public void setUp() throws Exception { existingProject = getWorkspace().getRoot().getProject("ExistingProject"); otherExistingProject = getWorkspace().getRoot().getProject("OtherExistingProject"); @@ -122,7 +127,7 @@ public void setUp() throws Exception { nonExistingFileInOtherExistingProject = otherExistingProject.getFile("nonExistingFileInOtherExistingProject"); nonExistingFileInExistingFolder = existingFolderInExistingProject.getFile("nonExistingFileInExistingFolder"); localFolder = getRandomLocation(); - workspaceRule.deleteOnTearDown(resolve(localFolder)); + fileStoreExtension.deleteOnTearDown(resolve(localFolder)); localFile = localFolder.append(childName); doCleanup(); } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IFileTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IFileTest.java index 89f5b575b80..68b5bd163fa 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IFileTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IFileTest.java @@ -30,10 +30,10 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.ensureOutOfSync; import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromFileSystem; import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromWorkspace; -import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertArrayEquals; 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.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IProjectTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IProjectTest.java index 76c4c19708a..b770da7d6a9 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IProjectTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IProjectTest.java @@ -31,13 +31,13 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.getLineSeparatorFromFile; import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.waitForRefresh; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; @@ -65,16 +65,20 @@ import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.core.tests.harness.FussyProgressMonitor; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.FileStoreAutoDeleteExtension; +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.extension.RegisterExtension; import org.osgi.service.prefs.BackingStoreException; import org.osgi.service.prefs.Preferences; +@ExtendWith(WorkspaceResetExtension.class) public class IProjectTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + @RegisterExtension + private final FileStoreAutoDeleteExtension fileStoreExtension = new FileStoreAutoDeleteExtension(); private final FussyProgressMonitor monitor = new FussyProgressMonitor(); @@ -97,13 +101,13 @@ public void setGetPersistentProperty(IResource target) throws CoreException { QualifiedName name = new QualifiedName("itp-test", "testProperty"); target.setPersistentProperty(name, value); // see if we can get the property - assertTrue("get not equal set", target.getPersistentProperty(name).equals(value)); + assertTrue(target.getPersistentProperty(name).equals(value), "get not equal set"); // see what happens if we get a non-existant property name = new QualifiedName("eclipse-test", "testNonProperty"); - assertNull("non-existant persistent property not missing", target.getPersistentProperty(name)); + assertNull(target.getPersistentProperty(name), "non-existant persistent property not missing"); } - @Before + @BeforeEach public void setUp() throws Exception { monitor.prepare(); } @@ -233,7 +237,7 @@ public void testInvalidProjectNames() throws CoreException { } for (String name : names) { IProject project = root.getProject(name); - assertFalse(name, project.exists()); + assertFalse(project.exists(), name); assertThrows(CoreException.class, () -> { monitor.prepare(); project.create(monitor); @@ -242,8 +246,8 @@ public void testInvalidProjectNames() throws CoreException { project.open(monitor); monitor.assertUsedUp(); }); - assertFalse(name, project.exists()); - assertFalse(name, project.isOpen()); + assertFalse(project.exists(), name); + assertFalse(project.isOpen(), name); } //do some tests with valid names that are *almost* invalid @@ -256,15 +260,15 @@ public void testInvalidProjectNames() throws CoreException { } for (String name : names) { IProject project = root.getProject(name); - assertFalse(name, project.exists()); + assertFalse(project.exists(), name); monitor.prepare(); project.create(monitor); monitor.assertUsedUp(); monitor.prepare(); project.open(monitor); monitor.assertUsedUp(); - assertTrue(name, project.exists()); - assertTrue(name, project.isOpen()); + assertTrue(project.exists(), name); + assertTrue(project.isOpen(), name); } } @@ -641,7 +645,7 @@ public void testProjectCreationInvalidLocation() { */ @Test public void testProjectCreationLocationExistsWithDifferentCase() throws CoreException { - assumeTrue("only relevant on Windows", OS.isWindows()); + assumeTrue(OS.isWindows(), "only relevant on Windows"); String projectName = createUniqueString() + "a"; IProject project = getWorkspace().getRoot().getProject(projectName); @@ -1099,7 +1103,7 @@ public void testProjectDeletionClosedUserDefinedInSync() throws CoreException { * Force = TRUE * Delete content = ALWAYS * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(file); @@ -1125,7 +1129,7 @@ public void testProjectDeletionClosedUserDefinedInSync() throws CoreException { * Force = FALSE * Delete content = ALWAYS * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(file); @@ -1149,7 +1153,7 @@ public void testProjectDeletionClosedUserDefinedInSync() throws CoreException { * Force = TRUE * Delete content = NEVER * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(file); @@ -1173,7 +1177,7 @@ public void testProjectDeletionClosedUserDefinedInSync() throws CoreException { * Force = FALSE * Delete content = NEVER * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(file); @@ -1197,7 +1201,7 @@ public void testProjectDeletionClosedUserDefinedInSync() throws CoreException { * Force = TRUE * Delete content = DEFAULT * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(new IResource[] {project, file}); @@ -1221,7 +1225,7 @@ public void testProjectDeletionClosedUserDefinedInSync() throws CoreException { * Force = FALSE * Delete content = DEFAULT * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(file); @@ -1260,7 +1264,7 @@ public void testProjectDeletionClosedUserDefinedOutOfSync() throws Exception { * Force = TRUE * Delete content = ALWAYS * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(file); @@ -1291,7 +1295,7 @@ public void testProjectDeletionClosedUserDefinedOutOfSync() throws Exception { * Force = FALSE * Delete content = ALWAYS * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(file); @@ -1320,7 +1324,7 @@ public void testProjectDeletionClosedUserDefinedOutOfSync() throws Exception { * Force = TRUE * Delete content = NEVER * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(file); @@ -1347,7 +1351,7 @@ public void testProjectDeletionClosedUserDefinedOutOfSync() throws Exception { * Force = FALSE * Delete content = NEVER * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); @@ -1376,7 +1380,7 @@ public void testProjectDeletionClosedUserDefinedOutOfSync() throws Exception { * Force = TRUE * Delete content = DEFAULT * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(new IResource[] {project, file}); @@ -1404,7 +1408,7 @@ public void testProjectDeletionClosedUserDefinedOutOfSync() throws Exception { * Force = FALSE * Delete content = DEFAULT * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(file); @@ -1695,7 +1699,7 @@ public void testProjectDeletionOpenUserDefinedInSync() throws CoreException { * Force = TRUE * Delete content = ALWAYS * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(file); @@ -1717,7 +1721,7 @@ public void testProjectDeletionOpenUserDefinedInSync() throws CoreException { * Force = FALSE * Delete content = ALWAYS * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(file); @@ -1737,7 +1741,7 @@ public void testProjectDeletionOpenUserDefinedInSync() throws CoreException { * Force = TRUE * Delete content = NEVER * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(file); @@ -1756,7 +1760,7 @@ public void testProjectDeletionOpenUserDefinedInSync() throws CoreException { * Force = FALSE * Delete content = NEVER * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(file); @@ -1777,7 +1781,7 @@ public void testProjectDeletionOpenUserDefinedInSync() throws CoreException { * Force = TRUE * Delete content = DEFAULT * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(new IResource[] {project, file}); @@ -1797,7 +1801,7 @@ public void testProjectDeletionOpenUserDefinedInSync() throws CoreException { * Force = FALSE * Delete content = DEFAULT * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(file); @@ -1832,7 +1836,7 @@ public void testProjectDeletionOpenUserDefinedOutOfSync() throws Exception { * Force = TRUE * Delete content = ALWAYS * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(file); @@ -1860,7 +1864,7 @@ public void testProjectDeletionOpenUserDefinedOutOfSync() throws Exception { * Force = FALSE * Delete content = ALWAYS * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(file); @@ -1886,7 +1890,7 @@ public void testProjectDeletionOpenUserDefinedOutOfSync() throws Exception { * Force = TRUE * Delete content = NEVER * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(file); @@ -1912,7 +1916,7 @@ public void testProjectDeletionOpenUserDefinedOutOfSync() throws Exception { * Force = FALSE * Delete content = NEVER * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(file); @@ -1936,7 +1940,7 @@ public void testProjectDeletionOpenUserDefinedOutOfSync() throws Exception { * Force = TRUE * Delete content = DEFAULT * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(new IResource[] {project, file}); @@ -1961,7 +1965,7 @@ public void testProjectDeletionOpenUserDefinedOutOfSync() throws Exception { * Force = FALSE * Delete content = DEFAULT * =======================================================================*/ - projectStore = workspaceRule.getTempStore(); + projectStore = fileStoreExtension.getTempStore(); description.setLocationURI(projectStore.toURI()); ensureExistsInWorkspace(project, description); createInWorkspace(file); @@ -2119,7 +2123,7 @@ public void testProjectLocationWithEscapes() throws CoreException { IProjectDescription desc = getWorkspace().newProjectDescription(project1.getName()); desc.setLocation(location); project1.create(desc, monitor); - workspaceRule.deleteOnTearDown(location); + fileStoreExtension.deleteOnTearDown(location); monitor.assertUsedUp(); project1.open(null); @@ -2145,7 +2149,7 @@ public void testProjectMoveContent() throws CoreException { IProjectDescription destination = project.getDescription(); IPath oldPath = project.getLocation(); IPath newPath = getTempDir().append(Long.toString(System.currentTimeMillis())); - workspaceRule.deleteOnTearDown(newPath); + fileStoreExtension.deleteOnTearDown(newPath); destination.setLocation(newPath); monitor.prepare(); project.move(destination, false, monitor); @@ -2337,7 +2341,7 @@ public void testRenameExternalProject() throws CoreException { IResource[] resources = buildResources(project, children); // create the project at an external location IProjectDescription description = getWorkspace().newProjectDescription(project.getName()); - description.setLocationURI(workspaceRule.getTempStore().toURI()); + description.setLocationURI(fileStoreExtension.getTempStore().toURI()); monitor.prepare(); project.create(description, monitor); monitor.assertUsedUp(); @@ -2388,7 +2392,7 @@ public void testReplaceLocation() throws Exception { IProject target = getWorkspace().getRoot().getProject("testReplaceLocation"); createInWorkspace(target); - IFileStore projectStore = workspaceRule.getTempStore(); + IFileStore projectStore = fileStoreExtension.getTempStore(); IFileStore childFile = projectStore.getChild("File.txt"); // add some content to the current location diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeEventTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeEventTest.java index bcfdf24ef6d..8ffa531c346 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeEventTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeEventTest.java @@ -30,18 +30,17 @@ import org.eclipse.core.resources.IResourceDelta; import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.runtime.CoreException; -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; /** * This class tests the public API of IResourceChangeEvent. */ +@ExtendWith(WorkspaceResetExtension.class) public class IResourceChangeEventTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - /* some random resource handles */ protected IProject project1; protected IProject project2; @@ -61,7 +60,7 @@ public class IResourceChangeEventTest { * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. */ - @Before + @BeforeEach public void setUp() throws Exception { // Create some resource handles project1 = getWorkspace().getRoot().getProject("Project" + 1); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeListenerTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeListenerTest.java index 6acaa1e4a2a..d04feabe69c 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeListenerTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeListenerTest.java @@ -28,9 +28,9 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.setAutoBuilding; import static org.eclipse.core.tests.resources.ResourceTestUtil.waitForBuild; import static org.eclipse.core.tests.resources.ResourceTestUtil.waitForRefresh; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -65,12 +65,13 @@ import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.core.runtime.jobs.Job; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.FileStoreAutoDeleteExtension; import org.junit.function.ThrowingRunnable; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; @@ -87,8 +88,8 @@ */ public class IResourceChangeListenerTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + @RegisterExtension + private final FileStoreAutoDeleteExtension fileStoreExtension = new FileStoreAutoDeleteExtension(); static class SimpleListener implements IResourceChangeListener { Object source; @@ -159,7 +160,7 @@ public void resourceChanged(IResourceChangeEvent event) { IProjectDescription description = getWorkspace().newProjectDescription(project.getName()); IPath root = getWorkspace().getRoot().getLocation(); IPath contents = root.append("temp/testing"); - workspaceRule.deleteOnTearDown(root.append("temp")); + fileStoreExtension.deleteOnTearDown(root.append("temp")); description.setLocation(contents); project.create(description, createTestMonitor()); project.open(createTestMonitor()); @@ -188,7 +189,7 @@ public void resourceChanged(IResourceChangeEvent event) { * Tests that the builder is receiving an appropriate delta */ public void assertDelta() { - assertTrue(verifier.getMessage(), verifier.isDeltaValid()); + assertTrue(verifier.isDeltaValid(), verifier.getMessage()); } /** @@ -224,7 +225,7 @@ void assertNotDeltaVisits(IResourceDelta delta, final IResource[] resources) thr * Sets up the fixture, for example, open a network connection. This method * is called before a test is executed. */ - @Before + @BeforeEach public void setUp() throws Exception { // Create some resource handles project1 = getWorkspace().getRoot().getProject("Project" + 1); @@ -260,7 +261,7 @@ public void setUp() throws Exception { * Tears down the fixture, for example, close a network connection. This * method is called after a test is executed. */ - @After + @AfterEach public void tearDown() throws Exception { getWorkspace().removeResourceChangeListener(verifier); } @@ -339,7 +340,7 @@ public void testAddAndRemoveFile() throws CoreException { } }, createTestMonitor()); // should not have been verified since there was no change - assertTrue("Unexpected notification on no change", !verifier.hasBeenNotified()); + assertFalse(verifier.hasBeenNotified(), "Unexpected notification on no change"); } @Test @@ -355,7 +356,7 @@ public void testAddAndRemoveFolder() throws CoreException { } }, createTestMonitor()); // should not have been verified since there was no change - assertTrue("Unexpected notification on no change", !verifier.hasBeenNotified()); + assertFalse(verifier.hasBeenNotified(), "Unexpected notification on no change"); } @Test @@ -424,7 +425,7 @@ public void testBug45996() throws Throwable { } catch (CoreException e) { return; } - listenerInMainThreadCallback.set(Assert::fail); + listenerInMainThreadCallback.set(Assertions::fail); }; // register the listener with the workspace. getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.POST_CHANGE); @@ -468,23 +469,23 @@ public void testBuildKind() throws CoreException { file1.touch(null); workspace.build(trigger, monitor); }, createTestMonitor()); - assertEquals(i + "", workspace, preBuild.source); - assertEquals(i + "", workspace, postBuild.source); - assertEquals(i + "", workspace, postChange.source); - assertEquals(i + "", trigger, preBuild.trigger); - assertEquals(i + "", trigger, postBuild.trigger); - assertEquals(i + "", 0, postChange.trigger); + assertEquals(workspace, preBuild.source, i + ""); + assertEquals(workspace, postBuild.source, i + ""); + assertEquals(workspace, postChange.source, i + ""); + assertEquals(trigger, preBuild.trigger, i + ""); + assertEquals(trigger, postBuild.trigger, i + ""); + assertEquals(0, postChange.trigger, i + ""); workspace.run((IWorkspaceRunnable) monitor -> { file1.touch(null); project1.build(trigger, createTestMonitor()); }, createTestMonitor()); - assertEquals(i + "", project1, preBuild.source); - assertEquals(i + "", project1, postBuild.source); - assertEquals(i + "", workspace, postChange.source); - assertEquals(i + "", trigger, preBuild.trigger); - assertEquals(i + "", trigger, postBuild.trigger); - assertEquals(i + "", 0, postChange.trigger); + assertEquals(project1, preBuild.source, i + ""); + assertEquals(project1, postBuild.source, i + ""); + assertEquals(workspace, postChange.source, i + ""); + assertEquals(trigger, preBuild.trigger, i + ""); + assertEquals(trigger, postBuild.trigger, i + ""); + assertEquals(0, postChange.trigger, i + ""); } @@ -537,10 +538,10 @@ public void testTouchFileWithAutobuildOff() throws Exception { ((Workspace) getWorkspace()).getBuildManager().waitForAutoBuildOff(); int trigger = IncrementalProjectBuilder.AUTO_BUILD; - assertEquals("Should see PRE_BUILD event", trigger, preBuild.trigger); - assertEquals("Should see POST_BUILD event", trigger, postBuild.trigger); - assertEquals("Should see workspace root on PRE_BUILD event", workspace, preBuild.source); - assertEquals("Should see workspace root on POST_BUILD event", workspace, postBuild.source); + assertEquals(trigger, preBuild.trigger, "Should see PRE_BUILD event"); + assertEquals(trigger, postBuild.trigger, "Should see POST_BUILD event"); + assertEquals(workspace, preBuild.source, "Should see workspace root on PRE_BUILD event"); + assertEquals(workspace, postBuild.source, "Should see workspace root on POST_BUILD event"); } finally { workspace.removeResourceChangeListener(preBuild); workspace.removeResourceChangeListener(postBuild); @@ -816,7 +817,7 @@ protected IStatus run(IProgressMonitor monitor) { Job.getJobManager().wakeUp(ResourcesPlugin.FAMILY_MANUAL_REFRESH); Job.getJobManager().join(ResourcesPlugin.FAMILY_MANUAL_REFRESH, null); - assertTrue("deletion did unexpectedly not succeed", listener1.deletePerformed); + assertTrue(listener1.deletePerformed, "deletion did unexpectedly not succeed"); assertDoesNotExistInWorkspace(f); } finally { getWorkspace().removeResourceChangeListener(listener1); @@ -1268,7 +1269,7 @@ public void testMoveProject1() throws CoreException { @Test public void testMoveProject2() throws CoreException { final IPath path = getRandomLocation(); - workspaceRule.deleteOnTearDown(path); + fileStoreExtension.deleteOnTearDown(path); verifier.addExpectedChange(project1, IResourceDelta.CHANGED, IResourceDelta.DESCRIPTION); getWorkspace().run((IWorkspaceRunnable) m -> { m.beginTask("Creating and moving", 100); @@ -1304,16 +1305,14 @@ public void resourceChanged(IResourceChangeEvent event) { int i = 0; while (!(listener1.done && listener2.done)) { // timeout if the listeners are never called - assertTrue("Listeners were never called", ++i < 600); + assertTrue(++i < 600, "Listeners were never called"); try { Thread.sleep(100); } catch (InterruptedException e1) { } } - assertEquals("Improper change event processed by first listener", IResourceChangeEvent.POST_CHANGE, - listener1.eventType); - assertEquals("Improper change event processed by second listener", IResourceChangeEvent.POST_BUILD, - listener2.eventType); + assertEquals(IResourceChangeEvent.POST_CHANGE, listener1.eventType); + assertEquals(IResourceChangeEvent.POST_BUILD, listener2.eventType); } finally { getWorkspace().removeResourceChangeListener(listener1); getWorkspace().removeResourceChangeListener(listener2); @@ -1390,12 +1389,9 @@ public void resourceChanged(IResourceChangeEvent event) { reg3.unregister(); } } - assertEquals("Improper change event processed by first listener", IResourceChangeEvent.POST_CHANGE, - listener1.eventType); - assertEquals("Improper change event processed by second listener", IResourceChangeEvent.POST_BUILD, - listener2.eventType); - assertEquals("Improper change event processed by third listener", IResourceChangeEvent.POST_CHANGE, - listener3.eventType); + assertEquals(IResourceChangeEvent.POST_CHANGE, listener1.eventType); + assertEquals(IResourceChangeEvent.POST_BUILD, listener2.eventType); + assertEquals(IResourceChangeEvent.POST_CHANGE, listener3.eventType); logListenerInMainThreadCallback.get().run(); } @@ -1528,11 +1524,11 @@ public void testSetLocal() throws CoreException { verifier.reset(); // set local on a file that is already local -- should be no change file1.setLocal(true, IResource.DEPTH_INFINITE, createTestMonitor()); - assertTrue("Unexpected notification on no change", !verifier.hasBeenNotified()); + assertFalse(verifier.hasBeenNotified(), "Unexpected notification on no change"); // set non-local, still shouldn't appear in delta verifier.reset(); file1.setLocal(false, IResource.DEPTH_INFINITE, createTestMonitor()); - assertTrue("Unexpected notification on no change", !verifier.hasBeenNotified()); + assertFalse(verifier.hasBeenNotified(), "Unexpected notification on no change"); } @Test @@ -1670,7 +1666,7 @@ public void testTwoFileChanges() throws CoreException { @Test public void testRemoveAndCreateUnderlyingFileForLinkedResource() throws CoreException, IOException { IPath path = getTempDir().addTrailingSeparator().append(createUniqueString()); - workspaceRule.deleteOnTearDown(path); + fileStoreExtension.deleteOnTearDown(path); path.toFile().createNewFile(); IFile linkedFile = project1.getFile(createUniqueString()); @@ -1693,7 +1689,7 @@ public void testRemoveAndCreateUnderlyingFileForLinkedResource() throws CoreExce @Test public void testRemoveAndCreateUnderlyingFolderForLinkedResource() throws CoreException { IPath path = getTempDir().addTrailingSeparator().append(createUniqueString()); - workspaceRule.deleteOnTearDown(path); + fileStoreExtension.deleteOnTearDown(path); path.toFile().mkdir(); IFolder linkedFolder = project1.getFolder(createUniqueString()); @@ -1715,7 +1711,7 @@ public void testRemoveAndCreateUnderlyingFolderForLinkedResource() throws CoreEx @Test public void testBug228354() throws CoreException { IPath path = getTempDir().addTrailingSeparator().append(createUniqueString()); - workspaceRule.deleteOnTearDown(path); + fileStoreExtension.deleteOnTearDown(path); path.toFile().mkdir(); IFolder linkedFolder = project1.getFolder(createUniqueString()); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceDeltaTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceDeltaTest.java index ce1c18ab497..a799d3b7abb 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceDeltaTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceDeltaTest.java @@ -17,9 +17,9 @@ 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.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -30,18 +30,17 @@ import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -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; /** * Tests the public API of IResourceDelta */ +@ExtendWith(WorkspaceResetExtension.class) public class IResourceDeltaTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - /* some random resource handles */ protected IProject project1; protected IProject project2; @@ -58,7 +57,7 @@ public class IResourceDeltaTest { * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. */ - @Before + @BeforeEach public void setUp() throws Exception { // Create some resource handles project1 = getWorkspace().getRoot().getProject("Project" + 1); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceTest.java index de21b7fcff4..54a509a2c8d 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceTest.java @@ -35,13 +35,13 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.setAutoBuilding; import static org.eclipse.core.tests.resources.ResourceTestUtil.touchInFilesystem; import static org.eclipse.core.tests.resources.ResourceTestUtil.waitForBuild; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; @@ -87,17 +87,18 @@ import org.eclipse.core.tests.harness.CancelingProgressMonitor; import org.eclipse.core.tests.harness.FileSystemHelper; import org.eclipse.core.tests.harness.FussyProgressMonitor; +import org.eclipse.core.tests.resources.util.FileStoreAutoDeleteExtension; +import org.eclipse.core.tests.resources.util.WorkspaceResetExtension; import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.function.ThrowingRunnable; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.api.function.Executable; +@ExtendWith(WorkspaceResetExtension.class) public class IResourceTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - protected static final Boolean[] FALSE_AND_TRUE = { Boolean.FALSE, Boolean.TRUE }; protected static final IPath[] interestingPaths = getInterestingPaths(); protected static IResource[] interestingResources; @@ -145,6 +146,9 @@ public class IResourceTest { protected static final Boolean[] TRUE_AND_FALSE = { Boolean.TRUE, Boolean.FALSE }; protected static Set unsynchronizedResources = new HashSet<>(); + @RegisterExtension + private final FileStoreAutoDeleteExtension fileStoreExtension = new FileStoreAutoDeleteExtension(); + /* the delta verifier */ ResourceDeltaVerifier verifier; @@ -289,7 +293,7 @@ private static IPath[] getInterestingPaths() { * @param target the resource that was out of sync */ protected boolean checkAfterState(IResource receiver, IResource target, int state, int depth) { - assertTrue(verifier.getMessage(), verifier.isDeltaValid()); + assertTrue(verifier.isDeltaValid(), verifier.getMessage()); switch (state) { case S_FILESYSTEM_ONLY : assertExistsInFileSystem(target); @@ -443,7 +447,7 @@ protected boolean makesSense(IResource receiver, IResource target, int state, in return true; } - @Before + @BeforeEach public void setUp() throws Exception { setAutoBuilding(false); initializeProjects(); @@ -793,7 +797,7 @@ public void testAddLocalProject() throws CoreException { IProject project2 = getWorkspace().getRoot().getProject("NewProject"); IPath projectPath = project1.getLocation().removeLastSegments(1).append("NewProject"); - workspaceRule.deleteOnTearDown(projectPath); + fileStoreExtension.deleteOnTearDown(projectPath); projectPath.toFile().mkdirs(); project1.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); @@ -996,7 +1000,7 @@ public void testCopyProjectWithResFilterToExternLocation() throws CoreException IProject destProj = getWorkspace().getRoot().getProject("testCopyProject" + 2); IPath targetLocation = IPath .fromOSString(getRandomLocation(FileSystemHelper.getTempDir()).append(destProj.getName()).toOSString()); - workspaceRule.deleteOnTearDown(targetLocation); + fileStoreExtension.deleteOnTearDown(targetLocation); IProjectDescription desc = prepareDestProjDesc(sourceProj, destProj, targetLocation); LogListener logListener = copyProject(sourceProj, desc); @@ -1005,8 +1009,8 @@ public void testCopyProjectWithResFilterToExternLocation() throws CoreException logListener.assertNoLoggedErrors(); // assert there is no duplicate folder in the workspace. IPath destProjLocInWs = getWorkspace().getRoot().getLocation().append(destProj.getName()); - assertFalse("Project folder should not exist in workspace when copied to external location", - destProjLocInWs.toFile().exists()); + assertFalse(destProjLocInWs.toFile().exists(), + "Project folder should not exist in workspace when copied to external location"); } /** @@ -1020,7 +1024,7 @@ public void testCopyProjectWithoutResFilterToExternLocation() throws CoreExcepti IProject destProj = getWorkspace().getRoot().getProject("testCopyProject" + 2); IPath targetLocation = IPath .fromOSString(getRandomLocation(FileSystemHelper.getTempDir()).append(destProj.getName()).toOSString()); - workspaceRule.deleteOnTearDown(targetLocation); + fileStoreExtension.deleteOnTearDown(targetLocation); IProjectDescription desc = prepareDestProjDesc(sourceProj, destProj, targetLocation); LogListener logListener = copyProject(sourceProj, desc); @@ -1029,9 +1033,9 @@ public void testCopyProjectWithoutResFilterToExternLocation() throws CoreExcepti logListener.assertNoLoggedErrors(); // assert there is no duplicate folder in the workspace. IPath destProjLocInWs = getWorkspace().getRoot().getLocation().append(destProj.getName()); - assertFalse("Project folder should not exist in workspace when copied to external location", - destProjLocInWs.toFile().exists()); - assertTrue("Project folder should exist in external location", destProj.getLocation().toFile().exists()); + assertFalse(destProjLocInWs.toFile().exists(), + "Project folder should not exist in workspace when copied to external location"); + assertTrue(destProj.getLocation().toFile().exists(), "Project folder should exist in external location"); } /** @@ -1052,8 +1056,8 @@ public void testCopyProjectWithResFilterWithinWorkspace() throws CoreException { logListener.assertNoLoggedErrors(); // assert there is no duplicate folder in the workspace. IPath destProjLocInWs = getWorkspace().getRoot().getLocation().append(destProj.getName()); - assertTrue("Project folder should exist in workspace when copied with default location", - destProjLocInWs.toFile().exists()); + assertTrue(destProjLocInWs.toFile().exists(), + "Project folder should exist in workspace when copied with default location"); } private LogListener copyProject(IProject sourceProj, IProjectDescription desc) throws CoreException { @@ -1122,7 +1126,8 @@ public Object invokeMethod(Object[] args, int count) throws Exception { } try { if (resource.exists()) { - workspaceRule.deleteOnTearDown(resource.getLocation()); // Ensure that resource contents are + fileStoreExtension.deleteOnTearDown(resource.getLocation()); // Ensure that resource contents + // are // removed from file // system } @@ -1254,7 +1259,7 @@ public void testDerived() throws CoreException { assertFalse(project.isDerived()); assertFalse(folder.isDerived()); assertFalse(file.isDerived()); - assertTrue(verifier.getMessage(), verifier.isDeltaValid()); + assertTrue(verifier.isDeltaValid(), verifier.getMessage()); verifier.reset(); root.setDerived(false, new NullProgressMonitor()); @@ -1262,7 +1267,7 @@ public void testDerived() throws CoreException { assertFalse(project.isDerived()); assertFalse(folder.isDerived()); assertFalse(file.isDerived()); - assertTrue(verifier.getMessage(), verifier.isDeltaValid()); + assertTrue(verifier.isDeltaValid(), verifier.getMessage()); verifier.reset(); // project - cannot be marked as derived @@ -1271,7 +1276,7 @@ public void testDerived() throws CoreException { assertFalse(project.isDerived()); assertFalse(folder.isDerived()); assertFalse(file.isDerived()); - assertTrue(verifier.getMessage(), verifier.isDeltaValid()); + assertTrue(verifier.isDeltaValid(), verifier.getMessage()); verifier.reset(); project.setDerived(false, new NullProgressMonitor()); @@ -1279,7 +1284,7 @@ public void testDerived() throws CoreException { assertFalse(project.isDerived()); assertFalse(folder.isDerived()); assertFalse(file.isDerived()); - assertTrue(verifier.getMessage(), verifier.isDeltaValid()); + assertTrue(verifier.isDeltaValid(), verifier.getMessage()); verifier.reset(); // folder @@ -1289,7 +1294,7 @@ public void testDerived() throws CoreException { assertFalse(project.isDerived()); assertTrue(folder.isDerived()); assertFalse(file.isDerived()); - assertTrue(verifier.getMessage(), verifier.isDeltaValid()); + assertTrue(verifier.isDeltaValid(), verifier.getMessage()); verifier.reset(); verifier.addExpectedChange(folder, IResourceDelta.CHANGED, IResourceDelta.DERIVED_CHANGED); @@ -1298,7 +1303,7 @@ public void testDerived() throws CoreException { assertFalse(project.isDerived()); assertFalse(folder.isDerived()); assertFalse(file.isDerived()); - assertTrue(verifier.getMessage(), verifier.isDeltaValid()); + assertTrue(verifier.isDeltaValid(), verifier.getMessage()); verifier.reset(); // file @@ -1308,7 +1313,7 @@ public void testDerived() throws CoreException { assertFalse(project.isDerived()); assertFalse(folder.isDerived()); assertTrue(file.isDerived()); - assertTrue(verifier.getMessage(), verifier.isDeltaValid()); + assertTrue(verifier.isDeltaValid(), verifier.getMessage()); verifier.reset(); verifier.addExpectedChange(file, IResourceDelta.CHANGED, IResourceDelta.DERIVED_CHANGED); @@ -1317,7 +1322,7 @@ public void testDerived() throws CoreException { assertFalse(project.isDerived()); assertFalse(folder.isDerived()); assertFalse(file.isDerived()); - assertTrue(verifier.getMessage(), verifier.isDeltaValid()); + assertTrue(verifier.isDeltaValid(), verifier.getMessage()); verifier.reset(); /* remove trash */ @@ -1436,48 +1441,48 @@ public void testDerivedUsingAncestors() throws CoreException { // initial values should be false for (IResource resource2 : resources) { IResource resource = resource2; - assertFalse(resource.getFullPath().toString(), resource.isDerived()); + assertFalse(resource.isDerived(), resource.getFullPath().toString()); } // now set the root as derived root.setDerived(true, new NullProgressMonitor()); // we can't mark the root as derived, so none of its children should be derived - assertFalse(root.getFullPath().toString(), root.isDerived(IResource.CHECK_ANCESTORS)); - assertFalse(project.getFullPath().toString(), project.isDerived(IResource.CHECK_ANCESTORS)); - assertFalse(folder.getFullPath().toString(), folder.isDerived(IResource.CHECK_ANCESTORS)); - assertFalse(file1.getFullPath().toString(), file1.isDerived(IResource.CHECK_ANCESTORS)); - assertFalse(file2.getFullPath().toString(), file2.isDerived(IResource.CHECK_ANCESTORS)); + assertFalse(root.isDerived(IResource.CHECK_ANCESTORS), root.getFullPath().toString()); + assertFalse(project.isDerived(IResource.CHECK_ANCESTORS), project.getFullPath().toString()); + assertFalse(folder.isDerived(IResource.CHECK_ANCESTORS), folder.getFullPath().toString()); + assertFalse(file1.isDerived(IResource.CHECK_ANCESTORS), file1.getFullPath().toString()); + assertFalse(file2.isDerived(IResource.CHECK_ANCESTORS), file2.getFullPath().toString()); // now set the project as derived project.setDerived(true, new NullProgressMonitor()); // we can't mark a project as derived, so none of its children should be derived // even when CHECK_ANCESTORS is used - assertFalse(project.getFullPath().toString(), project.isDerived(IResource.CHECK_ANCESTORS)); - assertFalse(folder.getFullPath().toString(), folder.isDerived(IResource.CHECK_ANCESTORS)); - assertFalse(file1.getFullPath().toString(), file1.isDerived(IResource.CHECK_ANCESTORS)); - assertFalse(file2.getFullPath().toString(), file2.isDerived(IResource.CHECK_ANCESTORS)); + assertFalse(project.isDerived(IResource.CHECK_ANCESTORS), project.getFullPath().toString()); + assertFalse(folder.isDerived(IResource.CHECK_ANCESTORS), folder.getFullPath().toString()); + assertFalse(file1.isDerived(IResource.CHECK_ANCESTORS), file1.getFullPath().toString()); + assertFalse(file2.isDerived(IResource.CHECK_ANCESTORS), file2.getFullPath().toString()); // now set the folder as derived folder.setDerived(true, new NullProgressMonitor()); // first check if isDerived() returns valid values - assertTrue(folder.getFullPath().toString(), folder.isDerived()); - assertFalse(file1.getFullPath().toString(), file1.isDerived()); - assertFalse(file2.getFullPath().toString(), file2.isDerived()); + assertTrue(folder.isDerived(), folder.getFullPath().toString()); + assertFalse(file1.isDerived(), file1.getFullPath().toString()); + assertFalse(file2.isDerived(), file2.getFullPath().toString()); // check if isDerived(IResource.CHECK_ANCESTORS) returns valid values - assertTrue(folder.getFullPath().toString(), folder.isDerived(IResource.CHECK_ANCESTORS)); - assertTrue(file1.getFullPath().toString(), file1.isDerived(IResource.CHECK_ANCESTORS)); - assertTrue(file2.getFullPath().toString(), file2.isDerived(IResource.CHECK_ANCESTORS)); + assertTrue(folder.isDerived(IResource.CHECK_ANCESTORS), folder.getFullPath().toString()); + assertTrue(file1.isDerived(IResource.CHECK_ANCESTORS), file1.getFullPath().toString()); + assertTrue(file2.isDerived(IResource.CHECK_ANCESTORS), file2.getFullPath().toString()); // clear the values folder.setDerived(false, new NullProgressMonitor()); // values should be false again for (IResource resource2 : resources) { - assertFalse(resource2.getFullPath().toString(), resource2.isDerived()); + assertFalse(resource2.isDerived(), resource2.getFullPath().toString()); } } @@ -1514,8 +1519,8 @@ public boolean wasSuccess(Object[] args, Object result, Object[] oldState) throw boolean booleanResult = ((Boolean) result).booleanValue(); boolean expectedResult = resource0.getFullPath().equals(resource1.getFullPath()) && resource0.getType() == resource1.getType() && resource0.getWorkspace().equals(resource1.getWorkspace()); if (booleanResult) { - assertEquals("hashCode should be equal if equals returns true", resource0.hashCode(), - resource1.hashCode()); + assertEquals(resource0.hashCode(), resource1.hashCode(), + "hashCode should be equal if equals returns true"); } return booleanResult == expectedResult; } @@ -1606,7 +1611,7 @@ public void testGetModificationStamp() throws CoreException { for (IResource resource : resources) { if (resource.getType() != IResource.ROOT) { - assertEquals(resource.getFullPath().toString(), IResource.NULL_STAMP, resource.getModificationStamp()); + assertEquals(IResource.NULL_STAMP, resource.getModificationStamp(), resource.getFullPath().toString()); } } @@ -1617,25 +1622,25 @@ public void testGetModificationStamp() throws CoreException { for (IProject project2 : projects) { project = project2; project.create(createTestMonitor()); - assertEquals(project.getFullPath().toString(), IResource.NULL_STAMP, project.getModificationStamp()); + assertEquals(IResource.NULL_STAMP, project.getModificationStamp(), project.getFullPath().toString()); } // open the project(s) and create the resources. none should have a // null stamp anymore. for (IProject project2 : projects) { project = project2; - assertEquals(project.getFullPath().toString(), IResource.NULL_STAMP, project.getModificationStamp()); + assertEquals(IResource.NULL_STAMP, project.getModificationStamp(), project.getFullPath().toString()); project.open(createTestMonitor()); - assertNotEquals(project.getFullPath().toString(), IResource.NULL_STAMP, project.getModificationStamp()); + assertNotEquals(IResource.NULL_STAMP, project.getModificationStamp(), project.getFullPath().toString()); // cache the value for later use table.put(project.getFullPath(), Long.valueOf(project.getModificationStamp())); } for (IResource resource : resources) { if (resource.getType() != IResource.PROJECT) { - assertEquals(resource.getFullPath().toString(), IResource.NULL_STAMP, resource.getModificationStamp()); + assertEquals(IResource.NULL_STAMP, resource.getModificationStamp(), resource.getFullPath().toString()); createInWorkspace(resource); - assertNotEquals(resource.getFullPath().toString(), IResource.NULL_STAMP, - resource.getModificationStamp()); + assertNotEquals(IResource.NULL_STAMP, resource.getModificationStamp(), + resource.getFullPath().toString()); // cache the value for later use table.put(resource.getFullPath(), Long.valueOf(resource.getModificationStamp())); } @@ -1648,7 +1653,7 @@ public void testGetModificationStamp() throws CoreException { } for (IResource resource : resources) { if (resource.getType() != IResource.ROOT) { - assertEquals(resource.getFullPath().toString(), IResource.NULL_STAMP, resource.getModificationStamp()); + assertEquals(IResource.NULL_STAMP, resource.getModificationStamp(), resource.getFullPath().toString()); } } @@ -1660,9 +1665,9 @@ public void testGetModificationStamp() throws CoreException { for (IResource resource : resources) { if (resource.getType() != IResource.PROJECT) { Object v = table.get(resource.getFullPath()); - assertNotNull(resource.getFullPath().toString(), v); + assertNotNull(v, resource.getFullPath().toString()); long old = ((Long) v).longValue(); - assertEquals(resource.getFullPath().toString(), old, resource.getModificationStamp()); + assertEquals(old, resource.getModificationStamp(), resource.getFullPath().toString()); } } @@ -1673,9 +1678,9 @@ public void testGetModificationStamp() throws CoreException { resource.touch(createTestMonitor()); long stamp = resource.getModificationStamp(); Object v = table.get(resource.getFullPath()); - assertNotNull(resource.getFullPath().toString(), v); + assertNotNull(v, resource.getFullPath().toString()); long old = ((Long) v).longValue(); - assertNotEquals(resource.getFullPath().toString(), old, stamp); + assertNotEquals(old, stamp, resource.getFullPath().toString()); // cache for next time tempTable.put(resource.getFullPath(), Long.valueOf(stamp)); } @@ -1689,10 +1694,10 @@ public void testGetModificationStamp() throws CoreException { IResourceVisitor visitor = resource -> { //projects and root are always local if (resource.getType() == IResource.ROOT || resource.getType() == IResource.PROJECT) { - assertNotEquals(resource.getFullPath().toString(), IResource.NULL_STAMP, - resource.getModificationStamp()); + assertNotEquals(IResource.NULL_STAMP, resource.getModificationStamp(), + resource.getFullPath().toString()); } else { - assertEquals(resource.getFullPath().toString(), IResource.NULL_STAMP, resource.getModificationStamp()); + assertEquals(IResource.NULL_STAMP, resource.getModificationStamp(), resource.getFullPath().toString()); } return true; }; @@ -1706,11 +1711,11 @@ public void testGetModificationStamp() throws CoreException { for (IResource resource : resources) { if (resource.getType() != IResource.ROOT) { long stamp = resource.getModificationStamp(); - assertNotEquals(resource.getFullPath().toString(), IResource.NULL_STAMP, stamp); + assertNotEquals(IResource.NULL_STAMP, stamp, resource.getFullPath().toString()); Object v = table.get(resource.getFullPath()); - assertNotNull(resource.getFullPath().toString(), v); + assertNotNull(v, resource.getFullPath().toString()); long old = ((Long) v).longValue(); - assertNotEquals(resource.getFullPath().toString(), IResource.NULL_STAMP, old); + assertNotEquals(IResource.NULL_STAMP, old, resource.getFullPath().toString()); tempTable.put(resource.getFullPath(), Long.valueOf(stamp)); } } @@ -1722,11 +1727,11 @@ public void testGetModificationStamp() throws CoreException { for (IResource resource : resources) { if (resource.getType() != IResource.ROOT) { long newStamp = resource.getModificationStamp(); - assertNotEquals(resource.getFullPath().toString(), IResource.NULL_STAMP, newStamp); + assertNotEquals(IResource.NULL_STAMP, newStamp, resource.getFullPath().toString()); Object v = table.get(resource.getFullPath()); - assertNotNull(resource.getFullPath().toString(), v); + assertNotNull(v, resource.getFullPath().toString()); long oldStamp = ((Long) v).longValue(); - assertEquals(resource.getFullPath().toString(), oldStamp, newStamp); + assertEquals(oldStamp, newStamp, resource.getFullPath().toString()); } } @@ -1737,7 +1742,7 @@ public void testGetModificationStamp() throws CoreException { // should be null for (IResource resource : resources) { if (resource.getType() != IResource.ROOT) { - assertEquals(resource.getFullPath().toString(), IResource.NULL_STAMP, resource.getModificationStamp()); + assertEquals(IResource.NULL_STAMP, resource.getModificationStamp(), resource.getFullPath().toString()); } } @@ -1756,12 +1761,12 @@ public void testGetModificationStamp() throws CoreException { case IResource.ROOT : break; case IResource.PROJECT : - assertNotEquals(resource.getFullPath().toString(), IResource.NULL_STAMP, - resource.getModificationStamp()); + assertNotEquals(IResource.NULL_STAMP, resource.getModificationStamp(), + resource.getFullPath().toString()); break; default : - assertEquals(resource.getFullPath().toString(), IResource.NULL_STAMP, - resource.getModificationStamp()); + assertEquals(IResource.NULL_STAMP, resource.getModificationStamp(), + resource.getFullPath().toString()); break; } } @@ -1769,8 +1774,8 @@ public void testGetModificationStamp() throws CoreException { getWorkspace().getRoot().setLocal(true, IResource.DEPTH_INFINITE, createTestMonitor()); visitor = resource -> { if (resource.getType() != IResource.ROOT) { - assertNotEquals(resource.getFullPath().toString(), IResource.NULL_STAMP, - resource.getModificationStamp()); + assertNotEquals(IResource.NULL_STAMP, resource.getModificationStamp(), + resource.getFullPath().toString()); } return true; }; @@ -1835,13 +1840,13 @@ public void testGetRawLocation() throws Exception { assertEquals(workspaceLocation.append(deepFile.getFullPath()), deepFile.getRawLocation()); IPath projectLocation = getRandomLocation(); - workspaceRule.deleteOnTearDown(projectLocation); + fileStoreExtension.deleteOnTearDown(projectLocation); IPath folderLocation = getRandomLocation(); - workspaceRule.deleteOnTearDown(folderLocation); + fileStoreExtension.deleteOnTearDown(folderLocation); IPath fileLocation = getRandomLocation(); - workspaceRule.deleteOnTearDown(fileLocation); + fileStoreExtension.deleteOnTearDown(fileLocation); IPath variableLocation = getRandomLocation(); - workspaceRule.deleteOnTearDown(variableLocation); + fileStoreExtension.deleteOnTearDown(variableLocation); final String variableName = "IResourceTest_VariableName"; IPathVariableManager varMan = getWorkspace().getPathVariableManager(); try { @@ -2372,12 +2377,12 @@ public void testRevertModificationStamp() throws Throwable { resource.touch(null); long newStamp = resource.getModificationStamp(); if (resource.getType() == IResource.ROOT) { - assertEquals(resource.getFullPath().toString(), oldStamp, newStamp); + assertEquals(oldStamp, newStamp, resource.getFullPath().toString()); } else { - assertNotEquals(resource.getFullPath().toString(), oldStamp, newStamp); + assertNotEquals(oldStamp, newStamp, resource.getFullPath().toString()); } resource.revertModificationStamp(oldStamp); - assertEquals(resource.getFullPath().toString(), oldStamp, resource.getModificationStamp()); + assertEquals(oldStamp, resource.getModificationStamp(), resource.getFullPath().toString()); return true; }); @@ -2396,9 +2401,9 @@ public void testRevertModificationStamp() throws Throwable { getWorkspace().getRoot().delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, createTestMonitor()); for (IResource resource : resources) { //should fail except for root - ThrowingRunnable revertOperation = () -> resource.revertModificationStamp(1); + Executable revertOperation = () -> resource.revertModificationStamp(1); if (resource.getType() == IResource.ROOT) { - revertOperation.run(); + revertOperation.execute(); } else { assertThrows(CoreException.class, revertOperation); } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ISynchronizerTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ISynchronizerTest.java index a4e64c2143a..8196106cd67 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ISynchronizerTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ISynchronizerTest.java @@ -22,11 +22,11 @@ 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.removeFromWorkspace; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.DataInputStream; import java.io.DataOutputStream; @@ -61,19 +61,23 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.Status; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; - +import org.eclipse.core.tests.resources.util.FileStoreAutoDeleteExtension; +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.extension.RegisterExtension; + +@ExtendWith(WorkspaceResetExtension.class) public class ISynchronizerTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - public static int NUMBER_OF_PARTNERS = 100; public IResource[] resources; + @RegisterExtension + private final FileStoreAutoDeleteExtension fileStoreExtension = new FileStoreAutoDeleteExtension(); + /* * Internal method used for flushing all sync information for a particular resource * and its children. @@ -95,14 +99,14 @@ protected void flushAllSyncInfo(final IResource root) throws CoreException { getWorkspace().run(body, null); } - @Before + @BeforeEach public void setUp() throws Exception { resources = buildResources(getWorkspace().getRoot(), new String[] { "/", "1/", "1/1", "1/2/", "1/2/1", "1/2/2/", "2/", "2/1", "2/2/", "2/2/1", "2/2/2/" }); createInWorkspace(resources); } - @After + @AfterEach public void tearDown() throws Exception { // remove all registered sync partners so we don't create // phantoms when we delete @@ -179,7 +183,7 @@ public void testDeleteResources() throws CoreException { // sync info should be gone since projects can't become phantoms visitor = resource -> { - assertNull(resource.getFullPath().toString(), synchronizer.getSyncInfo(qname, resource)); + assertNull(synchronizer.getSyncInfo(qname, resource), resource.getFullPath().toString()); return true; }; getWorkspace().getRoot().accept(visitor); @@ -256,7 +260,7 @@ public void testDeleteResources2() throws CoreException { if (type == IResource.FILE && resource.getParent().getType() == IResource.PROJECT && resource.getName().equals(IProjectDescription.DESCRIPTION_FILE_NAME)) { return true; } - assertNull(resource.getFullPath().toString(), synchronizer.getSyncInfo(qname, resource)); + assertNull(synchronizer.getSyncInfo(qname, resource), resource.getFullPath().toString()); return true; }; @@ -395,7 +399,7 @@ public void testSave() throws Exception { // write out the data IPath syncInfoPath = Platform.getLocation().append(".testsyncinfo"); File file = syncInfoPath.toFile(); - workspaceRule.deleteOnTearDown(syncInfoPath); + fileStoreExtension.deleteOnTearDown(syncInfoPath); try (OutputStream fileOutput = new FileOutputStream(file)) { try (DataOutputStream output = new DataOutputStream(fileOutput)) { final List list = new ArrayList<>(5); @@ -500,7 +504,7 @@ public void testSyncInfo() throws CoreException { // there shouldn't be any info yet visitor = resource -> { byte[] actual = synchronizer.getSyncInfo(qname, resource); - assertNull("3.0." + resource.getFullPath(), actual); + assertNull(actual, resource.getFullPath().toString()); return true; }; getWorkspace().getRoot().accept(visitor); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceRootTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceRootTest.java index 9f34cff4937..ff569695de1 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceRootTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceRootTest.java @@ -21,12 +21,12 @@ 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.removeFromWorkspace; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.ByteArrayInputStream; import java.net.URI; @@ -47,26 +47,30 @@ import org.eclipse.core.runtime.Platform.OS; import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.tests.internal.filesystem.wrapper.WrapperFileSystem; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.FileStoreAutoDeleteExtension; +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.extension.RegisterExtension; +@ExtendWith(WorkspaceResetExtension.class) public class IWorkspaceRootTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + @RegisterExtension + private final FileStoreAutoDeleteExtension fileStoreExtension = new FileStoreAutoDeleteExtension(); /** * Tests findFilesForLocation when non-canonical paths are used (bug 155101). */ @Test public void testFindFilesNonCanonicalPath() throws Exception { - assumeTrue("only relevant on Windows", OS.isWindows()); + assumeTrue(OS.isWindows(), "only relevant on Windows"); IProject project = getWorkspace().getRoot().getProject("testFindFilesNonCanonicalPath"); createInWorkspace(project); IFile link = project.getFile("file.txt"); - IFileStore fileStore = workspaceRule.getTempStore(); + IFileStore fileStore = fileStoreExtension.getTempStore(); createInFileSystem(fileStore); assertEquals(EFS.SCHEME_FILE, fileStore.getFileSystem().getScheme()); IPath fileLocationLower = URIUtil.toPath(fileStore.toURI()); @@ -144,7 +148,7 @@ private void testFindContainersForLocation(IProject p1, IProject p2) throws Exce assertThrows(RuntimeException.class, () -> root.findContainersForLocationURI(relative)); //linked folder that does not overlap a project location IFolder otherLink = p1.getFolder("otherLink"); - IFileStore linkStore = workspaceRule.getTempStore(); + IFileStore linkStore = fileStoreExtension.getTempStore(); URI location = linkStore.toURI(); linkStore.mkdir(EFS.NONE, createTestMonitor()); otherLink.createLink(location, IResource.NONE, createTestMonitor()); @@ -225,7 +229,7 @@ private void testFindFilesForLocation(IProject project) throws CoreException { //linked resource IFolder link = project.getFolder("link"); - IFileStore linkStore = workspaceRule.getTempStore(); + IFileStore linkStore = fileStoreExtension.getTempStore(); URI location = linkStore.toURI(); linkStore.mkdir(EFS.NONE, createTestMonitor()); link.createLink(location, IResource.NONE, createTestMonitor()); @@ -274,7 +278,7 @@ public void testGetFile() { @Test public void testGetFileForLocation() { IWorkspaceRoot root = getWorkspace().getRoot(); - assertTrue(root.getFileForLocation(root.getLocation()) == null); + assertNull(root.getFileForLocation(root.getLocation())); } @Test diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceTest.java index 51d493bf7f9..f4df24f6e42 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceTest.java @@ -43,13 +43,13 @@ 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.removeFromWorkspace; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.net.URI; import java.net.URISyntaxException; @@ -73,17 +73,16 @@ import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform.OS; -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.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference; +@ExtendWith(WorkspaceResetExtension.class) public class IWorkspaceTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - private IResource[] buildResourceHierarchy() throws CoreException { return buildResources(getWorkspace().getRoot(), new String[] { "/", "/Project/", "/Project/Folder/", "/Project/Folder/File", }); @@ -625,7 +624,7 @@ public void testMultiCopy() throws Exception { assertTrue(oneMoreFile.exists()); assertTrue(folder.getFile(file1.getName()).exists()); assertTrue(folder.getFile(anotherFile.getName()).exists()); - assertTrue("Fails because of 1FVFOOQ", folder.getFile(oneMoreFile.getName()).exists()); + assertTrue(folder.getFile(oneMoreFile.getName()).exists(), "Fails because of 1FVFOOQ"); /* copy projects should not be allowed */ IResource destination = getWorkspace().getRoot().getProject("destination"); @@ -811,28 +810,28 @@ public void testValidateName() { assertFalse(getWorkspace().validateName("...", IResource.PROJECT).isOK()); assertFalse(getWorkspace().validateName("foo.", IResource.FILE).isOK()); for (int i = 0; i <= 31; i++) { - assertFalse("Windows should NOT accept character #" + i, - getWorkspace().validateName("anything" + ((char) i) + "something", IResource.FILE).isOK()); + assertFalse(getWorkspace().validateName("anything" + ((char) i) + "something", IResource.FILE).isOK(), + "Windows should NOT accept character #" + i); } - assertTrue("Windows should accept character #" + 32, - getWorkspace().validateName("anything" + ((char) 32) + "something", IResource.FILE).isOK()); - assertFalse("Windows should NOT accept space at the end", - getWorkspace().validateName("foo ", IResource.FILE).isOK()); - assertTrue("Windows should accept space in the middle", - getWorkspace().validateName("fo o", IResource.FILE).isOK()); - assertTrue("Windows should accept space in at the beginning", - getWorkspace().validateName(" foo", IResource.FILE).isOK()); + assertTrue(getWorkspace().validateName("anything" + ((char) 32) + "something", IResource.FILE).isOK(), + "Windows should accept character #" + 32); + assertFalse(getWorkspace().validateName("foo ", IResource.FILE).isOK(), + "Windows should NOT accept space at the end"); + assertTrue(getWorkspace().validateName("fo o", IResource.FILE).isOK(), + "Windows should accept space in the middle"); + assertTrue(getWorkspace().validateName(" foo", IResource.FILE).isOK(), + "Windows should accept space in at the beginning"); } else { //trailing dots are ok on other platforms assertTrue(getWorkspace().validateName("...", IResource.FILE).isOK()); assertTrue(getWorkspace().validateName("....", IResource.PROJECT).isOK()); assertTrue(getWorkspace().validateName("abc.", IResource.FILE).isOK()); for (int i = 1; i <= 32; i++) { - assertTrue("Unix-style filesystems should accept character #" + i, - getWorkspace().validateName("anything" + ((char) i) + "something", IResource.FILE).isOK()); + assertTrue(getWorkspace().validateName("anything" + ((char) i) + "something", IResource.FILE).isOK(), + "Unix-style filesystems should accept character #" + i); } - assertTrue("Unix-style filesystems should accept space at the end", - getWorkspace().validateName("foo ", IResource.FILE).isOK()); + assertTrue(getWorkspace().validateName("foo ", IResource.FILE).isOK(), + "Unix-style filesystems should accept space at the end"); } /* invalid characters on all platforms */ assertFalse(getWorkspace().validateName("/dsasf", IResource.FILE).isOK()); @@ -860,14 +859,14 @@ public void testValidateNatureSet() { String[][] invalid = getInvalidNatureSets(); for (int i = 0; i < invalid.length; i++) { IStatus result = ws.validateNatureSet(invalid[i]); - assertFalse("invalid (severity): " + i, result.isOK()); - assertNotEquals("invalid (code): " + i, IStatus.OK, result.getCode()); + assertFalse(result.isOK(), "invalid (severity): " + i); + assertNotEquals(IStatus.OK, result.getCode(), "invalid (code): " + i); } String[][] valid = getValidNatureSets(); for (int i = 0; i < valid.length; i++) { IStatus result = ws.validateNatureSet(valid[i]); - assertTrue("valid (severity): " + i, result.isOK()); - assertEquals("valid (code): " + i, IStatus.OK, result.getCode()); + assertTrue(result.isOK(), "valid (severity): " + i); + assertEquals(IStatus.OK, result.getCode(), "valid (code): " + i); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedDotProjectTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedDotProjectTest.java index a22db210c5d..ee5423ab9bb 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedDotProjectTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedDotProjectTest.java @@ -14,13 +14,13 @@ import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_EARTH; import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_MISSING; import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_SIMPLE; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.nio.file.Files; @@ -35,14 +35,13 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; -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 LinkedDotProjectTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - private void linkDotProject(IProject project) throws CoreException { IFile dotProject = project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME); if (dotProject.isLinked()) { diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceSyncMoveAndCopyTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceSyncMoveAndCopyTest.java index fdbd65879d2..ee76637735e 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceSyncMoveAndCopyTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceSyncMoveAndCopyTest.java @@ -22,10 +22,10 @@ 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.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +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.net.URI; import org.eclipse.core.filesystem.URIUtil; @@ -39,15 +39,19 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; - +import org.eclipse.core.tests.resources.util.FileStoreAutoDeleteExtension; +import org.eclipse.core.tests.resources.util.WorkspaceResetExtension; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.RegisterExtension; + +@ExtendWith(WorkspaceResetExtension.class) public class LinkedResourceSyncMoveAndCopyTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + @RegisterExtension + private final FileStoreAutoDeleteExtension fileStoreExtension = new FileStoreAutoDeleteExtension(); protected IProject existingProject; protected IProject otherExistingProject; @@ -66,7 +70,7 @@ protected URI resolve(URI uri) { return uri; } - @Before + @BeforeEach public void setUp() throws Exception { existingProject = getWorkspace().getRoot().getProject("ExistingProject"); otherExistingProject = getWorkspace().getRoot().getProject("OtherExistingProject"); @@ -113,7 +117,7 @@ public void testFileLinkedToNonExistent_Deep() throws Exception { internalMovedAndCopyTest(fileLink, IResource.NONE, false); createInFileSystem(fileLocation); - workspaceRule.deleteOnTearDown(fileLocation); + fileStoreExtension.deleteOnTearDown(fileLocation); exception = assertThrows(CoreException.class, () -> fileLink .setContents(createRandomString().getBytes(), IResource.NONE, createTestMonitor())); @@ -138,7 +142,7 @@ public void testFileLinkedToNonExistent_Shallow() throws Exception { internalMovedAndCopyTest(fileLink, IResource.SHALLOW, true); createInFileSystem(fileLocation); - workspaceRule.deleteOnTearDown(fileLocation); + fileStoreExtension.deleteOnTearDown(fileLocation); assertFalse(fileLink.isSynchronized(IResource.DEPTH_INFINITE)); internalMovedAndCopyTest(fileLink, IResource.SHALLOW, true); @@ -159,7 +163,7 @@ public void testFolderLinkedToNonExistent_Deep() throws CoreException { internalMovedAndCopyTest(folderLink, IResource.NONE, false); folderLocation.toFile().mkdir(); - workspaceRule.deleteOnTearDown(folderLocation); + fileStoreExtension.deleteOnTearDown(folderLocation); assertFalse(folderLink.isSynchronized(IResource.DEPTH_INFINITE)); internalMovedAndCopyTest(folderLink, IResource.NONE, true); @@ -180,7 +184,7 @@ public void testFolderLinkedToNonExistent_Shallow() throws CoreException { internalMovedAndCopyTest(folderLink, IResource.SHALLOW, true); folderLocation.toFile().mkdir(); - workspaceRule.deleteOnTearDown(folderLocation); + fileStoreExtension.deleteOnTearDown(folderLocation); assertFalse(folderLink.isSynchronized(IResource.DEPTH_INFINITE)); internalMovedAndCopyTest(folderLink, IResource.SHALLOW, true); @@ -224,7 +228,7 @@ public void testMoveFolderWithLinksToNonExisitngLocations_withShallow() throws C * Tests bug 299024. */ @Test - @Ignore("see bug 299024") + @Disabled("see bug 299024") public void testCopyFolderWithLinksToNonExistingLocations_withShallow() throws CoreException { // create a folder IFolder folderWithLinks = existingProject.getFolder(createUniqueString()); @@ -263,7 +267,7 @@ public void testFolderWithFileLinkedToNonExistent_Deep() throws Exception { internalMovedAndCopyTest(folder, IResource.NONE, false); createInFileSystem(fileLocation); - workspaceRule.deleteOnTearDown(fileLocation); + fileStoreExtension.deleteOnTearDown(fileLocation); assertFalse(folder.isSynchronized(IResource.DEPTH_INFINITE)); internalMovedAndCopyTest(folder, IResource.NONE, false); @@ -288,7 +292,7 @@ public void testFolderWithFileLinkedToNonExistent_Shallow() throws Exception { internalMovedAndCopyTest(folder, IResource.SHALLOW, true); createInFileSystem(fileLocation); - workspaceRule.deleteOnTearDown(fileLocation); + fileStoreExtension.deleteOnTearDown(fileLocation); assertFalse(folder.isSynchronized(IResource.DEPTH_INFINITE)); internalMovedAndCopyTest(folder, IResource.SHALLOW, true); @@ -313,7 +317,7 @@ public void testFolderWithFolderLinkedToNonExistent_Deep() throws CoreException internalMovedAndCopyTest(folder, IResource.NONE, false); folderLocation.toFile().mkdir(); - workspaceRule.deleteOnTearDown(folderLocation); + fileStoreExtension.deleteOnTearDown(folderLocation); assertFalse(folder.isSynchronized(IResource.DEPTH_INFINITE)); internalMovedAndCopyTest(folder, IResource.NONE, true); @@ -338,7 +342,7 @@ public void testFolderWithFolderLinkedToNonExistent_Shallow() throws CoreExcepti internalMovedAndCopyTest(folder, IResource.SHALLOW, true); folderLocation.toFile().mkdir(); - workspaceRule.deleteOnTearDown(folderLocation); + fileStoreExtension.deleteOnTearDown(folderLocation); assertFalse(folder.isSynchronized(IResource.DEPTH_INFINITE)); internalMovedAndCopyTest(folder, IResource.SHALLOW, true); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceTest.java index 75fbe2f97d9..d621c5a58f1 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceTest.java @@ -31,14 +31,14 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromFileSystem; import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.waitForRefresh; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; -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.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeFalse; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; @@ -71,10 +71,13 @@ import org.eclipse.core.runtime.Platform.OS; import org.eclipse.core.tests.harness.CancelingProgressMonitor; import org.eclipse.core.tests.harness.FussyProgressMonitor; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.function.ThrowingRunnable; +import org.eclipse.core.tests.resources.util.FileStoreAutoDeleteExtension; +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.extension.RegisterExtension; +import org.junit.jupiter.api.function.Executable; /** * Tests the following API methods: @@ -93,10 +96,11 @@ * IFile#createLink and IFolder#createLink and when * the location is obtained using IResource#getLocation(). */ +@ExtendWith(WorkspaceResetExtension.class) public class LinkedResourceTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + @RegisterExtension + final FileStoreAutoDeleteExtension fileStoreExtension = new FileStoreAutoDeleteExtension(); protected String childName = "File.txt"; protected IProject closedProject; @@ -151,7 +155,7 @@ protected URI resolve(URI uri) { return uri; } - @Before + @BeforeEach public void setUp() throws Exception { existingProject = getWorkspace().getRoot().getProject("ExistingProject"); existingProjectInSubDirectory = getWorkspace().getRoot().getProject("ExistingProjectInSubDirectory"); @@ -172,9 +176,9 @@ public void setUp() throws Exception { nonExistingFileInOtherExistingProject = otherExistingProject.getFile("nonExistingFileInOtherExistingProject"); nonExistingFileInExistingFolder = existingFolderInExistingProject.getFile("nonExistingFileInExistingFolder"); localFolder = getRandomLocation(); - workspaceRule.deleteOnTearDown(resolve(localFolder)); + fileStoreExtension.deleteOnTearDown(resolve(localFolder)); nonExistingLocation = getRandomLocation(); - workspaceRule.deleteOnTearDown(resolve(nonExistingLocation)); + fileStoreExtension.deleteOnTearDown(resolve(nonExistingLocation)); localFile = localFolder.append(childName); doCleanup(); @@ -183,7 +187,7 @@ public void setUp() throws Exception { File dir = existingProject.getLocation().toFile(); dir = dir.getParentFile(); dir = new File(dir + File.separator + "sub"); - workspaceRule.deleteOnTearDown(IPath.fromOSString(dir.getAbsolutePath())); + fileStoreExtension.deleteOnTearDown(IPath.fromOSString(dir.getAbsolutePath())); dir = new File(dir + File.separator + "dir" + File.separator + "more" + File.separator + "proj"); dir.mkdirs(); desc.setLocation(IPath.fromOSString(dir.getAbsolutePath())); @@ -571,7 +575,7 @@ public void testCopyMissingFolder() throws CoreException { @Test public void testCopyProjectWithLinks() throws Exception { IPath fileLocation = getRandomLocation(); - workspaceRule.deleteOnTearDown(fileLocation); + fileStoreExtension.deleteOnTearDown(fileLocation); IFile linkedFile = nonExistingFileInExistingProject; IFolder linkedFolder = nonExistingFolderInExistingProject; createInFileSystem(resolve(fileLocation)); @@ -611,7 +615,7 @@ public void testCopyProjectWithLinks() throws Exception { IResource[] srcChildren = existingProject.members(); for (int i = 0; i < srcChildren.length; i++) { if (!srcChildren[i].equals(linkedFile)) { - assertNotNull(i + "", destination.findMember(srcChildren[i].getProjectRelativePath())); + assertNotNull(destination.findMember(srcChildren[i].getProjectRelativePath()), i + ""); } } // test copy project when linked resources don't exist with force=true @@ -621,12 +625,12 @@ public void testCopyProjectWithLinks() throws Exception { assertThrows(CoreException.class, () -> existingProject.copy(destination.getFullPath(), IResource.FORCE, createTestMonitor())); assertTrue(destination.exists()); - assertTrue("6.7.1", !destination.getFile(linkedFile.getName()).exists()); + assertFalse(destination.getFile(linkedFile.getName()).exists()); // all members except the missing link should have been copied srcChildren = existingProject.members(); for (int i = 0; i < srcChildren.length; i++) { if (!srcChildren[i].equals(linkedFile)) { - assertNotNull(i + "", destination.findMember(srcChildren[i].getProjectRelativePath())); + assertNotNull(destination.findMember(srcChildren[i].getProjectRelativePath()), i + ""); } } } @@ -636,7 +640,7 @@ public void testCopyProjectWithLinks() throws Exception { */ @Test public void testCreateFolderInBackground() throws Exception { - final IFileStore rootStore = workspaceRule.getTempStore(); + final IFileStore rootStore = fileStoreExtension.getTempStore(); rootStore.mkdir(IResource.NONE, createTestMonitor()); IFileStore childStore = rootStore.getChild("file.txt"); createInFileSystem(childStore); @@ -661,10 +665,10 @@ public void testCreateLinkCaseVariant() throws Throwable { IFolder variant = link.getParent().getFolder(IPath.fromOSString(link.getName().toUpperCase())); createInWorkspace(variant); - ThrowingRunnable linkCreation = () -> link.createLink(localFolder, IResource.NONE, createTestMonitor()); + Executable linkCreation = () -> link.createLink(localFolder, IResource.NONE, createTestMonitor()); // should fail on case insensitive platforms if (Workspace.caseSensitive) { - linkCreation.run(); + linkCreation.execute(); } else { assertThrows(CoreException.class, linkCreation); } @@ -732,7 +736,7 @@ public void testCreateHiddenLinkedResources() throws CoreException { @Test public void testDeepMoveProjectWithLinks() throws Exception { IPath fileLocation = getRandomLocation(); - workspaceRule.deleteOnTearDown(fileLocation); + fileStoreExtension.deleteOnTearDown(fileLocation); IFile file = nonExistingFileInExistingProject; IFolder folder = nonExistingFolderInExistingProject; IFile childFile = folder.getFile(childName); @@ -890,7 +894,7 @@ public void testDeleteFolderWithLinks() throws CoreException { */ @Test public void testFindFilesForLocationCaseVariant() throws CoreException { - assumeTrue("only relevant on Windows", OS.isWindows()); + assumeTrue(OS.isWindows(), "only relevant on Windows"); IFolder link = nonExistingFolderInExistingProject; IPath localLocation = resolve(localFolder); @@ -911,9 +915,9 @@ public void testIsLinked() throws CoreException { //initially nothing is linked IResource[] toTest = new IResource[] {closedProject, existingFileInExistingProject, existingFolderInExistingFolder, existingFolderInExistingProject, existingProject, nonExistingFileInExistingFolder, nonExistingFileInExistingProject, nonExistingFileInOtherExistingProject, nonExistingFolderInExistingFolder, nonExistingFolderInExistingProject, nonExistingFolderInNonExistingFolder, nonExistingFolderInNonExistingProject, nonExistingFolderInOtherExistingProject, nonExistingProject, otherExistingProject}; for (IResource t : toTest) { - assertFalse(t.toString(), t.isLinked()); - assertFalse(t.toString(), t.isLinked(IResource.NONE)); - assertFalse(t.toString(), t.isLinked(IResource.CHECK_ANCESTORS)); + assertFalse(t.isLinked(), t.toString()); + assertFalse(t.isLinked(IResource.NONE), t.toString()); + assertFalse(t.isLinked(IResource.CHECK_ANCESTORS), t.toString()); } // create a link IFolder link = nonExistingFolderInExistingProject; @@ -934,9 +938,9 @@ public void testSetLinkLocation() throws CoreException { // initially nothing is linked IResource[] toTest = new IResource[] {closedProject, existingFileInExistingProject, existingFolderInExistingFolder, existingFolderInExistingProject, existingProject, nonExistingFileInExistingFolder, nonExistingFileInExistingProject, nonExistingFileInOtherExistingProject, nonExistingFolderInExistingFolder, nonExistingFolderInExistingProject, nonExistingFolderInNonExistingFolder, nonExistingFolderInNonExistingProject, nonExistingFolderInOtherExistingProject, nonExistingProject, otherExistingProject}; for (IResource toTest1 : toTest) { - assertFalse(toTest1.toString(), toTest1.isLinked()); - assertFalse(toTest1.toString(), toTest1.isLinked(IResource.NONE)); - assertFalse(toTest1.toString(), toTest1.isLinked(IResource.CHECK_ANCESTORS)); + assertFalse(toTest1.isLinked(), toTest1.toString()); + assertFalse(toTest1.isLinked(IResource.NONE), toTest1.toString()); + assertFalse(toTest1.isLinked(IResource.CHECK_ANCESTORS), toTest1.toString()); } // create a link IFolder link = nonExistingFolderInExistingProject; @@ -995,9 +999,9 @@ public void testSetLinkLocationPath() throws CoreException { //initially nothing is linked IResource[] toTest = new IResource[] {closedProject, existingFileInExistingProject, existingFolderInExistingFolder, existingFolderInExistingProject, existingProject, nonExistingFileInExistingFolder, nonExistingFileInExistingProject, nonExistingFileInOtherExistingProject, nonExistingFolderInExistingFolder, nonExistingFolderInExistingProject, nonExistingFolderInNonExistingFolder, nonExistingFolderInNonExistingProject, nonExistingFolderInOtherExistingProject, nonExistingProject, otherExistingProject}; for (IResource toTest1 : toTest) { - assertFalse(toTest1.toString(), toTest1.isLinked()); - assertFalse(toTest1.toString(), toTest1.isLinked(IResource.NONE)); - assertFalse(toTest1.toString(), toTest1.isLinked(IResource.CHECK_ANCESTORS)); + assertFalse(toTest1.isLinked(), toTest1.toString()); + assertFalse(toTest1.isLinked(IResource.NONE), toTest1.toString()); + assertFalse(toTest1.isLinked(IResource.CHECK_ANCESTORS), toTest1.toString()); } //create a link IFolder link = nonExistingFolderInExistingProject; @@ -1029,9 +1033,9 @@ public void testLinkedFileInLinkedFolder() throws CoreException, IOException { IFolder linkedFolder = top.getFolder("linkedFolder"); IFolder subFolder = linkedFolder.getFolder("subFolder"); IFile linkedFile = subFolder.getFile("Link.txt"); - IFileStore folderStore = workspaceRule.getTempStore(); + IFileStore folderStore = fileStoreExtension.getTempStore(); IFileStore subFolderStore = folderStore.getChild(subFolder.getName()); - IFileStore fileStore = workspaceRule.getTempStore(); + IFileStore fileStore = fileStoreExtension.getTempStore(); IPath folderLocation = URIUtil.toPath(folderStore.toURI()); IPath fileLocation = URIUtil.toPath(fileStore.toURI()); @@ -1277,7 +1281,7 @@ public void testValidateEmptyLinkLocation() { */ @Test public void testLocationWithColon() throws CoreException { - assumeFalse("not relevant on Windows, as it does not allow a location with colon in the name", OS.isWindows()); + assumeFalse(OS.isWindows(), "not relevant on Windows, as it does not allow a location with colon in the name"); IFolder folder = nonExistingFolderInExistingProject; // Note that on *nix, "c:/temp" is a relative path with two segments @@ -1294,7 +1298,7 @@ public void testLocationWithColon() throws CoreException { @Test public void testModificationStamp() throws Exception { IPath location = getRandomLocation(); - workspaceRule.deleteOnTearDown(location); + fileStoreExtension.deleteOnTearDown(location); IFile linkedFile = nonExistingFileInExistingProject; linkedFile.createLink(location, IResource.ALLOW_MISSING_LOCAL, createTestMonitor()); assertEquals(IResource.NULL_STAMP, linkedFile.getModificationStamp()); @@ -1542,7 +1546,7 @@ public void testMoveMissingFolder() throws CoreException { @Test public void testMoveProjectWithLinks() throws Exception { IPath fileLocation = getRandomLocation(); - workspaceRule.deleteOnTearDown(fileLocation); + fileStoreExtension.deleteOnTearDown(fileLocation); IFile file = nonExistingFileInExistingProject; IFolder folder = nonExistingFolderInExistingProject; IFile childFile = folder.getFile(childName); @@ -1591,7 +1595,7 @@ public void testMoveProjectWithLinks() throws Exception { @Test public void testMoveProjectWithLinks2() throws Exception { IPath fileLocation = getRandomLocation(); - workspaceRule.deleteOnTearDown(fileLocation); + fileStoreExtension.deleteOnTearDown(fileLocation); IFile linkedFile = existingProject.getFile("(test)"); createInFileSystem(resolve(fileLocation)); linkedFile.createLink(fileLocation, IResource.NONE, createTestMonitor()); @@ -1615,7 +1619,7 @@ public void testMoveFolderWithLinks() throws Exception { folderWithLinks.create(true, true, createTestMonitor()); IPath fileLocation = getRandomLocation(); - workspaceRule.deleteOnTearDown(fileLocation); + fileStoreExtension.deleteOnTearDown(fileLocation); createInFileSystem(resolve(fileLocation)); // create a linked file in the folder @@ -1675,8 +1679,8 @@ public void testNatureVeto() throws CoreException { */ @Test public void testNestedLink() throws CoreException { - final IFileStore store1 = workspaceRule.getTempStore(); - final IFileStore store2 = workspaceRule.getTempStore(); + final IFileStore store1 = fileStoreExtension.getTempStore(); + final IFileStore store2 = fileStoreExtension.getTempStore(); URI location1 = store1.toURI(); URI location2 = store2.toURI(); //folder names are important here, because we want a certain order in the link hash map @@ -1760,11 +1764,11 @@ public void testLinkedFolderWithOverlappingLocation_Bug293935_() { @Test public void testLinkedFolderWithSymlink_Bug338010() throws Exception { - assumeTrue("only relevant for platforms supporting symbolic links", canCreateSymLinks()); + assumeTrue(canCreateSymLinks(), "only relevant for platforms supporting symbolic links"); IPath baseLocation = getRandomLocation(); IPath resolvedBaseLocation = resolve(baseLocation); - workspaceRule.deleteOnTearDown(resolvedBaseLocation); + fileStoreExtension.deleteOnTearDown(resolvedBaseLocation); IPath symlinkTarget = resolvedBaseLocation.append("dir1/target"); symlinkTarget.toFile().mkdirs(); createSymLink(resolvedBaseLocation.toFile(), "symlink", symlinkTarget.toOSString(), true); @@ -1772,7 +1776,7 @@ public void testLinkedFolderWithSymlink_Bug338010() throws Exception { IPath resolvedLinkChildLocation = resolve(linkChildLocation); File linkChild = resolvedLinkChildLocation.toFile(); linkChild.mkdir(); - assertTrue("Could not create link at location: " + linkChild, linkChild.exists()); + assertTrue(linkChild.exists(), "Could not create link at location: " + linkChild); IFolder folder = nonExistingFolderInExistingProject; folder.createLink(linkChildLocation, IResource.NONE, createTestMonitor()); @@ -1785,11 +1789,11 @@ public void testLinkedFolderWithSymlink_Bug338010() throws Exception { */ @Test public void testDeleteLinkTarget_Bug507084() throws Exception { - assumeTrue("only relevant for platforms supporting symbolic links", canCreateSymLinks()); + assumeTrue(canCreateSymLinks(), "only relevant for platforms supporting symbolic links"); IPath baseLocation = getRandomLocation(); IPath resolvedBaseLocation = resolve(baseLocation); - workspaceRule.deleteOnTearDown(resolvedBaseLocation); + fileStoreExtension.deleteOnTearDown(resolvedBaseLocation); IPath symlinkTarget = resolvedBaseLocation.append("dir1/A"); symlinkTarget.append("B/C").toFile().mkdirs(); IPath linkParentDir = resolvedBaseLocation.append("dir2"); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceWithPathVariableTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceWithPathVariableTest.java index 9ee95317d67..3ba04f57078 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceWithPathVariableTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceWithPathVariableTest.java @@ -25,12 +25,12 @@ 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.removeFromFileSystem; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; @@ -54,9 +54,9 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.tests.harness.FileSystemHelper; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * This class extends LinkedResourceTest in order to use @@ -73,20 +73,20 @@ public class LinkedResourceWithPathVariableTest extends LinkedResourceTest { private IFileStore toSetWritable = null; @Override - @Before + @BeforeEach public void setUp() throws Exception { IPath base = FileSystemHelper.getRandomLocation(); - workspaceRule.deleteOnTearDown(base); + fileStoreExtension.deleteOnTearDown(base); getWorkspace().getPathVariableManager().setURIValue(VARIABLE_NAME, URIUtil.toURI(base)); base = FileSystemHelper.getRandomLocation(); - workspaceRule.deleteOnTearDown(base); + fileStoreExtension.deleteOnTearDown(base); super.setUp(); existingProject.getPathVariableManager().setURIValue(PROJECT_VARIABLE_NAME, URIUtil.toURI(base)); existingProject.getPathVariableManager().setURIValue(PROJECT_RELATIVE_VARIABLE_NAME, URIUtil.toURI(IPath.fromPortableString(PROJECT_RELATIVE_VARIABLE_VALUE))); } - @After + @AfterEach public void tearDown() throws Exception { if (toSetWritable != null) { IFileInfo info = toSetWritable.fetchInfo(); @@ -155,7 +155,7 @@ private URI getRandomLocation() { } path = FileSystemHelper.computeRandomLocation(parent); } - workspaceRule.deleteOnTearDown(pathVars.resolvePath(path)); + fileStoreExtension.deleteOnTearDown(pathVars.resolvePath(path)); return URIUtil.toURI(path); } @@ -172,7 +172,7 @@ public URI getRandomProjectLocation() { } path = FileSystemHelper.computeRandomLocation(parent); } - workspaceRule.deleteOnTearDown(pathVars.resolvePath(path)); + fileStoreExtension.deleteOnTearDown(pathVars.resolvePath(path)); return URIUtil.toURI(path); } @@ -189,7 +189,7 @@ public URI getRandomRelativeProjectLocation() { } path = FileSystemHelper.computeRandomLocation(parent); } - workspaceRule.deleteOnTearDown(pathVars.resolvePath(path)); + fileStoreExtension.deleteOnTearDown(pathVars.resolvePath(path)); return URIUtil.toURI(path); } @@ -348,7 +348,7 @@ public void testMoveFileToDifferentProject() throws Exception { if (!targetPath.toFile().exists()) { targetPath.toFile().createNewFile(); } - workspaceRule.deleteOnTearDown(targetPath); + fileStoreExtension.deleteOnTearDown(targetPath); variableBasedLocation = convertToRelative(targetPath, file, true, null); @@ -364,8 +364,8 @@ public void testMoveFileToDifferentProject() throws Exception { IFile newFile = nonExistingFileInExistingFolder; file.move(newFile.getFullPath(), IResource.SHALLOW, null); assertExistsInWorkspace(newFile); - assertTrue("3,2", !newFile.getLocation().equals(newFile.getRawLocation())); - assertEquals("3,3", newFile.getLocation(), resolvedPath); + assertFalse(newFile.getLocation().equals(newFile.getRawLocation())); + assertEquals(newFile.getLocation(), resolvedPath); } private IPath convertToRelative(IPath path, IResource res, boolean force, String variableHint) throws CoreException { @@ -396,7 +396,7 @@ public void testPROJECT_LOC_MoveFileToDifferentProject() throws Exception { if (!targetPath.toFile().exists()) { targetPath.toFile().createNewFile(); } - workspaceRule.deleteOnTearDown(targetPath); + fileStoreExtension.deleteOnTearDown(targetPath); existingProjectInSubDirectory.getPathVariableManager().setURIValue("P_RELATIVE", URIUtil.toURI(IPath.fromPortableString("${PARENT-3-PROJECT_LOC}"))); @@ -415,14 +415,14 @@ public void testPROJECT_LOC_MoveFileToDifferentProject() throws Exception { file.move(newFile.getFullPath(), IResource.SHALLOW, null); assertExistsInWorkspace(newFile); URI newLocation = newFile.getLocationURI(); - assertTrue("3,2", !newLocation.equals(newFile.getRawLocationURI())); + assertFalse(newLocation.equals(newFile.getRawLocationURI())); URI newRawLocation = newFile.getRawLocationURI(); /* we cannot test the value of the location since the test machines generate an incorrect value IPath newValue = newFile.getProject().getPathVariableManager().getValue("P_RELATIVE"); assertEquals("3,3", Path.fromPortableString("${PARENT-1-PROJECT_LOC}/sub"), newValue); */ - assertTrue("3,4", newRawLocation.equals(variableBasedLocation)); - assertTrue("3,5", newLocation.equals(resolvedPath)); + assertTrue(newRawLocation.equals(variableBasedLocation)); + assertTrue(newLocation.equals(resolvedPath)); } /** @@ -453,10 +453,10 @@ public void testMoveFileProjectVariable() throws CoreException { // removes the variable - the location will be undefined (null) file.move(newFile.getFullPath(), IResource.SHALLOW, null); assertExistsInWorkspace(newFile); - assertTrue("3,2", !newFile.getLocation().equals(newFile.getRawLocation())); - assertTrue("3,3", newFile.getRawLocationURI().equals(variableBasedLocation)); - assertTrue("3,4", newFile.getRawLocationURI().equals(variableBasedLocation)); - assertTrue("3,5", newFile.getLocationURI().equals(resolvedPath)); + assertFalse(newFile.getLocation().equals(newFile.getRawLocation())); + assertTrue(newFile.getRawLocationURI().equals(variableBasedLocation)); + assertTrue(newFile.getRawLocationURI().equals(variableBasedLocation)); + assertTrue(newFile.getLocationURI().equals(resolvedPath)); } /** @@ -487,9 +487,9 @@ public void testMoveFileToNewProjectProjectVariable() throws CoreException { // moves the variable - the location will be undefined (null) file.move(newFile.getFullPath(), IResource.SHALLOW, createTestMonitor()); assertExistsInWorkspace(newFile); - assertTrue("3,2", !newFile.getLocation().equals(newFile.getRawLocation())); - assertTrue("3,3", newFile.getRawLocationURI().equals(variableBasedLocation)); - assertTrue("3,4", newFile.getLocationURI().equals(resolvedPath)); + assertFalse(newFile.getLocation().equals(newFile.getRawLocation())); + assertTrue(newFile.getRawLocationURI().equals(variableBasedLocation)); + assertTrue(newFile.getLocationURI().equals(resolvedPath)); } /** @@ -824,7 +824,7 @@ public void testVariableChanged() throws Exception { // changes the variable value - the file location will change IPath newLocation = FileSystemHelper.getRandomLocation(); - workspaceRule.deleteOnTearDown(newLocation); + fileStoreExtension.deleteOnTearDown(newLocation); manager.setURIValue(VARIABLE_NAME, URIUtil.toURI(newLocation)); // try to change resource's contents @@ -890,7 +890,7 @@ public void testProjectVariableChanged() throws Exception { // changes the variable value - the file location will change IPath newLocation = FileSystemHelper.getRandomLocation(); - workspaceRule.deleteOnTearDown(newLocation); + fileStoreExtension.deleteOnTearDown(newLocation); manager.setURIValue(PROJECT_VARIABLE_NAME, URIUtil.toURI(newLocation)); // try to change resource's contents @@ -944,7 +944,7 @@ public void testNonRedundentPathVariablesGenerated() throws Exception { if (!targetPath.toFile().exists()) { targetPath.toFile().createNewFile(); } - workspaceRule.deleteOnTearDown(targetPath); + fileStoreExtension.deleteOnTearDown(targetPath); variableBasedLocation = convertToRelative(targetPath, file, true, null); IPath resolvedPath = URIUtil.toPath(pathVariableManager.resolveURI(URIUtil.toURI(variableBasedLocation))); @@ -984,9 +984,9 @@ public void testConvertToUserEditableFormat() { for (int i = 0; i < table.length; i++) { String result = pathVariableManager.convertToUserEditableFormat(toOS(table[i][0]), false); - assertEquals(i + "", toOS(table[i][1]), result); + assertEquals(toOS(table[i][1]), result, i + ""); String original = pathVariableManager.convertFromUserEditableFormat(result, false); - assertEquals(i + "", toOS(table[i].length == 2 ? table[i][0] : table[i][2]), original); + assertEquals(toOS(table[i].length == 2 ? table[i][0] : table[i][2]), original, i + ""); } String[][] tableLocationFormat = { // format: {internal-format, user-editable-format [, internal-format-reconverted] @@ -1009,11 +1009,11 @@ public void testConvertToUserEditableFormat() { for (int i = 0; i < table.length; i++) { String result = pathVariableManager.convertToUserEditableFormat(toOS(tableLocationFormat[i][0]), true); - assertEquals(i + "", toOS(tableLocationFormat[i][1]), result); + assertEquals(toOS(tableLocationFormat[i][1]), result, i + ""); String original = pathVariableManager.convertFromUserEditableFormat(result, true); - assertEquals(i + "", + assertEquals( toOS(tableLocationFormat[i].length == 2 ? tableLocationFormat[i][0] : tableLocationFormat[i][2]), - original); + original, i + ""); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerAttributeChangeListener.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerAttributeChangeListener.java index d5043aef6b3..a201c4b24a7 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerAttributeChangeListener.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerAttributeChangeListener.java @@ -14,7 +14,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.HashMap; import java.util.Map; @@ -64,11 +64,11 @@ public void resourceChanged(IResourceChangeEvent event) { private void checkDelta(IMarkerDelta[] deltas) { int expectedCount = attributeMap.size(); int actualCount = deltas.length; - assertEquals("wrong number of changes", expectedCount, actualCount); + assertEquals(expectedCount, actualCount, "wrong number of changes"); for (IMarkerDelta delta : deltas) { Map expected = attributeMap.get(Long.valueOf(delta.getId())); Map actual = delta.getAttributes(); - assertEquals("Changes different from expecations", expected, actual); + assertEquals(expected, actual, "Changes different from expecations"); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerSetTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerSetTest.java index df384ba1475..298cfd0802e 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerSetTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerSetTest.java @@ -16,13 +16,13 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.Arrays; import java.util.Map; @@ -31,14 +31,13 @@ import org.eclipse.core.internal.resources.MarkerInfo; import org.eclipse.core.internal.resources.MarkerSet; import org.eclipse.core.resources.IMarker; -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 MarkerSetTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - private void assertMarkerElementsEqual(IMarkerSetElement[] array1, IMarkerSetElement[] array2) { assertNotNull(array1); assertNotNull(array2); @@ -79,16 +78,16 @@ public void testAdd() { for (int i = 0; i < infos.length; i++) { info = infos[i]; set.add(info); - assertTrue(i + "", set.contains(info.getId())); - assertEquals(i + "", i + 1, set.size()); + assertTrue(set.contains(info.getId()), i + ""); + assertEquals(set.size(), i + 1, i + ""); } // make sure they are all still there assertEquals(max, set.size()); for (int i = 0; i < infos.length; i++) { info = infos[i]; - assertTrue(i + "", set.contains(info.getId())); - assertNotNull(i + "", set.get(info.getId())); + assertTrue(set.contains(info.getId()), i + ""); + assertNotNull(set.get(info.getId()), i + ""); } } @@ -130,11 +129,11 @@ public void testRemove() { for (int i = max - 1; i >= 0; i--) { info = infos[i]; set.remove(info); - assertFalse(i + "", set.contains(info.getId())); - assertEquals(i + "", i, set.size()); + assertFalse(set.contains(info.getId()), i + ""); + assertEquals(i, set.size(), i + ""); // check that the others still exist for (int j = 0; j < i; j++) { - assertTrue(j + "", set.contains(infos[j].getId())); + assertTrue(set.contains(infos[j].getId()), j + ""); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java index d4c82a80eae..b3991180322 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java @@ -25,7 +25,7 @@ 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.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.OutputStream; import java.nio.file.Files; @@ -52,22 +52,21 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.core.tests.internal.resources.SimpleNature; -import org.junit.After; -import org.junit.Before; -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.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.function.Executable; /** * Tests all aspects of project natures. These tests only * exercise API classes and methods. Note that the nature-related * APIs on IWorkspace are tested by IWorkspaceTest. */ +@ExtendWith(WorkspaceResetExtension.class) public class NatureTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - IProject project; /** @@ -94,22 +93,22 @@ private void setNatures(IProject project, String[] natures, boolean shouldFail, } else { flags = IResource.KEEP_HISTORY; } - ThrowingRunnable descriptionSetter = () -> project.setDescription(desc, flags, createTestMonitor()); + Executable descriptionSetter = () -> project.setDescription(desc, flags, createTestMonitor()); if (shouldFail) { assertThrows(CoreException.class, descriptionSetter); } else { - descriptionSetter.run(); + descriptionSetter.execute(); } } - @After + @AfterEach public void tearDown() throws Exception { project.delete(true, null); InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES).putInt(ResourcesPlugin.PREF_MISSING_NATURE_MARKER_SEVERITY, PreferenceInitializer.PREF_MISSING_NATURE_MARKER_SEVERITY_DEFAULT); InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES).flush(); } - @Before + @BeforeEach public void setUp() throws Exception { this.project = ResourcesPlugin.getWorkspace().getRoot().getProject(createUniqueString()); } @@ -186,7 +185,7 @@ public void testDuplicateNatures() throws Throwable { desc.setNatureIds(new String[] { NATURE_SIMPLE, NATURE_SIMPLE }); // This should not throw IllegalArgumentException when hasPrivateChanges is called project.setDescription(desc, IResource.KEEP_HISTORY, createTestMonitor()); - + // After deduplication, only one instance of the nature should remain assertHasEnabledNature(NATURE_SIMPLE); } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NonLocalLinkedResourceTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NonLocalLinkedResourceTest.java index b453e3a6eeb..de0b646e3b4 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NonLocalLinkedResourceTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NonLocalLinkedResourceTest.java @@ -18,8 +18,8 @@ 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.removeFromWorkspace; -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.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; @@ -33,18 +33,22 @@ import org.eclipse.core.tests.internal.filesystem.bogus.BogusFileSystem; import org.eclipse.core.tests.internal.filesystem.ram.MemoryFileSystem; import org.eclipse.core.tests.internal.filesystem.ram.MemoryTree; -import org.junit.After; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.FileStoreAutoDeleteExtension; +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; +import org.junit.jupiter.api.extension.RegisterExtension; /** * Tests behaviour of manipulating linked resources that are not linked into * the local file system. */ +@ExtendWith(WorkspaceResetExtension.class) public class NonLocalLinkedResourceTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + @RegisterExtension + private final FileStoreAutoDeleteExtension fileStoreExtension = new FileStoreAutoDeleteExtension(); /** * Creates a folder in the test file system with the given name @@ -60,7 +64,7 @@ protected IFileSystem getFileSystem() throws CoreException { return EFS.getFileSystem(MemoryFileSystem.SCHEME_MEMORY); } - @After + @AfterEach public void tearDown() throws Exception { MemoryTree.TREE.deleteAll(); } @@ -179,7 +183,7 @@ public void test342060() throws CoreException { protected IFileStore createBogusFolderStore(String name) throws CoreException { IFileSystem system = getBogusFileSystem(); IFileStore store = system.getStore(IPath.ROOT.append(name)); - workspaceRule.deleteOnTearDown( + fileStoreExtension.deleteOnTearDown( IPath.fromOSString(system.getStore(IPath.ROOT).toLocalFile(EFS.NONE, createTestMonitor()).getPath())); store.mkdir(EFS.NONE, createTestMonitor()); return store; diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectEncodingTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectEncodingTest.java index 7941db58701..b80ec2d3ccb 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectEncodingTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectEncodingTest.java @@ -31,28 +31,27 @@ 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.util.WorkspaceResetExtension; import org.eclipse.osgi.util.NLS; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.DiagnosingMatcher; -import org.junit.After; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; /** * Test for integration of marker * {@link org.eclipse.core.resources.ResourcesPlugin#PREF_MISSING_ENCODING_MARKER_SEVERITY}. */ +@ExtendWith(WorkspaceResetExtension.class) public class ProjectEncodingTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - private static final int IGNORE = -1; private IProject project; - @After + @AfterEach public void tearDown() throws Exception { if (project != null) { project.delete(true, true, null); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectOrderTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectOrderTest.java index 7f01b57c9b4..47dbf01558e 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectOrderTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectOrderTest.java @@ -27,19 +27,18 @@ import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.runtime.CoreException; -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; /** * Performs black box testing of the following API methods: * IWorkspace.computeProjectOrder(IProject[]) * IWorkspace.computePrerequisiteOrder(IProject[]) */ +@ExtendWith(WorkspaceResetExtension.class) public class ProjectOrderTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - /** * Adds a project reference from the given source project, which must * be accessible, to the given target project, which need not be accessible. diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectScopeTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectScopeTest.java index 12dc8fc5d46..a0cdbe5e28b 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectScopeTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectScopeTest.java @@ -15,18 +15,17 @@ import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createUniqueString; -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.ProjectScope; -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 ProjectScopeTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - @Test public void testEqualsAndHashCode() { IProject project = getWorkspace().getRoot().getProject(createUniqueString()); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectSnapshotPerfManualTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectSnapshotPerfManualTest.java index c5fe38a9d1d..d94df200669 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectSnapshotPerfManualTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectSnapshotPerfManualTest.java @@ -16,7 +16,8 @@ import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.File; import java.net.URI; @@ -31,9 +32,9 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.core.tests.harness.PerformanceTestRunner; -import org.junit.Assume; -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; /** * Measure speed of a project "Import with Snapshot" operation compared @@ -44,11 +45,9 @@ * to be available on a slow file system (bigSiteLocation). Modify * bigSiteLocation to suit your needs, then run-as > JUnit Plug-in Test. */ +@ExtendWith(WorkspaceResetExtension.class) public class ProjectSnapshotPerfManualTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - /** big site default volume (windows) */ public static final String bigSiteDevice = "c:"; @@ -85,7 +84,7 @@ protected int countChildren(File root) { @Test public void testSnapshotImportPerformance() throws Exception { // test if the test can be done in this machine - Assume.assumeTrue(bigSiteLocation.toFile().isDirectory()); + assumeTrue(bigSiteLocation.toFile().isDirectory()); // create common objects final IProject project = getWorkspace().getRoot().getProject("MyTestProject"); @@ -145,7 +144,7 @@ protected void test() throws CoreException { } }.run(getClass(), "Forced refresh only", 1, 1); verifier[0].verifyDelta(null); - assertTrue(verifier[0].getMessage(), verifier[0].isDeltaValid()); + assertTrue(verifier[0].isDeltaValid(), verifier[0].getMessage()); // close and delete project but leave contents project.close(null); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectSnapshotTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectSnapshotTest.java index 6c653f8f1ff..7c991faae6f 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectSnapshotTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectSnapshotTest.java @@ -19,11 +19,11 @@ import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInFileSystem; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +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.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.InputStream; import java.net.URI; @@ -41,9 +41,12 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.FileStoreAutoDeleteExtension; +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.extension.RegisterExtension; /** * Tests API for save/load refresh snapshots introduced in 3.6M6 (bug 301563): @@ -53,10 +56,11 @@ *
  • {@link IProject#SNAPSHOT_TREE} * */ +@ExtendWith(WorkspaceResetExtension.class) public class ProjectSnapshotTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + @RegisterExtension + private final FileStoreAutoDeleteExtension fileStoreExtension = new FileStoreAutoDeleteExtension(); /** location of refresh snapshot file */ private static final String REFRESH_SNAPSHOT_FILE_LOCATION = "resource-index.zip"; @@ -64,7 +68,7 @@ public class ProjectSnapshotTest { protected IProject[] projects = new IProject[2]; - @Before + @BeforeEach public void setUp() throws Exception { projects[0] = getWorkspace().getRoot().getProject("p1"); projects[1] = getWorkspace().getRoot().getProject("p2"); @@ -176,7 +180,7 @@ public void testLoadWithRefresh() throws Throwable { // perform refresh to create resource delta against snapshot project.refreshLocal(IResource.DEPTH_INFINITE, null); verifier.verifyDelta(null); - assertTrue(verifier.getMessage(), verifier.isDeltaValid()); + assertTrue(verifier.isDeltaValid(), verifier.getMessage()); // verify that the resources are no longer thought to exist assertFalse(file.exists()); assertFalse(folder.exists()); @@ -287,7 +291,7 @@ public void testAutoLoadMissingSnapshot() throws Throwable { IProject project = getWorkspace().getRoot().getProject("project"); IProjectDescription description = getWorkspace().newProjectDescription(project.getName()); // create project with non-existing snapshot autoload location - ((ProjectDescription) description).setSnapshotLocationURI(workspaceRule.getTempStore().toURI()); + ((ProjectDescription) description).setSnapshotLocationURI(fileStoreExtension.getTempStore().toURI()); project.create(description, null); createInFileSystem(project.getFile("foo")); assertFalse(project.getFile("foo").exists()); @@ -307,7 +311,7 @@ public void testAutoLoadMissingSnapshot() throws Throwable { @Test public void testAutoLoadWithRename() throws Throwable { // create project p0 outside the workspace - IFileStore tempStore = workspaceRule.getTempStore(); + IFileStore tempStore = fileStoreExtension.getTempStore(); tempStore.mkdir(EFS.NONE, null); IProject project = getWorkspace().getRoot().getProject("project"); IProjectDescription description = getWorkspace().newProjectDescription(project.getName()); @@ -354,7 +358,7 @@ public void testAutoLoadWithRename() throws Throwable { @Test public void testResetAutoLoadSnapshot() throws Throwable { IProject project = projects[0]; - URI tempURI = workspaceRule.getTempStore().toURI(); + URI tempURI = fileStoreExtension.getTempStore().toURI(); IFile projectFile = project.getFile(".project"); long stamp = projectFile.getModificationStamp(); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceAttributeTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceAttributeTest.java index a1f0c45203f..495e6f12c06 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceAttributeTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceAttributeTest.java @@ -27,11 +27,11 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.setReadOnly; import static org.eclipse.core.tests.resources.ResourceTestUtil.waitForRefresh; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.File; import org.eclipse.core.filesystem.EFS; @@ -41,47 +41,46 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourceAttributes; import org.eclipse.core.runtime.CoreException; -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 ResourceAttributeTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - private void setArchive(IResource resource, boolean value) throws CoreException { ResourceAttributes attributes = resource.getResourceAttributes(); - assertNotNull("setAchive for null attributes", attributes); + assertNotNull(attributes); attributes.setArchive(value); resource.setResourceAttributes(attributes); } private void setExecutable(IResource resource, boolean value) throws CoreException { ResourceAttributes attributes = resource.getResourceAttributes(); - assertNotNull("setExecutable for null attributes", attributes); + assertNotNull(attributes); attributes.setExecutable(value); resource.setResourceAttributes(attributes); } private void setHidden(IResource resource, boolean value) throws CoreException { ResourceAttributes attributes = resource.getResourceAttributes(); - assertNotNull("setHidden for null attributes", attributes); + assertNotNull(attributes); attributes.setHidden(value); resource.setResourceAttributes(attributes); } private void setSymlink(IResource resource, boolean value) throws CoreException { ResourceAttributes attributes = resource.getResourceAttributes(); - assertNotNull("setSymlink for null attributes", attributes); + assertNotNull(attributes); attributes.setSymbolicLink(value); resource.setResourceAttributes(attributes); } @Test public void testAttributeArchive() throws CoreException { - assumeTrue("only relevant for platforms supporting archive attribute", - isAttributeSupported(EFS.ATTRIBUTE_ARCHIVE)); + assumeTrue(isAttributeSupported(EFS.ATTRIBUTE_ARCHIVE), + "only relevant for platforms supporting archive attribute"); IProject project = getWorkspace().getRoot().getProject("Project"); IFile file = project.getFile("target"); @@ -104,8 +103,8 @@ public void testAttributeArchive() throws CoreException { @Test public void testAttributeExecutable() throws CoreException { - assumeTrue("only relevant for platforms supporting executable attribute", - isAttributeSupported(EFS.ATTRIBUTE_EXECUTABLE)); + assumeTrue(isAttributeSupported(EFS.ATTRIBUTE_EXECUTABLE), + "only relevant for platforms supporting executable attribute"); IProject project = getWorkspace().getRoot().getProject("Project"); IFile file = project.getFile("target"); @@ -129,8 +128,8 @@ public void testAttributeExecutable() throws CoreException { @Test public void testAttributeHidden() throws CoreException { - assumeTrue("only relevant for platforms supporting hidden attribute", - isAttributeSupported(EFS.ATTRIBUTE_HIDDEN)); + assumeTrue(isAttributeSupported(EFS.ATTRIBUTE_HIDDEN), + "only relevant for platforms supporting hidden attribute"); IProject project = getWorkspace().getRoot().getProject("Project"); IFile file = project.getFile("target"); @@ -153,8 +152,8 @@ public void testAttributeHidden() throws CoreException { @Test public void testAttributeReadOnly() throws CoreException { - assumeTrue("only relevant for platforms supporting read-only attribute", - isAttributeSupported(EFS.ATTRIBUTE_READ_ONLY)); + assumeTrue(isAttributeSupported(EFS.ATTRIBUTE_READ_ONLY), + "only relevant for platforms supporting read-only attribute"); IProject project = getWorkspace().getRoot().getProject("Project"); IFile file = project.getFile("target"); @@ -217,10 +216,10 @@ public void testNonExistingResource() throws CoreException { * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=397353 */ @Test - @Ignore("currently failing on Hudson: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=397353") + @Disabled("currently failing on Hudson: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=397353") public void testRefreshExecutableOnFolder() throws CoreException { - assumeTrue("only relevant for platforms supporting executable attribute", - isAttributeSupported(EFS.ATTRIBUTE_EXECUTABLE)); + assumeTrue(isAttributeSupported(EFS.ATTRIBUTE_EXECUTABLE), + "only relevant for platforms supporting executable attribute"); IProject project = getWorkspace().getRoot().getProject("testRefreshExecutableOnFolder"); IFolder folder = project.getFolder("folder"); @@ -247,7 +246,7 @@ public void testRefreshExecutableOnFolder() throws CoreException { @Test public void testAttributeSymlink() throws Exception { - assumeTrue("only relevant for platforms supporting symbolic links", canCreateSymLinks()); + assumeTrue(canCreateSymLinks(), "only relevant for platforms supporting symbolic links"); IProject project = getWorkspace().getRoot().getProject("Project"); IFile link = project.getFile("link"); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceDeltaVerifier.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceDeltaVerifier.java index 76a1d2b09a4..b61ba3c1649 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceDeltaVerifier.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceDeltaVerifier.java @@ -14,7 +14,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import java.util.HashSet; import java.util.Hashtable; diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceURLTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceURLTest.java index 0fa3d3a5383..0e7250c7da4 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceURLTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceURLTest.java @@ -18,8 +18,8 @@ import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.buildResources; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; -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.IOException; import java.io.InputStream; @@ -32,17 +32,16 @@ import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Platform; -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 suites for {@link org.eclipse.core.internal.resources.PlatformURLResourceConnection} */ +@ExtendWith(WorkspaceResetExtension.class) public class ResourceURLTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - private final String[] resourcePaths = new String[] { "/", "/1/", "/1/1", "/1/2", "/1/3", "/2/", "/2/1", "/2/2", "/2/3", "/3/", "/3/1", "/3/2", "/3/3", "/4/", "/5" }; diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/TeamPrivateMemberTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/TeamPrivateMemberTest.java index b47d84d3299..2286b1649a5 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/TeamPrivateMemberTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/TeamPrivateMemberTest.java @@ -22,8 +22,8 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.ensureOutOfSync; import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.waitForBuild; -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; @@ -36,14 +36,13 @@ import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.runtime.CoreException; -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 TeamPrivateMemberTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - @Test public void testRefreshLocal() throws Exception { IWorkspaceRoot root = getWorkspace().getRoot(); @@ -61,7 +60,7 @@ public void testRefreshLocal() throws Exception { setTeamPrivateMember(folder, true, IResource.DEPTH_ZERO); ensureOutOfSync(subFile); project.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); - assertTrue(listener.getMessage(), listener.isDeltaValid()); + assertTrue(listener.isDeltaValid(), listener.getMessage()); } finally { getWorkspace().removeResourceChangeListener(listener); } @@ -188,19 +187,19 @@ public void testAccept() throws CoreException { visitor.addExpected(resources); visitor.addExpected(description); project.accept(visitor); - assertTrue(visitor.getMessage(), visitor.isValid()); + assertTrue(visitor.isValid(), visitor.getMessage()); visitor.reset(); visitor.addExpected(resources); visitor.addExpected(description); project.accept(visitor, IResource.DEPTH_INFINITE, IResource.NONE); - assertTrue(visitor.getMessage(), visitor.isValid()); + assertTrue(visitor.isValid(), visitor.getMessage()); visitor.reset(); visitor.addExpected(resources); visitor.addExpected(description); project.accept(visitor, IResource.DEPTH_INFINITE, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS); - assertTrue(visitor.getMessage(), visitor.isValid()); + assertTrue(visitor.isValid(), visitor.getMessage()); // set the folder to be team private. It and its children should // be ignored by the visitor @@ -212,7 +211,7 @@ public void testAccept() throws CoreException { visitor.addExpected(settings); visitor.addExpected(prefs); project.accept(visitor); - assertTrue(visitor.getMessage(), visitor.isValid()); + assertTrue(visitor.isValid(), visitor.getMessage()); visitor.reset(); visitor.addExpected(project); @@ -221,27 +220,27 @@ public void testAccept() throws CoreException { visitor.addExpected(settings); visitor.addExpected(prefs); project.accept(visitor, IResource.DEPTH_INFINITE, IResource.NONE); - assertTrue(visitor.getMessage(), visitor.isValid()); + assertTrue(visitor.isValid(), visitor.getMessage()); // should see all resources if we include the flag visitor.reset(); visitor.addExpected(resources); visitor.addExpected(description); project.accept(visitor, IResource.DEPTH_INFINITE, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS); - assertTrue(visitor.getMessage(), visitor.isValid()); + assertTrue(visitor.isValid(), visitor.getMessage()); // should NOT visit the folder and its members if we call accept on it directly visitor.reset(); folder.accept(visitor); - assertTrue(visitor.getMessage(), visitor.isValid()); + assertTrue(visitor.isValid(), visitor.getMessage()); visitor.reset(); folder.accept(visitor, IResource.DEPTH_INFINITE, IResource.NONE); - assertTrue(visitor.getMessage(), visitor.isValid()); + assertTrue(visitor.isValid(), visitor.getMessage()); visitor.reset(); visitor.addExpected(folder); visitor.addExpected(subFile); folder.accept(visitor, IResource.DEPTH_INFINITE, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS); - assertTrue(visitor.getMessage(), visitor.isValid()); + assertTrue(visitor.isValid(), visitor.getMessage()); // now set all file/folder resources to be team private. setTeamPrivateMember(project, true, IResource.DEPTH_INFINITE); @@ -250,18 +249,18 @@ public void testAccept() throws CoreException { // projects are never team private visitor.addExpected(project); project.accept(visitor); - assertTrue(visitor.getMessage(), visitor.isValid()); + assertTrue(visitor.isValid(), visitor.getMessage()); visitor.reset(); visitor.addExpected(project); project.accept(visitor, IResource.DEPTH_INFINITE, IResource.NONE); - assertTrue(visitor.getMessage(), visitor.isValid()); + assertTrue(visitor.isValid(), visitor.getMessage()); // should see all resources if we include the flag visitor.reset(); visitor.addExpected(resources); visitor.addExpected(description); project.accept(visitor, IResource.DEPTH_INFINITE, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS); - assertTrue(visitor.getMessage(), visitor.isValid()); + assertTrue(visitor.isValid(), visitor.getMessage()); } @Test @@ -452,7 +451,7 @@ public void testDeltas() throws CoreException { listener.addExpectedChange(description, IResourceDelta.ADDED, IResource.NONE); getWorkspace().run(body, createTestMonitor()); waitForBuild(); - assertTrue(listener.getMessage(), listener.isDeltaValid()); + assertTrue(listener.isDeltaValid(), listener.getMessage()); removeFromWorkspace(resources); } finally { getWorkspace().removeResourceChangeListener(listener); @@ -470,7 +469,7 @@ public void testDeltas() throws CoreException { listener.addExpectedChange(project, IResourceDelta.ADDED, IResourceDelta.OPEN); listener.addExpectedChange(description, IResourceDelta.ADDED, IResource.NONE); getWorkspace().run(body, createTestMonitor()); - assertTrue(listener.getMessage(), listener.isDeltaValid()); + assertTrue(listener.isDeltaValid(), listener.getMessage()); removeFromWorkspace(resources); } finally { getWorkspace().removeResourceChangeListener(listener); @@ -488,7 +487,7 @@ public void testDeltas() throws CoreException { listener.addExpectedChange(project, IResourceDelta.ADDED, IResourceDelta.OPEN); listener.addExpectedChange(description, IResourceDelta.ADDED, IResource.NONE); getWorkspace().run(body, createTestMonitor()); - assertTrue(listener.getMessage(), listener.isDeltaValid()); + assertTrue(listener.isDeltaValid(), listener.getMessage()); removeFromWorkspace(resources); } finally { getWorkspace().removeResourceChangeListener(listener); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/TestPerformer.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/TestPerformer.java index 61a8783e71a..fdeabd62887 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/TestPerformer.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/TestPerformer.java @@ -13,10 +13,12 @@ *******************************************************************************/ package org.eclipse.core.tests.resources; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.util.Arrays; import java.util.Random; import org.eclipse.core.tests.harness.FussyProgressMonitor; -import org.junit.Assert; /** * Abstract superclass of inner classes used for black-box testing @@ -73,7 +75,7 @@ private void performTestRecursiveLoop(Object[][] inputs, Object[] args, int nth) if (shouldFail(args, count)) { try { invokeMethod(args, count); - Assert.fail(getFailMessagePrefixForCurrentInvocation(args) + fail(getFailMessagePrefixForCurrentInvocation(args) + "invocation did not fail although it should" + (reasonForExpectedFail != null ? ": " + reasonForExpectedFail : "")); } catch (Exception ex) { @@ -102,8 +104,8 @@ private void performTestRecursiveLoop(Object[][] inputs, Object[] args, int nth) } catch (Exception ex) { ex.printStackTrace(); } - Assert.assertTrue(getFailMessagePrefixForCurrentInvocation(args) - + "invocation should succeed but did not produce desired result", success); + assertTrue(success, getFailMessagePrefixForCurrentInvocation(args) + + "invocation should succeed but did not produce desired result"); } cleanUp(args, count); count++; diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/VirtualFolderTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/VirtualFolderTest.java index e80b24f4d68..68113e1a8be 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/VirtualFolderTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/VirtualFolderTest.java @@ -26,11 +26,11 @@ 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.createUniqueString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; @@ -42,23 +42,27 @@ import org.eclipse.core.resources.ResourceAttributes; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.FileStoreAutoDeleteExtension; +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.extension.RegisterExtension; /** * Tests Virtual Folders */ +@ExtendWith(WorkspaceResetExtension.class) public class VirtualFolderTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - protected IProject existingProject; protected IFolder existingVirtualFolderInExistingProject; - @Before - public void setUp() throws Exception { + @RegisterExtension + private final FileStoreAutoDeleteExtension fileStoreExtension = new FileStoreAutoDeleteExtension(); + + @BeforeEach + void setUp() throws Exception { existingProject = getWorkspace().getRoot().getProject("ExistingProject"); existingVirtualFolderInExistingProject = existingProject.getFolder("existingVirtualFolderInExistingProject"); createInWorkspace(new IResource[] { existingProject }); @@ -160,9 +164,9 @@ public void testCreateLinkedFileUnderVirtualFolder() throws CoreException { @Test public void testCopyProjectWithVirtualFolder() throws Exception { IPath fileLocation = getRandomLocation(); - workspaceRule.deleteOnTearDown(fileLocation); + fileStoreExtension.deleteOnTearDown(fileLocation); IPath folderLocation = getRandomLocation(); - workspaceRule.deleteOnTearDown(folderLocation); + fileStoreExtension.deleteOnTearDown(folderLocation); IFile linkedFile = existingVirtualFolderInExistingProject.getFile(createUniqueString()); IFolder linkedFolder = existingVirtualFolderInExistingProject.getFolder(createUniqueString()); @@ -204,9 +208,9 @@ public void testCopyProjectWithVirtualFolder() throws Exception { @Test public void testMoveProjectWithVirtualFolder() throws Exception { IPath fileLocation = getRandomLocation(); - workspaceRule.deleteOnTearDown(fileLocation); + fileStoreExtension.deleteOnTearDown(fileLocation); IPath folderLocation = getRandomLocation(); - workspaceRule.deleteOnTearDown(folderLocation); + fileStoreExtension.deleteOnTearDown(folderLocation); IFile file = existingVirtualFolderInExistingProject.getFile(createUniqueString()); IFolder folder = existingVirtualFolderInExistingProject.getFolder(createUniqueString()); @@ -267,7 +271,7 @@ public void testDeleteProjectWithVirtualFolder() throws CoreException { @Test public void testDeleteProjectWithVirtualFolderAndLink() throws CoreException { IPath folderLocation = getRandomLocation(); - workspaceRule.deleteOnTearDown(folderLocation); + fileStoreExtension.deleteOnTearDown(folderLocation); IFolder virtualFolder = existingProject.getFolder(createUniqueString()); IFolder linkedFolder = virtualFolder.getFolder("a_link"); @@ -330,9 +334,9 @@ public void testVirtualFolderInLinkedFolder() throws CoreException { IFolder virtualFolder = subFolder.getFolder("virtualFolder"); IPath linkedFolderLocation = getRandomLocation(); - workspaceRule.deleteOnTearDown(linkedFolderLocation); + fileStoreExtension.deleteOnTearDown(linkedFolderLocation); IPath subFolderLocation = linkedFolderLocation.append(subFolder.getName()); - workspaceRule.deleteOnTearDown(subFolderLocation); + fileStoreExtension.deleteOnTearDown(subFolderLocation); // create the structure on disk linkedFolderLocation.toFile().mkdir(); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceTest.java index ffbb0f1990d..38ef015bf32 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceTest.java @@ -27,11 +27,11 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createInputStream; import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomContentsStream; import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomString; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -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.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.File; import java.io.InputStream; @@ -46,18 +46,22 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.tests.harness.FussyProgressMonitor; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.FileStoreAutoDeleteExtension; +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.extension.RegisterExtension; /** * This class should be refactored into the black box tests for * solution, project, folder and file. */ +@ExtendWith(WorkspaceResetExtension.class) public class WorkspaceTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + @RegisterExtension + private final FileStoreAutoDeleteExtension fileStoreExtension = new FileStoreAutoDeleteExtension(); protected IProject getTestProject() { return getWorkspace().getRoot().getProject("testProject"); @@ -72,10 +76,10 @@ public void setGetPersistentProperty(IResource target) throws Throwable { QualifiedName name = new QualifiedName("itp-test", "testProperty"); target.setPersistentProperty(name, value); // see if we can get the property - assertTrue("get not equal set", target.getPersistentProperty(name).equals(value)); + assertTrue(target.getPersistentProperty(name).equals(value), "get not equal set"); // see what happens if we get a non-existant property name = new QualifiedName("itp-test", "testNonProperty"); - assertNull("non-existant persistent property not missing", target.getPersistentProperty(name)); + assertNull(target.getPersistentProperty(name), "non-existant persistent property not missing"); } @Test @@ -295,7 +299,7 @@ public void testProjectCreateOpenCloseDelete() throws Throwable { assertTrue(!target.exists()); } - @Before + @BeforeEach public void setUp() throws Exception { IProject target = getTestProject(); FussyProgressMonitor monitor = new FussyProgressMonitor(); @@ -333,18 +337,18 @@ public void testProjectDeletion() throws Throwable { FussyProgressMonitor monitor = new FussyProgressMonitor(); target.delete(true, monitor); monitor.assertUsedUp(); - assertTrue("Project Deletion failed", !target.exists()); + assertFalse(target.exists(), "Project Deletion failed"); } @Test public void testWorkingLocationDeletion_bug433061() throws Throwable { - assumeTrue("only relevant for platforms supporting symbolic links", canCreateSymLinks()); + assumeTrue(canCreateSymLinks(), "only relevant for platforms supporting symbolic links"); IProject project = getTestProject(); FussyProgressMonitor monitor = new FussyProgressMonitor(); IPath workingLocation = project.getWorkingLocation("org.eclipse.core.tests.resources"); IPath linkTarget = getRandomLocation(); - workspaceRule.deleteOnTearDown(linkTarget); + fileStoreExtension.deleteOnTearDown(linkTarget); linkTarget.toFile().mkdirs(); File file = linkTarget.append("aFile").toFile(); assertTrue(file.createNewFile()); @@ -355,9 +359,9 @@ public void testWorkingLocationDeletion_bug433061() throws Throwable { monitor.prepare(); project.delete(true, monitor); monitor.assertUsedUp(); - assertTrue("Project deletion failed", !project.exists()); - assertTrue("Working location was not deleted", !workingLocation.toFile().exists()); - assertTrue("File inside a symlinked directory got deleted", file.exists()); + assertFalse(project.exists(), "Project deletion failed"); + assertFalse(workingLocation.toFile().exists(), "Working location was not deleted"); + assertTrue(file.exists(), "File inside a symlinked directory got deleted"); } @Test @@ -435,7 +439,7 @@ public void testSetProperty() throws Throwable { String value = "this is a test property value"; QualifiedName name = new QualifiedName("itp-test", "testProperty"); target.setPersistentProperty(name, value); - assertTrue("get not equal set", target.getPersistentProperty(name).equals(value)); + assertTrue(target.getPersistentProperty(name).equals(value), "get not equal set"); } @Test diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceTestRule.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceTestRule.java index 19f697951e1..3ce73d40007 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceTestRule.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceTestRule.java @@ -20,7 +20,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; @@ -71,7 +71,7 @@ protected void before() throws Exception { // Wait for any pending refresh operation, in particular from startup waitForRefresh(); TestUtil.log(IStatus.INFO, testName, "setUp"); - assertNotNull("Workspace was not setup", getWorkspace()); + assertNotNull(getWorkspace(), "Workspace was not setup"); FreezeMonitor.expectCompletionInAMinute(); waitForRefresh(); } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/util/FileStoreAutoDeleteExtension.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/util/FileStoreAutoDeleteExtension.java new file mode 100644 index 00000000000..97880e26868 --- /dev/null +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/util/FileStoreAutoDeleteExtension.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2026 Vector Informatik GmbH and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.core.tests.resources.util; + +import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; +import static org.eclipse.core.tests.harness.FileSystemHelper.getRandomLocation; +import static org.eclipse.core.tests.harness.FileSystemHelper.getTempDir; +import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; + +import java.util.HashSet; +import java.util.Set; +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.runtime.IPath; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; + +/** + * A test extension that automatically deletes file stores that are either + * retrieved from the extension itself or passed to it via one of the + * {@code deleteOnTearDown()} methods. + */ +public class FileStoreAutoDeleteExtension implements AfterEachCallback { + + private final Set storesToDelete = new HashSet<>(); + + /** + * {@return a temporary file store backed by storage in a temporary location + * which will be automatically deleted when the test is completed} + */ + public IFileStore getTempStore() { + IFileStore store = EFS.getLocalFileSystem().getStore(getRandomLocation(getTempDir())); + deleteOnTearDown(store); + return store; + } + + /** + * Ensures that the store for the given path in the local file system is deleted + * when the test is completed. + * + * @param path + * the path to the file store to delete after test execution + */ + public void deleteOnTearDown(IPath path) { + storesToDelete.add(EFS.getLocalFileSystem().getStore(path)); + } + + /** + * Ensures that the given store is deleted when the test is completed. + * + * @param store + * the store to delete after test execution + */ + public void deleteOnTearDown(IFileStore store) { + storesToDelete.add(store); + + } + + @Override + public void afterEach(ExtensionContext context) throws Exception { + getWorkspace().run((IWorkspaceRunnable) monitor -> { + getWorkspace().getRoot().delete(true, true, createTestMonitor()); + // clear stores in workspace runnable to avoid interaction with resource jobs + for (IFileStore element : storesToDelete) { + element.delete(EFS.NONE, null); + } + storesToDelete.clear(); + }, null); + } + +}