diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/BlobStoreTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/BlobStoreTest.java index 562cc919ee9..ac87a6b6816 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/BlobStoreTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/BlobStoreTest.java @@ -16,9 +16,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInFileSystem; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInputStream; -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.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.io.InputStream; @@ -30,14 +30,17 @@ import org.eclipse.core.internal.utils.UniversalUniqueIdentifier; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.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 BlobStoreTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + @RegisterExtension + private final FileStoreAutoDeleteExtension fileStoreExtension = new FileStoreAutoDeleteExtension(); @Test public void testConstructor() throws CoreException { @@ -63,11 +66,11 @@ public void testConstructor() throws CoreException { } private IFileStore createStore() throws CoreException { - IFileStore root = workspaceRule.getTempStore(); + IFileStore root = fileStoreExtension.getTempStore(); root.mkdir(EFS.NONE, null); IFileInfo info = root.fetchInfo(); - assertTrue("createStore.1", info.exists()); - assertTrue("createStore.2", info.isDirectory()); + assertTrue(info.exists()); + assertTrue(info.isDirectory()); return root; } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/BucketTreeTests.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/BucketTreeTests.java index f437e0b1a80..339c57861e9 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/BucketTreeTests.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/BucketTreeTests.java @@ -18,8 +18,8 @@ import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.harness.FileSystemHelper.getRandomLocation; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.DataInputStream; import java.io.DataOutputStream; @@ -39,14 +39,17 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.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 BucketTreeTests { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + @RegisterExtension + private final FileStoreAutoDeleteExtension fileStoreExtension = new FileStoreAutoDeleteExtension(); static class SimpleBucket extends Bucket { @@ -147,7 +150,7 @@ protected void writeEntryValue(DataOutputStream destination, Object entryValue) @Test public void testVisitor() throws CoreException { IPath baseLocation = getRandomLocation(); - workspaceRule.deleteOnTearDown(baseLocation); + fileStoreExtension.deleteOnTearDown(baseLocation); // keep the reference around - it is the same returned by tree.getCurrent() SimpleBucket bucket = new SimpleBucket(); @@ -166,44 +169,44 @@ public void testVisitor() throws CoreException { bucket.set(path, "segments", Integer.toString(path.segmentCount())); } bucket.save(); - verify(tree, "1.1", IPath.ROOT, BucketTree.DEPTH_ZERO, Set.of(IPath.ROOT)); - verify(tree, "1.2", IPath.ROOT, BucketTree.DEPTH_ONE, + verify(tree, IPath.ROOT, BucketTree.DEPTH_ZERO, Set.of(IPath.ROOT)); + verify(tree, IPath.ROOT, BucketTree.DEPTH_ONE, Set.of(IPath.ROOT, proj1.getFullPath(), proj2.getFullPath())); - verify(tree, "1.3", IPath.ROOT, BucketTree.DEPTH_INFINITE, Set.of(IPath.ROOT, proj1.getFullPath(), + verify(tree, IPath.ROOT, BucketTree.DEPTH_INFINITE, Set.of(IPath.ROOT, proj1.getFullPath(), file1.getFullPath(), folder1.getFullPath(), file2.getFullPath(), proj2.getFullPath())); - verify(tree, "2.1", proj1.getFullPath(), BucketTree.DEPTH_ZERO, + verify(tree, proj1.getFullPath(), BucketTree.DEPTH_ZERO, Arrays.asList(new IPath[] { proj1.getFullPath() })); - verify(tree, "2.2", proj1.getFullPath(), BucketTree.DEPTH_ONE, + verify(tree, proj1.getFullPath(), BucketTree.DEPTH_ONE, Arrays.asList(new IPath[] { proj1.getFullPath(), file1.getFullPath(), folder1.getFullPath() })); - verify(tree, "2.3", proj1.getFullPath(), BucketTree.DEPTH_INFINITE, Arrays.asList( + verify(tree, proj1.getFullPath(), BucketTree.DEPTH_INFINITE, Arrays.asList( new IPath[] { proj1.getFullPath(), file1.getFullPath(), folder1.getFullPath(), file2.getFullPath() })); - verify(tree, "3.1", file1.getFullPath(), BucketTree.DEPTH_ZERO, + verify(tree, file1.getFullPath(), BucketTree.DEPTH_ZERO, Arrays.asList(new IPath[] { file1.getFullPath() })); - verify(tree, "3.2", file1.getFullPath(), BucketTree.DEPTH_ONE, + verify(tree, file1.getFullPath(), BucketTree.DEPTH_ONE, Arrays.asList(new IPath[] { file1.getFullPath() })); - verify(tree, "3.3", file1.getFullPath(), BucketTree.DEPTH_INFINITE, + verify(tree, file1.getFullPath(), BucketTree.DEPTH_INFINITE, Arrays.asList(new IPath[] { file1.getFullPath() })); - verify(tree, "4.1", folder1.getFullPath(), BucketTree.DEPTH_ZERO, + verify(tree, folder1.getFullPath(), BucketTree.DEPTH_ZERO, Arrays.asList(new IPath[] { folder1.getFullPath() })); - verify(tree, "4.2", folder1.getFullPath(), BucketTree.DEPTH_ONE, + verify(tree, folder1.getFullPath(), BucketTree.DEPTH_ONE, Arrays.asList(new IPath[] { folder1.getFullPath(), file2.getFullPath() })); - verify(tree, "4.3", folder1.getFullPath(), BucketTree.DEPTH_INFINITE, + verify(tree, folder1.getFullPath(), BucketTree.DEPTH_INFINITE, Arrays.asList(new IPath[] { folder1.getFullPath(), file2.getFullPath() })); - verify(tree, "5.1", file2.getFullPath(), BucketTree.DEPTH_ZERO, + verify(tree, file2.getFullPath(), BucketTree.DEPTH_ZERO, Arrays.asList(new IPath[] { file2.getFullPath() })); - verify(tree, "5.2", file2.getFullPath(), BucketTree.DEPTH_ONE, + verify(tree, file2.getFullPath(), BucketTree.DEPTH_ONE, Arrays.asList(new IPath[] { file2.getFullPath() })); - verify(tree, "5.3", file2.getFullPath(), BucketTree.DEPTH_INFINITE, + verify(tree, file2.getFullPath(), BucketTree.DEPTH_INFINITE, Arrays.asList(new IPath[] { file2.getFullPath() })); - verify(tree, "6.1", proj2.getFullPath(), BucketTree.DEPTH_ZERO, + verify(tree, proj2.getFullPath(), BucketTree.DEPTH_ZERO, Arrays.asList(new IPath[] { proj2.getFullPath() })); - verify(tree, "6.2", proj2.getFullPath(), BucketTree.DEPTH_ONE, + verify(tree, proj2.getFullPath(), BucketTree.DEPTH_ONE, Arrays.asList(new IPath[] { proj2.getFullPath() })); - verify(tree, "6.3", proj2.getFullPath(), BucketTree.DEPTH_INFINITE, + verify(tree, proj2.getFullPath(), BucketTree.DEPTH_INFINITE, Arrays.asList(new IPath[] { proj2.getFullPath() })); } - public void verify(BucketTree tree, final String tag, IPath root, int depth, final Collection expected) + public void verify(BucketTree tree, IPath root, int depth, final Collection expected) throws CoreException { final Set visited = new HashSet<>(); SimpleBucket.Visitor verifier = new SimpleBucket.Visitor() { @@ -211,17 +214,17 @@ public void verify(BucketTree tree, final String tag, IPath root, int depth, fin public int visit(org.eclipse.core.internal.localstore.Bucket.Entry entry) { SimpleBucket.SimpleEntry simple = (SimpleBucket.SimpleEntry) entry; IPath path = simple.getPath(); - assertTrue(tag + ".0 " + path, expected.contains(path)); + assertTrue(expected.contains(path), path.toString()); visited.add(path); - assertEquals(tag + ".1 " + path, path.toString(), simple.getProperty("path")); - assertEquals(tag + ".2 " + path, Integer.toString(path.segmentCount()), simple.getProperty("segments")); + assertEquals(path.toString(), simple.getProperty("path"), path.toString()); + assertEquals(Integer.toString(path.segmentCount()), simple.getProperty("segments"), path.toString()); return CONTINUE; } }; tree.accept(verifier, root, depth); - assertEquals(tag + ".4", expected.size(), visited.size()); + assertEquals(expected.size(), visited.size()); for (IPath path : expected) { - assertTrue(tag + ".5 " + path, visited.contains(path)); + assertTrue(visited.contains(path), path.toString()); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/CaseSensitivityTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/CaseSensitivityTest.java index 7effe650683..6c3fe9fe4b8 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/CaseSensitivityTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/CaseSensitivityTest.java @@ -18,9 +18,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.removeFromFileSystem; -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.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import org.eclipse.core.internal.resources.Workspace; @@ -30,16 +30,14 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.function.ThrowingRunnable; +import org.eclipse.core.tests.resources.util.WorkspaceResetExtension; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.function.Executable; +@ExtendWith(WorkspaceResetExtension.class) public class CaseSensitivityTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - private final boolean isCaseSensitive = Workspace.caseSensitive; @Test @@ -53,12 +51,12 @@ public void testCreateProjects() throws Throwable { // create a second project; should fail because has same name with different casing IProject project2 = getWorkspace().getRoot().getProject(projectName.toUpperCase()); - ThrowingRunnable projectCreation = () -> { + Executable projectCreation = () -> { project2.create(null); project2.open(null); }; if (isCaseSensitive) { - projectCreation.run(); + projectCreation.execute(); } else { assertThrows(CoreException.class, projectCreation); } @@ -76,9 +74,9 @@ public void testCreateFolders() throws Throwable { // create a second folder; should fail because has same name with different casing IFolder folder2 = project.getFolder(folderName.toUpperCase()); - ThrowingRunnable folderCreation = () -> folder2.create(true, true, null); + Executable folderCreation = () -> folder2.create(true, true, null); if (isCaseSensitive) { - folderCreation.run(); + folderCreation.execute(); } else { assertThrows(CoreException.class, folderCreation); } @@ -100,9 +98,9 @@ public void testCreateFiles() throws Throwable { // create a second file; should fail because has same name with different casing IFile file2 = project.getFile(fileName.toUpperCase()); - ThrowingRunnable fileCreation = () -> file2.create(createRandomContentsStream(), true, null); + Executable fileCreation = () -> file2.create(createRandomContentsStream(), true, null); if (isCaseSensitive) { - fileCreation.run(); + fileCreation.execute(); } else { assertThrows(CoreException.class, fileCreation); } @@ -127,10 +125,10 @@ public void testRenameProject() throws Throwable { project2.open(null); // try to rename project 1 to the uppercase name of project 2, should fail - ThrowingRunnable projectMovement = () -> project1.move(IPath.ROOT.append(project2.getName().toUpperCase()), + Executable projectMovement = () -> project1.move(IPath.ROOT.append(project2.getName().toUpperCase()), true, null); if (isCaseSensitive) { - projectMovement.run(); + projectMovement.execute(); } else { assertThrows(CoreException.class, projectMovement); } @@ -153,9 +151,9 @@ public void testRenameFolder() throws Throwable { // try to rename folder 1 to the uppercase name of folder 2, should fail IFolder folder3 = project.getFolder(folder2name.toUpperCase()); - ThrowingRunnable folderMovement = () -> folder1.move(folder3.getFullPath(), true, null); + Executable folderMovement = () -> folder1.move(folder3.getFullPath(), true, null); if (isCaseSensitive) { - folderMovement.run(); + folderMovement.execute(); } else { assertThrows(CoreException.class, folderMovement); } @@ -178,9 +176,9 @@ public void testRenameFile() throws Throwable { // try to rename folder 1 to the uppercase name of folder 2, should fail IFile file3 = project.getFile(file2name.toUpperCase()); - ThrowingRunnable fileMovement = () -> file1.move(file3.getFullPath(), true, null); + Executable fileMovement = () -> file1.move(file3.getFullPath(), true, null); if (isCaseSensitive) { - fileMovement.run(); + fileMovement.execute(); } else { assertThrows(CoreException.class, fileMovement); } @@ -203,10 +201,10 @@ public void testCopyAndMoveFolder() throws Throwable { // try to copy the folder from source project to destination project. // should fail due to conflict - ThrowingRunnable folderCopy = () -> folder1.copy(destinationProject.getFullPath().append(folder1.getName()), + Executable folderCopy = () -> folder1.copy(destinationProject.getFullPath().append(folder1.getName()), true, null); if (isCaseSensitive) { - folderCopy.run(); + folderCopy.execute(); } else { assertThrows(CoreException.class, folderCopy); } @@ -234,10 +232,10 @@ public void testCopyAndMoveFile() throws Throwable { // try to copy the file from source project to destination project. // should fail due to conflict - ThrowingRunnable fileCopy = () -> file1.copy(destinationProject.getFullPath().append(file1.getName()), true, + Executable fileCopy = () -> file1.copy(destinationProject.getFullPath().append(file1.getName()), true, null); if (isCaseSensitive) { - fileCopy.run(); + fileCopy.execute(); } else { assertThrows(CoreException.class, fileCopy); } @@ -265,10 +263,10 @@ public void testCopyAndMoveFolderOverFile() throws Throwable { // try to copy the folder from source project to destination project. // should fail due to conflict with existing file with case-different name - ThrowingRunnable folderCopy = () -> folder.copy(destinationProject.getFullPath().append(folder.getName()), true, + Executable folderCopy = () -> folder.copy(destinationProject.getFullPath().append(folder.getName()), true, null); if (isCaseSensitive) { - folderCopy.run(); + folderCopy.execute(); } else { assertThrows(CoreException.class, folderCopy); } @@ -296,10 +294,10 @@ public void testCopyAndMoveFileOverFolder() throws Throwable { // try to copy the file from source project to destination project. // should fail due to conflict with existing folder with case-different name - ThrowingRunnable fileCopy = () -> file.copy(destinationProject.getFullPath().append(file.getName()), true, + Executable fileCopy = () -> file.copy(destinationProject.getFullPath().append(file.getName()), true, null); if (isCaseSensitive) { - fileCopy.run(); + fileCopy.execute(); } else { assertThrows(CoreException.class, fileCopy); } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/CopyTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/CopyTest.java index 01182cd4423..3d57b3eba0d 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/CopyTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/CopyTest.java @@ -19,9 +19,9 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromFileSystem; import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromWorkspace; -import static org.junit.Assert.assertFalse; -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.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -30,20 +30,18 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.WorkspaceResetExtension; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; /** * Test the copy operation. */ +@ExtendWith(WorkspaceResetExtension.class) public class CopyTest { private static final int NUMBER_OF_PROPERTIES = 5; - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - @Test public void testCopyResource() throws Throwable { IProject project = getWorkspace().getRoot().getProject("Project"); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/DeleteTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/DeleteTest.java index c6f21e14292..ee2bd690b5f 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/DeleteTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/DeleteTest.java @@ -19,10 +19,10 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import static org.eclipse.core.tests.resources.ResourceTestUtil.ensureOutOfSync; import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromFileSystem; -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.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 org.eclipse.core.internal.resources.Workspace; import org.eclipse.core.resources.IFile; @@ -32,19 +32,17 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.WorkspaceResetExtension; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +@ExtendWith(WorkspaceResetExtension.class) public class DeleteTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - private IProject project; - @Before + @BeforeEach public void createTestProject() throws CoreException { project = getWorkspace().getRoot().getProject("Project"); createInWorkspace(project); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/FileSystemResourceManagerTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/FileSystemResourceManagerTest.java index f86680bb200..7c0d5dfdb80 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/FileSystemResourceManagerTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/FileSystemResourceManagerTest.java @@ -25,12 +25,12 @@ 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.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.InputStream; import java.net.URI; @@ -57,19 +57,17 @@ import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.core.tests.internal.filesystem.bug440110.Bug440110FileSystem; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.WorkspaceResetExtension; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +@ExtendWith(WorkspaceResetExtension.class) public class FileSystemResourceManagerTest implements ICoreConstants { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - private IProject project; - @Before + @BeforeEach public void createTestProject() throws CoreException { project = getWorkspace().getRoot().getProject("Project"); createInWorkspace(project); @@ -308,11 +306,11 @@ public void testWriteFile() throws Exception { /* test the overwrite parameter (false) */ ensureOutOfSync(file); InputStream another2 = createInputStream(anotherContent); - assertThrows("Should fail writing out of sync file #1", CoreException.class, - () -> write(file, another2, false, null)); + assertThrows(CoreException.class, () -> write(file, another2, false, null), + "Should fail writing out of sync file #1"); ensureOutOfSync(file); - assertThrows("Should fail writing out of sync file #2", CoreException.class, - () -> file.setContents(another2, false, false, null)); + assertThrows(CoreException.class, () -> file.setContents(another2, false, false, null), + "Should fail writing out of sync file #2"); try (InputStream another = createInputStream(anotherContent)) { file.setContents(another, true, false, null); } @@ -321,8 +319,8 @@ public void testWriteFile() throws Exception { removeFromFileSystem(file); // FIXME Race Condition with asynchronous workplace refresh see Bug 571133 InputStream another3 = createInputStream(anotherContent); waitForRefresh(); // wait for refresh to ensure that file is not present in workspace - assertThrows("Should fail writing non existing file", CoreException.class, - () -> write(file, another3, false, null)); + assertThrows(CoreException.class, () -> write(file, another3, false, null), + "Should fail writing non existing file"); /* remove trash */ removeFromWorkspace(project); @@ -339,8 +337,8 @@ public void testWriteDeletedFile() throws CoreException { write(file, createInputStream(content), true, null); file.delete(true, null); - assertThrows("Should fail writing file that is already deleted", CoreException.class, - () -> write(file, createInputStream(content), false, null)); + assertThrows(CoreException.class, () -> write(file, createInputStream(content), false, null), + "Should fail writing file that is already deleted"); } @Test @@ -405,7 +403,7 @@ public void testWriteProject() throws CoreException { // wrap in runnable to prevent snapshot from occurring in the middle. getWorkspace().run((IWorkspaceRunnable) monitor -> { removeFromFileSystem(project); - assertFalse("2.1", fileStore.fetchInfo().isDirectory()); + assertFalse(fileStore.fetchInfo().isDirectory()); //write project in a runnable, otherwise tree will be locked ((Project) project).writeDescription(IResource.FORCE); }, null); @@ -428,10 +426,10 @@ public void testBug547691() throws CoreException { project.open(null); FileSystemResourceManager manager = ((Workspace) getWorkspace()).getFileSystemManager(); URI location = manager.locationURIFor(project); - assertNotNull("Expected location for accessible project to not be null", location); + assertNotNull(location, "Expected location for accessible project to not be null"); project.delete(true, null); URI locationAfterDelete = manager.locationURIFor(project); - assertEquals("Expected location of project to not change after delete", location, locationAfterDelete); + assertEquals(location, locationAfterDelete, "Expected location of project to not change after delete"); } @Test @@ -449,7 +447,7 @@ protected void write(final IFile file, final InputStream contents, final boolean throws CoreException { try { IWorkspace workspace = getWorkspace(); - assertNotNull("workspace cannot be null", workspace); + assertNotNull(workspace, "workspace cannot be null"); workspace.run(new WriteFileContents(file, contents, force, getLocalManager()), monitor); } catch (Throwable t) { // Bug 541493: we see unlikely stack traces reported by JUnit here, log the @@ -474,21 +472,21 @@ static class WriteFileContents implements IWorkspaceRunnable { WriteFileContents(IFile file, InputStream contents, boolean force, FileSystemResourceManager localManager) { this.file = file; - assertNotNull("file cannot be null", file); + assertNotNull(file, "file cannot be null"); this.contents = contents; - assertNotNull("contents cannot be null", contents); + assertNotNull(contents, "contents cannot be null"); this.force = force; this.localManager = localManager; - assertNotNull("file system resource manager cannot be null", localManager); + assertNotNull(localManager, "file system resource manager cannot be null"); } @Override public void run(IProgressMonitor jobMonitor) throws CoreException { int flags = force ? IResource.FORCE : IResource.NONE; IFileStore store = ((Resource) file).getStore(); - assertNotNull("file store cannot be null", store); + assertNotNull(store, "file store cannot be null"); IFileInfo info = store.fetchInfo(); - assertNotNull("file info cannot be null for file " + file, info); + assertNotNull(info, "file info cannot be null for file " + file); localManager.write(file, contents, info, flags, false, jobMonitor); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/HistoryBucketTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/HistoryBucketTest.java index 8d87e12f1ef..bf2491cd11f 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/HistoryBucketTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/HistoryBucketTest.java @@ -14,23 +14,23 @@ package org.eclipse.core.tests.internal.localstore; import static org.eclipse.core.tests.harness.FileSystemHelper.getRandomLocation; -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.internal.localstore.Bucket.Entry; import org.eclipse.core.internal.localstore.HistoryBucket; import org.eclipse.core.internal.utils.UniversalUniqueIdentifier; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.FileStoreAutoDeleteExtension; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; public class HistoryBucketTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + @RegisterExtension + private final FileStoreAutoDeleteExtension fileStoreExtension = new FileStoreAutoDeleteExtension(); /** * Ensures that if another entry having exactly the same UUID is added, @@ -39,7 +39,7 @@ public class HistoryBucketTest { @Test public void testDuplicates() throws CoreException { IPath baseLocation = getRandomLocation(); - workspaceRule.deleteOnTearDown(baseLocation); + fileStoreExtension.deleteOnTearDown(baseLocation); HistoryBucket index1 = new HistoryBucket(); IPath location1 = baseLocation.append("location1"); index1.load("foo", location1.toFile()); @@ -61,7 +61,7 @@ public void testDuplicates() throws CoreException { @Test public void testPersistence() throws CoreException { IPath baseLocation = getRandomLocation(); - workspaceRule.deleteOnTearDown(baseLocation); + fileStoreExtension.deleteOnTearDown(baseLocation); HistoryBucket index1 = new HistoryBucket(); IPath location = baseLocation.append("location"); index1.load("foo", location.toFile()); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/HistoryStoreTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/HistoryStoreTest.java index 499431170ee..43194e5df82 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/HistoryStoreTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/HistoryStoreTest.java @@ -22,9 +22,9 @@ 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.ensureOutOfSync; -import static org.junit.Assert.assertEquals; -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.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.DataInputStream; @@ -55,19 +55,22 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.After; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.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; /** * This class defines all tests for the HistoryStore Class. */ +@ExtendWith(WorkspaceResetExtension.class) public class HistoryStoreTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + @RegisterExtension + private final FileStoreAutoDeleteExtension fileStoreExtension = new FileStoreAutoDeleteExtension(); static class LogListenerVerifier implements ILogListener { List actual = new ArrayList<>(); @@ -129,9 +132,9 @@ static class VerificationFailedException extends Exception { } public static void assertFileStateEquals(String tag, IFileState expected, IFileState actual) { - assertEquals(tag + " path differs", expected.getFullPath(), actual.getFullPath()); - assertEquals(tag + " timestamp differs", expected.getModificationTime(), actual.getModificationTime()); - assertEquals(tag + " uuid differs", ((FileState) expected).getUUID(), ((FileState) actual).getUUID()); + assertEquals(expected.getFullPath(), actual.getFullPath(), tag + " path differs"); + assertEquals(expected.getModificationTime(), actual.getModificationTime(), tag + " timestamp differs"); + assertEquals(((FileState) expected).getUUID(), ((FileState) actual).getUUID(), tag + " uuid differs"); } /* @@ -175,7 +178,7 @@ public IWorkspaceDescription setMaxFileStates(int maxFileStates) throws CoreExce return currentDescription; } - @After + @AfterEach public void tearDown() throws Exception { wipeHistoryStore(createTestMonitor()); } @@ -254,13 +257,13 @@ public void testAddStateAndPolicies() throws Exception { // assert that states are in the correct order (newer ones first) long lastModified = states[0].getModificationTime(); for (int i = 1; i < states.length; i++) { - assertTrue("1.3." + i, lastModified >= states[i].getModificationTime()); + assertTrue(lastModified >= states[i].getModificationTime(), i + ""); lastModified = states[i].getModificationTime(); } // assert that the most recent states were preserved for (int i = 0; i < states.length; i++) { - assertFileStateEquals("1.4." + i, oldStates[i], states[i]); + assertFileStateEquals(i + "", oldStates[i], states[i]); } /* test max file state size */ @@ -279,7 +282,7 @@ public void testAddStateAndPolicies() throws Exception { // #states = size + 1 for the 0 byte length file to begin with. for (int i = 0; i < states.length; i++) { int bytesRead = numBytes(states[i].getContents()); - assertTrue("2.2." + i, bytesRead <= description.getMaxFileStateSize()); + assertTrue(bytesRead <= description.getMaxFileStateSize(), i + ""); } /* test max file longevity */ @@ -324,7 +327,7 @@ public void testBug28238() throws Exception { IHistoryStore store = ((Resource) getWorkspace().getRoot()).getLocalManager().getHistoryStore(); // location of the data on disk - IFileStore fileStore = workspaceRule.getTempStore(); + IFileStore fileStore = fileStoreExtension.getTempStore(); createInFileSystem(fileStore); assertThat(store.getStates(file.getFullPath(), createTestMonitor())).as("check file has no state").isEmpty(); @@ -444,12 +447,12 @@ public void testClean() throws Exception { // assert that states are in the correct order (newer ones first) long lastModified = states[0].getModificationTime(); for (int i = 1; i < states.length; i++) { - assertTrue("2.4." + i, lastModified >= states[i].getModificationTime()); + assertTrue(lastModified >= states[i].getModificationTime(), i + ""); lastModified = states[i].getModificationTime(); } // Make sure we kept the 3 newer states. for (int i = 0; i < states.length; i++) { - assertTrue("2.5." + i, oldLastModTimes[i] == states[i].getModificationTime()); + assertTrue(oldLastModTimes[i] == states[i].getModificationTime(), i + ""); } /* test max file longevity */ @@ -531,7 +534,7 @@ public void testCopyFolder() throws Exception { // Check to make sure the file has been copied IFile file2 = folder2.getFile("file1.txt"); - assertTrue("1.3", file2.getFullPath().toString().endsWith("folder2/file1.txt")); + assertTrue(file2.getFullPath().toString().endsWith("folder2/file1.txt")); // Give the new (copied file) some new contents file2.setContents(createInputStream(contents[3]), true, true, createTestMonitor()); @@ -1122,7 +1125,7 @@ public void testMoveFolder() throws Exception { // Check to make sure the file has been moved IFile file2 = folder2.getFile("file1.txt"); - assertTrue("1.3", file2.getFullPath().toString().endsWith("folder2/file1.txt")); + assertTrue(file2.getFullPath().toString().endsWith("folder2/file1.txt")); // Give the new (moved file) some new contents file2.setContents(createInputStream(contents[3]), true, true, createTestMonitor()); @@ -1188,7 +1191,7 @@ public void testMoveProject() throws Exception { // Check to make sure the file has been moved IFile file2 = project2.getFile("folder1/file1.txt"); - assertTrue("1.3", file2.getFullPath().toString().endsWith("SecondMoveProjectProject/folder1/file1.txt")); + assertTrue(file2.getFullPath().toString().endsWith("SecondMoveProjectProject/folder1/file1.txt")); // Give the new (copied file) some new contents file2.setContents(createInputStream(contents[3]), true, true, createTestMonitor()); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/LocalSyncTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/LocalSyncTest.java index 0a31dfc6ebf..691618f6241 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/LocalSyncTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/LocalSyncTest.java @@ -22,9 +22,9 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createInFileSystem; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromFileSystem; -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.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.eclipse.core.internal.resources.ICoreConstants; import org.eclipse.core.internal.resources.TestingSupport; @@ -34,19 +34,17 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.WorkspaceResetExtension; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +@ExtendWith(WorkspaceResetExtension.class) public class LocalSyncTest implements ICoreConstants { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - private IProject project; - @Before + @BeforeEach public void createTestProject() throws CoreException { project = getWorkspace().getRoot().getProject("Project"); createInWorkspace(project); @@ -83,7 +81,7 @@ public void testProjectDeletion() throws CoreException { /* resources should not exist anymore */ for (int i = 1; i < resources.length; i++) { - assertFalse("Resource does unexpectedly exist: " + resources[i], resources[i].exists()); + assertFalse(resources[i].exists(), "Resource does unexpectedly exist: " + resources[i]); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/MoveTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/MoveTest.java index df68618805a..935e6aa3593 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/MoveTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/MoveTest.java @@ -25,12 +25,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.findAvailableDevices; -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.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.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 org.eclipse.core.internal.resources.File; import org.eclipse.core.internal.resources.Resource; @@ -47,30 +47,28 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Platform.OS; import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.WorkspaceResetExtension; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; /** * Tests the move operation. */ +@ExtendWith(WorkspaceResetExtension.class) public class MoveTest { private static final int NUMBER_OF_PROPERTIES = 5; - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - /** * This test has Windows as the target OS. Drives C: and D: should be available. */ @Test public void testMoveFileAcrossVolumes() throws CoreException { - assumeTrue("only relevant on Windows", OS.isWindows()); + assumeTrue(OS.isWindows(), "only relevant on Windows"); /* look for the adequate environment */ String[] devices = findAvailableDevices(); - assumeFalse("only executable if at least two volumes are present", devices[0] == null || devices[1] == null); + assumeFalse(devices[0] == null || devices[1] == null, "only executable if at least two volumes are present"); // create common objects String location = createUniqueString(); @@ -113,8 +111,8 @@ public void testMoveFileAcrossVolumes() throws CoreException { for (int j = 0; j < NUMBER_OF_PROPERTIES; j++) { String persistentValue = newFile.getPersistentProperty(propNames[j]); Object sessionValue = newFile.getSessionProperty(propNames[j]); - assertEquals("5.1", persistentValue, propValues[j]); - assertEquals("5.2", sessionValue, propValues[j]); + assertEquals(persistentValue, propValues[j]); + assertEquals(sessionValue, propValues[j]); } } @@ -160,8 +158,8 @@ public void testMoveFileBetweenProjects() throws Exception { for (int j = 0; j < NUMBER_OF_PROPERTIES; j++) { String persistentValue = newFile.getPersistentProperty(propNames[j]); Object sessionValue = newFile.getSessionProperty(propNames[j]); - assertEquals("persistent property value is not the same", propValues[j], persistentValue); - assertEquals("session property value is not the same", propValues[j], sessionValue); + assertEquals(propValues[j], persistentValue, "persistent property value is not the same"); + assertEquals(propValues[j], sessionValue, "session property value is not the same"); } } @@ -170,11 +168,11 @@ public void testMoveFileBetweenProjects() throws Exception { */ @Test public void testMoveFolderAcrossVolumes() throws CoreException { - assumeTrue("only relevant on Windows", OS.isWindows()); + assumeTrue(OS.isWindows(), "only relevant on Windows"); /* look for the adequate environment */ String[] devices = findAvailableDevices(); - assumeFalse("only executable if at least two volumes are present", devices[0] == null || devices[1] == null); + assumeFalse(devices[0] == null || devices[1] == null, "only executable if at least two volumes are present"); // create common objects String location = createUniqueString(); @@ -265,8 +263,8 @@ public void testMoveFolderBetweenProjects() throws Exception { for (int j = 0; j < NUMBER_OF_PROPERTIES; j++) { String persistentValue = newFolder.getPersistentProperty(propNames[j]); Object sessionValue = newFolder.getSessionProperty(propNames[j]); - assertEquals("persistent property value is not the same", propValues[j], persistentValue); - assertEquals("session property value is not the same", propValues[j], sessionValue); + assertEquals(propValues[j], persistentValue, "persistent property value is not the same"); + assertEquals(propValues[j], sessionValue, "session property value is not the same"); } } @@ -338,8 +336,8 @@ public void testMoveHierarchy() throws Exception { String propValue = sourceResource.getName() + propValues[j]; String persistentValue = destResource.getPersistentProperty(propName); Object sessionValue = destResource.getSessionProperty(propName); - assertEquals("persistent property value is not the same", propValue, persistentValue); - assertEquals("session property value is not the same", propValue, sessionValue); + assertEquals(propValue, persistentValue, "persistent property value is not the same"); + assertEquals(propValue, sessionValue, "session property value is not the same"); } } } @@ -411,8 +409,8 @@ public void testMoveHierarchyBetweenProjects() throws Exception { String propValue = sourceResource.getName() + propValues[j]; String persistentValue = destResource.getPersistentProperty(propName); Object sessionValue = destResource.getSessionProperty(propName); - assertEquals("persistent property value is not the same", propValue, persistentValue); - assertEquals("session property value is not the same", propValue, sessionValue); + assertEquals(propValue, persistentValue, "persistent property value is not the same"); + assertEquals(propValue, sessionValue, "session property value is not the same"); } } } @@ -541,8 +539,8 @@ public void testRenameFile() throws Exception { for (int j = 0; j < NUMBER_OF_PROPERTIES; j++) { String persistentValue = newFile.getPersistentProperty(propNames[j]); Object sessionValue = newFile.getSessionProperty(propNames[j]); - assertEquals("persistent property value is not the same", propValues[j], persistentValue); - assertEquals("session property value is not the same", propValues[j], sessionValue); + assertEquals(propValues[j], persistentValue, "persistent property value is not the same"); + assertEquals(propValues[j], sessionValue, "session property value is not the same"); } } @@ -593,8 +591,8 @@ public void testRenameFolder() throws Exception { for (int j = 0; j < NUMBER_OF_PROPERTIES; j++) { String persistentValue = newFolder.getPersistentProperty(propNames[j]); Object sessionValue = newFolder.getSessionProperty(propNames[j]); - assertEquals("persistent property value is not the same", propValues[j], persistentValue); - assertEquals("session property value is not the same", propValues[j], sessionValue); + assertEquals(propValues[j], persistentValue, "persistent property value is not the same"); + assertEquals(propValues[j], sessionValue, "session property value is not the same"); } } @@ -628,8 +626,8 @@ public void testRenameProjects() throws Exception { for (int i = 0; i < NUMBER_OF_PROPERTIES; i++) { String persistentValue = projects[i].getPersistentProperty(propNames[i]); Object sessionValue = projects[i].getSessionProperty(propNames[i]); - assertEquals("persistent property value is not the same", propValues[i], persistentValue); - assertEquals("session property value is not the same", propValues[i], sessionValue); + assertEquals(propValues[i], persistentValue, "persistent property value is not the same"); + assertEquals(propValues[i], sessionValue, "session property value is not the same"); } // move (rename) projects @@ -649,8 +647,8 @@ public void testRenameProjects() throws Exception { for (int i = 0; i < NUMBER_OF_PROPERTIES; i++) { String persistentValue = projects[i].getPersistentProperty(propNames[i]); Object sessionValue = projects[i].getSessionProperty(propNames[i]); - assertEquals("persistent property value is not the same", propValues[i], persistentValue); - assertEquals("session property value is not the same", propValues[i], sessionValue); + assertEquals(propValues[i], persistentValue, "persistent property value is not the same"); + assertEquals(propValues[i], sessionValue, "session property value is not the same"); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/PrefixPoolTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/PrefixPoolTest.java index 20d5ff38408..cd260a2b5af 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/PrefixPoolTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/PrefixPoolTest.java @@ -13,13 +13,13 @@ *******************************************************************************/ package org.eclipse.core.tests.internal.localstore; -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 org.eclipse.core.internal.localstore.PrefixPool; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PrefixPoolTest { diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/RefreshLocalPerformanceTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/RefreshLocalPerformanceTest.java index 815358c5ba2..97de870c0ae 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/RefreshLocalPerformanceTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/RefreshLocalPerformanceTest.java @@ -14,6 +14,7 @@ package org.eclipse.core.tests.internal.localstore; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.File; import java.util.Date; @@ -22,16 +23,13 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -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; +@ExtendWith(WorkspaceResetExtension.class) public class RefreshLocalPerformanceTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - /** big site default volume (windows) */ public static final String bigSiteDevice = "d:"; @@ -76,7 +74,7 @@ public long stopClock() { @Test public void testLocalRefreshPerformance() throws Exception { // test if the test can be done in this machine - Assume.assumeTrue(bigSiteLocation.toFile().isDirectory()); + assumeTrue(bigSiteLocation.toFile().isDirectory()); // create common objects int n = 10; diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/RefreshLocalTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/RefreshLocalTest.java index e570a940ddf..429c555c19f 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/RefreshLocalTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/RefreshLocalTest.java @@ -24,10 +24,10 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.isLocal; 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.assertNotSame; -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.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import org.eclipse.core.filesystem.IFileStore; @@ -40,19 +40,22 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.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; +@ExtendWith(WorkspaceResetExtension.class) public class RefreshLocalTest implements ICoreConstants { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + @RegisterExtension + private final FileStoreAutoDeleteExtension fileStoreExtension = new FileStoreAutoDeleteExtension(); private IProject project; - @Before + @BeforeEach public void createTestProject() throws CoreException { project = getWorkspace().getRoot().getProject("Project"); createInWorkspace(project); @@ -85,66 +88,13 @@ public void testDiscoverCaseChange() throws CoreException { assertTrue(project.isSynchronized(IResource.DEPTH_INFINITE)); } - /** - * Test discovery of a linked resource on refresh. - */ - @Test - public void testDiscoverLinkedResource() { - //create a linked resource with local contents missing - // IProject project = projects[0]; - // ensureExistsInWorkspace(project); - // IPath location = getRandomLocation(); - // IFile link = project.getFile("Link"); - // try { - // link.createLink(location, IResource.ALLOW_MISSING_LOCAL, getMonitor()); - // } catch (CoreException e) { - // fail("0.99", e); - // } - // - // //should not be synchronized (exists in ws, but not in fs) - // assertTrue("1.0", !project.isSynchronized(IResource.DEPTH_INFINITE)); - // assertTrue("1.1", !link.isSynchronized(IResource.DEPTH_ZERO)); - // - // //should exist in workspace - // assertTrue("1.3", link.exists()); - // - // //refreshing shouldn't get rid of the link - // try { - // link.refreshLocal(IResource.DEPTH_INFINITE, getMonitor()); - // } catch (CoreException e) { - // fail("1.99", e); - // } - // assertTrue("1.4", link.exists()); - // - // //create the contents in the file system - // try { - // createFileInFileSystem(location); - // } catch (CoreException e) { - // fail("2.99", e); - // } - // - // //should now be synchronized - // assertTrue("2.1", project.isSynchronized(IResource.DEPTH_INFINITE)); - // assertTrue("2.2", link.isSynchronized(IResource.DEPTH_ZERO)); - // - // //refresh - // try { - // link.refreshLocal(IResource.DEPTH_INFINITE, getMonitor()); - // } catch (CoreException e) { - // fail("3.99", e); - // } - // - // //assert should exist in workspace - // assertTrue("2.3", link.exists()); - } - /** * Tests discovering a file via refresh local when neither the file * nor its parent exists in the workspace. */ @Test public void testFileDiscovery() throws Throwable { - workspaceRule.deleteOnTearDown(project.getLocation()); + fileStoreExtension.deleteOnTearDown(project.getLocation()); IFolder folder = project.getFolder("Folder"); IFile file = folder.getFile("File"); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/SafeChunkyInputOutputStreamTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/SafeChunkyInputOutputStreamTest.java index f283060f58d..9bd8ee0828f 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/SafeChunkyInputOutputStreamTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/SafeChunkyInputOutputStreamTest.java @@ -17,9 +17,9 @@ import static org.eclipse.core.tests.harness.FileSystemHelper.getRandomLocation; import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomString; import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromFileSystem; -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.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.DataInputStream; import java.io.EOFException; @@ -30,17 +30,15 @@ import org.eclipse.core.internal.localstore.SafeChunkyInputStream; import org.eclipse.core.internal.localstore.SafeChunkyOutputStream; import org.eclipse.core.internal.resources.Workspace; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.WorkspaceResetExtension; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +@ExtendWith(WorkspaceResetExtension.class) public class SafeChunkyInputOutputStreamTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - private File temp; private List streams; @@ -54,16 +52,16 @@ private byte[] merge(byte[] b1, byte[] b2) { return result; } - @Before + @BeforeEach public void setUp() throws Exception { streams = new ArrayList<>(); temp = getRandomLocation().append("temp").toFile(); temp.mkdirs(); - assertTrue("could not create temp directory", temp.isDirectory()); + assertTrue(temp.isDirectory(), "could not create temp directory"); target = new File(temp, "target"); } - @After + @AfterEach public void tearDown() throws Exception { for (SafeChunkyOutputStream stream : streams) { try { @@ -78,7 +76,7 @@ public void tearDown() throws Exception { @Test public void testBufferLimit() throws Exception { Workspace.clear(target); // make sure there was nothing here before - assertTrue(!target.exists()); + assertFalse(target.exists()); // use only one chunk but bigger than the buffer int bufferSize = 10024; @@ -192,7 +190,7 @@ private void doNothing(SafeChunkyOutputStream output) { @Test public void testAlmostEmpty() throws Exception { Workspace.clear(target); // make sure there was nothing here before - assertTrue(!target.exists()); + assertFalse(target.exists()); // open the file but don't write anything. try (SafeChunkyOutputStream output = new SafeChunkyOutputStream(target)) { diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/SafeFileInputOutputStreamTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/SafeFileInputOutputStreamTest.java index a129ffbaa18..c401badd014 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/SafeFileInputOutputStreamTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/SafeFileInputOutputStreamTest.java @@ -17,8 +17,8 @@ import static org.eclipse.core.tests.harness.FileSystemHelper.getRandomLocation; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInputStream; import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomString; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; @@ -27,15 +27,18 @@ import org.eclipse.core.internal.localstore.SafeFileOutputStream; import org.eclipse.core.internal.resources.Workspace; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; - +import org.eclipse.core.tests.resources.util.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; + +@ExtendWith(WorkspaceResetExtension.class) public class SafeFileInputOutputStreamTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + @RegisterExtension + private final FileStoreAutoDeleteExtension fileStoreExtension = new FileStoreAutoDeleteExtension(); private IPath temp; @@ -52,12 +55,12 @@ private InputStream getContents(java.io.File target) throws IOException { return new SafeFileInputStream(target); } - @Before + @BeforeEach public void setUp() throws Exception { temp = getRandomLocation().append("temp"); temp.toFile().mkdirs(); - workspaceRule.deleteOnTearDown(temp); - assertTrue("could not create temp directory", temp.toFile().isDirectory()); + fileStoreExtension.deleteOnTearDown(temp); + assertTrue(temp.toFile().isDirectory(), "could not create temp directory"); } @Test diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/UnifiedTreeTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/UnifiedTreeTest.java index 51c953327d0..d0517a45e45 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/UnifiedTreeTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/UnifiedTreeTest.java @@ -18,9 +18,9 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import static org.eclipse.core.tests.resources.ResourceTestUtil.createUniqueString; -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.File; @@ -44,17 +44,20 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.tests.resources.WorkspaceTestRule; -import org.junit.Rule; -import org.junit.Test; +import org.eclipse.core.tests.resources.util.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 UnifiedTreeTest { - @Rule - public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - private static final int LIMIT = 10; + @RegisterExtension + private final FileStoreAutoDeleteExtension fileStoreExtension = new FileStoreAutoDeleteExtension(); + protected void createFiles(IFileStore folder, Hashtable set) throws Exception { for (int i = 0; i < LIMIT; i++) { IFileStore child = folder.getChild("fsFile" + i); @@ -276,7 +279,7 @@ public void test342968() throws CoreException { IFileStore fileStore = EFS.getLocalFileSystem().fromLocalFile(file); link.createLink(fileStore.toURI(), IResource.NONE, null); - workspaceRule.deleteOnTearDown(fileStore); + fileStoreExtension.deleteOnTearDown(fileStore); IFile rf = link.getFile("fileTest342968.txt"); rf.create(new ByteArrayInputStream("test342968".getBytes()), false, null);