From a022584d54d1d098f9891d13ede442cc14cc08c5 Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Wed, 14 Aug 2024 14:34:25 +0200 Subject: [PATCH] Improve assertions in resource regression tests #903 This change removes non-useful messages from assertions in org.eclipse.core.tests.resources.regression. In cases where multiple assertions without proper messages are placed in subsequent lines of code, assertions are improved to provide better messages and help identifying the failing line of code. This particularly affects assertTrue/assertFalse statements that are replaced with assertThat().matches(). This also prepares for a migration of assertions to JUnit 5, which would otherwise require swapping of parameters, as the message parameter has been moved to the end of the parameter list. Contributes to https://github.com/eclipse-platform/eclipse.platform/issues/903 --- .../resources/regression/Bug_006708.java | 8 +- .../resources/regression/Bug_025457.java | 27 ++-- .../resources/regression/Bug_026294.java | 130 +++++++++-------- .../resources/regression/Bug_027271.java | 4 +- .../resources/regression/Bug_028981.java | 21 +-- .../resources/regression/Bug_029671.java | 12 +- .../resources/regression/Bug_032076.java | 132 ++++++++++-------- .../resources/regression/Bug_044106.java | 17 ++- .../resources/regression/Bug_092108.java | 6 +- .../resources/regression/Bug_126104.java | 9 +- .../resources/regression/Bug_147232.java | 2 +- .../resources/regression/Bug_160251.java | 36 +++-- .../resources/regression/Bug_165892.java | 52 +++---- .../resources/regression/Bug_192631.java | 26 ++-- .../resources/regression/Bug_226264.java | 4 +- .../resources/regression/Bug_231301.java | 9 +- .../resources/regression/Bug_233939.java | 3 +- .../resources/regression/Bug_265810.java | 13 +- .../resources/regression/Bug_303517.java | 57 ++++---- .../resources/regression/Bug_329836.java | 11 +- .../resources/regression/Bug_331445.java | 8 +- .../resources/regression/Bug_378156.java | 6 +- .../resources/regression/Bug_380386.java | 8 +- .../tests/resources/regression/IFileTest.java | 10 +- .../resources/regression/IFolderTest.java | 35 ++--- .../resources/regression/IProjectTest.java | 23 +-- .../resources/regression/IResourceTest.java | 52 +++---- .../regression/LocalStoreRegressionTests.java | 15 +- .../resources/regression/PR_1GEAB3C_Test.java | 13 +- .../resources/regression/PR_1GH2B0N_Test.java | 2 +- 30 files changed, 395 insertions(+), 356 deletions(-) diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_006708.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_006708.java index 07451ce89ce..64a7348335d 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_006708.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_006708.java @@ -13,11 +13,13 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; -import static org.junit.Assert.assertFalse; +import static java.util.function.Predicate.not; +import static org.assertj.core.api.Assertions.assertThat; import java.io.ByteArrayInputStream; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; @@ -34,14 +36,14 @@ public class Bug_006708 { public void testBug() throws CoreException { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject sourceProj = root.getProject("bug_6708"); - assertFalse("Project bug_6708 exists already", sourceProj.exists()); + assertThat(sourceProj).matches(not(IResource::exists), "does not exists already"); sourceProj.create(null); sourceProj.open(null); IFile source = sourceProj.getFile("Source.txt"); source.create(new ByteArrayInputStream("abcdef".getBytes()), false, null); IProject destProj = root.getProject("bug_6708_2"); - assertFalse("Project bug_6708_2 exists already", destProj.exists()); + assertThat(destProj).matches(not(IResource::exists), "does not exists already"); destProj.create(null); destProj.open(null); IFile dest = destProj.getFile("Dest.txt"); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_025457.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_025457.java index 64f7b80d8c2..3abc4ce5c87 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_025457.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_025457.java @@ -13,13 +13,14 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; +import static java.util.function.Predicate.not; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomString; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import static org.eclipse.core.tests.resources.ResourceTestUtil.isReadOnlySupported; import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -66,11 +67,11 @@ public void testFile() throws Exception { () -> sourceFile.move(destFile.getFullPath(), IResource.NONE, createTestMonitor())); } //ensure source still exists and has same content - assertTrue("2.0", source.exists()); - assertTrue("2.1", sourceFile.exists()); + assertThat(source).matches(IResource::exists, "exists"); + assertThat(sourceFile).matches(IResource::exists, "exists"); assertEquals(content, sourceFile.readString()); //ensure destination file does not exist - assertTrue("2.3", !destFile.exists()); + assertThat(destFile).matches(not(IResource::exists), "not exists"); } @Test @@ -93,13 +94,13 @@ public void testFolder() throws IOException, CoreException { assertThrows(CoreException.class, () -> sourceFolder.move(destFolder.getFullPath(), IResource.NONE, createTestMonitor())); //ensure source still exists - assertTrue("2.0", source.exists()); - assertTrue("2.1", sourceFolder.exists()); - assertTrue("2.2", sourceFile.exists()); + assertThat(source).matches(IResource::exists, "exists"); + assertThat(sourceFolder).matches(IResource::exists, "exists"); + assertThat(sourceFile).matches(IResource::exists, "exists"); //ensure destination does not exist - assertTrue("2.3", !destFolder.exists()); - assertTrue("2.4", !destFile.exists()); + assertThat(destFolder).matches(not(IResource::exists), "not exists"); + assertThat(destFile).matches(not(IResource::exists), "not exists"); } } @@ -121,12 +122,12 @@ public void testProject() throws IOException, CoreException { () -> source.move(destination.getFullPath(), IResource.NONE, createTestMonitor())); //ensure source does not exist - assertTrue("2.0", !source.exists()); - assertTrue("2.1", !sourceFile.exists()); + assertThat(source).matches(not(IResource::exists), "not exists"); + assertThat(sourceFile).matches(not(IResource::exists), "not exists"); //ensure destination does not exist - assertTrue("2.2", destination.exists()); - assertTrue("2.3", destFile.exists()); + assertThat(destination).matches(IResource::exists, "exists"); + assertThat(destFile).matches(IResource::exists, "exists"); } } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_026294.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_026294.java index dd482c860ef..db4951e4351 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_026294.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_026294.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; +import static java.util.function.Predicate.not; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.assertDoesNotExistInFileSystem; import static org.eclipse.core.tests.resources.ResourceTestUtil.assertDoesNotExistInWorkspace; @@ -24,10 +26,10 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.isReadOnlySupported; import static org.eclipse.core.tests.resources.ResourceTestUtil.setReadOnly; import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import java.io.InputStream; +import java.util.function.Predicate; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; @@ -47,6 +49,12 @@ */ public class Bug_026294 { + private static final Predicate isSynchronizedDepthInfinite = resource -> resource + .isSynchronized(IResource.DEPTH_INFINITE); + + private static final Predicate isSynchronizedDepthZero = resource -> resource + .isSynchronized(IResource.DEPTH_ZERO); + @Rule public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); @@ -78,8 +86,8 @@ public void testDeleteOpenProjectWindows() throws Exception { // opens a file so it cannot be removed on Windows try (InputStream input = file1.getContents()) { - assertTrue("1.2", projectFile.exists()); - assertTrue("1.3", projectFile.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(projectFile).matches(IResource::exists, "exists"); + assertThat(projectFile).matches(isSynchronizedDepthInfinite, "is synchronized"); assertThrows(CoreException.class, () -> project.delete(IResource.FORCE, createTestMonitor())); @@ -90,35 +98,35 @@ public void testDeleteOpenProjectWindows() throws Exception { assertExistsInWorkspace(file1); assertExistsInFileSystem(file1); - assertTrue("2.2.3", file1.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(file1).matches(isSynchronizedDepthInfinite, "is synchronized"); assertDoesNotExistInWorkspace(file2); assertDoesNotExistInFileSystem(file2); - assertTrue("2.3.3", file2.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(file2).matches(isSynchronizedDepthInfinite, "is synchronized"); assertDoesNotExistInWorkspace(file3); assertDoesNotExistInFileSystem(file3); - assertTrue("2.4.3", file3.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(file3).matches(isSynchronizedDepthInfinite, "is synchronized"); assertExistsInWorkspace(folder); assertExistsInFileSystem(folder); - assertTrue("2.5.3", folder.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(folder).matches(isSynchronizedDepthInfinite, "is synchronized"); assertExistsInWorkspace(projectFile); assertExistsInFileSystem(projectFile); - assertTrue("2.6.3", projectFile.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(projectFile).matches(isSynchronizedDepthInfinite, "is synchronized"); - assertTrue("2.7.0", project.isSynchronized(IResource.DEPTH_ZERO)); - assertTrue("2.7.1", project.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(project).matches(isSynchronizedDepthZero, "is synchronized"); + assertThat(project).matches(isSynchronizedDepthInfinite, "is synchronized"); } - assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(project).matches(isSynchronizedDepthInfinite, "is synchronized"); project.delete(IResource.FORCE, createTestMonitor()); - assertTrue("5.1", !project.exists()); - assertTrue("5.2", !file1.exists()); - assertTrue("5.3", file1.isSynchronized(IResource.DEPTH_INFINITE)); - assertTrue("5.4", project.isSynchronized(IResource.DEPTH_INFINITE)); - assertTrue("6.0", !projectRoot.toFile().exists()); + assertThat(project).matches(not(IResource::exists), "not exists"); + assertThat(file1).matches(not(IResource::exists), "not exists"); + assertThat(file1).matches(isSynchronizedDepthInfinite, "is synchronized"); + assertThat(project).matches(isSynchronizedDepthInfinite, "is synchronized"); + assertThat(projectRoot).matches(it -> !it.toFile().exists(), "not exists"); } /** @@ -144,29 +152,29 @@ public void testDeleteOpenProjectLinux() throws CoreException { setReadOnly(folder, true); IFile projectFile = project.getFile(".project"); - assertTrue("1.2", projectFile.exists()); - assertTrue("1.3", projectFile.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(projectFile).matches(IResource::exists, "exists"); + assertThat(projectFile).matches(isSynchronizedDepthInfinite, "is synchronized"); assertThrows(CoreException.class, () -> project.delete(IResource.FORCE, createTestMonitor())); - assertTrue("2.1", project.exists()); - assertTrue("2.2", file1.exists()); - assertTrue("2.3", !file2.exists()); - assertTrue("2.5", folder.exists()); - assertTrue("2.6", projectFile.exists()); - assertTrue("2.7", project.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(project).matches(IResource::exists, "exists"); + assertThat(file1).matches(IResource::exists, "exists"); + assertThat(file2).matches(not(IResource::exists), "not exists"); + assertThat(folder).matches(IResource::exists, "exists"); + assertThat(projectFile).matches(IResource::exists, "exists"); + assertThat(project).matches(isSynchronizedDepthInfinite, "is synchronized"); } finally { if (folder.exists()) { setReadOnly(folder, false); } } - assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(project).matches(isSynchronizedDepthInfinite, "is synchronized"); project.delete(IResource.FORCE, createTestMonitor()); - assertTrue("5.1", !project.exists()); - assertTrue("5.2", !file1.exists()); - assertTrue("5.3", file1.isSynchronized(IResource.DEPTH_INFINITE)); - assertTrue("5.4", project.isSynchronized(IResource.DEPTH_INFINITE)); - assertTrue("6.0", !projectRoot.toFile().exists()); + assertThat(project).matches(not(IResource::exists), "not exists"); + assertThat(file1).matches(not(IResource::exists), "not exists"); + assertThat(file1).matches(isSynchronizedDepthInfinite, "is synchronized"); + assertThat(project).matches(isSynchronizedDepthInfinite, "is synchronized"); + assertThat(projectRoot).matches(it -> !it.toFile().exists(), "not exists"); } /** @@ -194,16 +202,16 @@ public void testDeleteClosedProjectWindows() throws Exception { project.close(createTestMonitor()); assertThrows(CoreException.class, () -> project.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, createTestMonitor())); - assertTrue("2.1", project.exists()); - assertTrue("2.7", project.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(project).matches(IResource::exists, "exists"); + assertThat(project).matches(isSynchronizedDepthInfinite, "is synchronized"); assertExistsInFileSystem(projectFile); } - assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(project).matches(isSynchronizedDepthInfinite, "is synchronized"); project.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, createTestMonitor()); - assertTrue("5.1", !project.exists()); - assertTrue("5.3", project.isSynchronized(IResource.DEPTH_INFINITE)); - assertTrue("6.0", !projectRoot.toFile().exists()); + assertThat(project).matches(not(IResource::exists), "not exists"); + assertThat(project).matches(isSynchronizedDepthInfinite, "is synchronized"); + assertThat(projectRoot).matches(it -> !it.toFile().exists(), "not exists"); assertDoesNotExistInFileSystem(projectFile); } @@ -234,8 +242,8 @@ public void testDeleteClosedProjectLinux() throws CoreException { assertThrows(CoreException.class, () -> project.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, createTestMonitor())); - assertTrue("3.0", project.exists()); - assertTrue("3.1", project.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(project).matches(IResource::exists, "exists"); + assertThat(project).matches(isSynchronizedDepthInfinite, "is synchronized"); assertExistsInFileSystem(projectFile); project.open(createTestMonitor()); @@ -246,9 +254,9 @@ public void testDeleteClosedProjectLinux() throws CoreException { } project.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, createTestMonitor()); - assertTrue("6.0", !project.exists()); - assertTrue("6.1", project.isSynchronized(IResource.DEPTH_INFINITE)); - assertTrue("6.2", !projectRoot.toFile().exists()); + assertThat(project).matches(not(IResource::exists), "not exists"); + assertThat(project).matches(isSynchronizedDepthInfinite, "is synchronized"); + assertThat(projectRoot).matches(it -> !it.toFile().exists(), "not exists"); assertDoesNotExistInFileSystem(projectFile); } @@ -273,18 +281,18 @@ public void testDeleteFolderWindows() throws Exception { // opens a file so it cannot be removed on Windows try (InputStream input = file1.getContents()) { assertThrows(CoreException.class, () -> folder.delete(IResource.FORCE, createTestMonitor())); - assertTrue("2.2", file1.exists()); - assertTrue("2.4", !file3.exists()); - assertTrue("2.5", folder.exists()); - assertTrue("2.7", folder.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(file1).matches(IResource::exists, "exists"); + assertThat(file3).matches(not(IResource::exists), "not exists"); + assertThat(folder).matches(IResource::exists, "exists"); + assertThat(folder).matches(isSynchronizedDepthInfinite, "is synchronized"); } - assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(project).matches(isSynchronizedDepthInfinite, "is synchronized"); folder.delete(IResource.FORCE, createTestMonitor()); - assertTrue("5.1", !file1.exists()); - assertTrue("5.2", !folder.exists()); - assertTrue("5.3", file1.isSynchronized(IResource.DEPTH_INFINITE)); - assertTrue("5.4", folder.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(file1).matches(not(IResource::exists), "not exists"); + assertThat(folder).matches(not(IResource::exists), "not exists"); + assertThat(file1).matches(isSynchronizedDepthInfinite, "is synchronized"); + assertThat(folder).matches(isSynchronizedDepthInfinite, "is synchronized"); } /** @@ -311,24 +319,24 @@ public void testDeleteFolderLinux() throws CoreException { setReadOnly(subFolder, true); assertThrows(CoreException.class, () -> folder.delete(IResource.FORCE, createTestMonitor())); - assertTrue("2.2", file1.exists()); - assertTrue("2.3", subFolder.exists()); - assertTrue("2.4", !file3.exists()); - assertTrue("2.5", folder.exists()); - assertTrue("2.7", folder.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(file1).matches(IResource::exists, "exists"); + assertThat(subFolder).matches(IResource::exists, "exists"); + assertThat(file3).matches(not(IResource::exists), "not exists"); + assertThat(folder).matches(IResource::exists, "exists"); + assertThat(folder).matches(isSynchronizedDepthInfinite, "is synchronized"); } finally { if (subFolder.exists()) { setReadOnly(subFolder, false); } } - assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(project).matches(isSynchronizedDepthInfinite, "is synchronized"); folder.delete(IResource.FORCE, createTestMonitor()); - assertTrue("5.1", !file1.exists()); - assertTrue("5.2", !subFolder.exists()); - assertTrue("5.3", !folder.exists()); - assertTrue("5.4", file1.isSynchronized(IResource.DEPTH_INFINITE)); - assertTrue("5.5", folder.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(file1).matches(not(IResource::exists), "not exists"); + assertThat(subFolder).matches(not(IResource::exists), "not exists"); + assertThat(folder).matches(not(IResource::exists), "not exists"); + assertThat(file1).matches(isSynchronizedDepthInfinite, "is synchronized"); + assertThat(folder).matches(isSynchronizedDepthInfinite, "is synchronized"); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_027271.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_027271.java index a306838d280..e08045594cc 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_027271.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_027271.java @@ -15,7 +15,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; import static org.junit.Assume.assumeTrue; import org.eclipse.core.resources.IPathVariableManager; @@ -81,7 +81,7 @@ public void testBug() { //sets invalid value (invalid path) IPath invalidPath = IPath.fromOSString("c:\\a\\:\\b"); prefs.setValue(VARIABLE_PREFIX + "ANOTHER_INVALID_VAR", invalidPath.toPortableString()); - assertTrue("3.0", !IPath.EMPTY.isValidPath(invalidPath.toPortableString())); + assertFalse(IPath.EMPTY.isValidPath(invalidPath.toPortableString())); assertThat(pvm.getPathVariableNames()).containsExactly("VALID_VAR"); } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_028981.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_028981.java index 88afba5c598..34b37089d6f 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_028981.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_028981.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; +import static java.util.function.Predicate.not; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomString; @@ -60,11 +62,12 @@ public void testBug() throws CoreException { createInWorkspace(new IResource[] {teamPrivateFile, regularFile}); synchronizer.setSyncInfo(partner, phantomFile, createRandomString().getBytes()); teamPrivateFile.setTeamPrivateMember(true); - assertTrue("0.7", !regularFile.isPhantom() && !regularFile.isTeamPrivateMember()); - assertTrue("0.8", teamPrivateFile.isTeamPrivateMember()); - assertTrue("0.8b", teamPrivateFile.exists()); - assertTrue("0.9", phantomFile.isPhantom()); - assertTrue("0.9b", !phantomFile.exists()); + assertThat(regularFile).matches(not(IResource::isPhantom), "is not phantom"); + assertThat(regularFile).matches(not(IResource::isTeamPrivateMember), "is not team-private member"); + assertThat(teamPrivateFile).matches(IResource::isTeamPrivateMember, "is team-private member"); + assertThat(teamPrivateFile).matches(IResource::exists, "exists"); + assertThat(phantomFile).matches(IResource::isPhantom, "is phantom"); + assertThat(phantomFile).matches(not(IResource::exists), "not exists"); ResourceVisitorVerifier verifier = new ResourceVisitorVerifier(); @@ -74,7 +77,7 @@ public void testBug() throws CoreException { verifier.addExpected(settings); verifier.addExpected(prefs); project.accept(verifier); - assertTrue("1.1 - " + verifier.getMessage(), verifier.isValid()); + assertTrue(verifier.getMessage(), verifier.isValid()); verifier.reset(); assertThrows(CoreException.class, () -> phantomFile.accept(verifier)); @@ -82,17 +85,17 @@ public void testBug() throws CoreException { verifier.reset(); verifier.addExpected(phantomFile); phantomFile.accept(verifier, IResource.DEPTH_INFINITE, IContainer.INCLUDE_PHANTOMS); - assertTrue("3.1 - " + verifier.getMessage(), verifier.isValid()); + assertTrue(verifier.getMessage(), verifier.isValid()); verifier.reset(); // no resources should be visited teamPrivateFile.accept(verifier); - assertTrue("4.1 - " + verifier.getMessage(), verifier.isValid()); + assertTrue(verifier.getMessage(), verifier.isValid()); verifier.reset(); verifier.addExpected(teamPrivateFile); teamPrivateFile.accept(verifier, IResource.DEPTH_INFINITE, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS); - assertTrue("5.1 - " + verifier.getMessage(), verifier.isValid()); + assertTrue(verifier.getMessage(), verifier.isValid()); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_029671.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_029671.java index f1823f14d42..1032f351477 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_029671.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_029671.java @@ -13,16 +13,18 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; +import static java.util.function.Predicate.not; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomString; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; -import static org.junit.Assert.assertTrue; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ISynchronizer; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.runtime.CoreException; @@ -61,14 +63,14 @@ public void testBug() throws CoreException { IFile targetFile = targetFolder.getFile(file.getName()); folder.move(targetFolder.getFullPath(), false, false, createTestMonitor()); - assertTrue("3.0", folder.isPhantom()); - assertTrue("4.0", file.isPhantom()); + assertThat(folder).matches(IResource::isPhantom, "is phantom"); + assertThat(file).matches(IResource::isPhantom, "is phantom"); assertExistsInWorkspace(targetFolder); - assertTrue("5.1", !targetFolder.isPhantom()); + assertThat(targetFolder).matches(not(IResource::isPhantom), "is not phantom"); assertExistsInWorkspace(targetFile); - assertTrue("6.1", !targetFile.isPhantom()); + assertThat(targetFile).matches(not(IResource::isPhantom), "is not phantom"); } finally { synchronizer.remove(partner); } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_032076.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_032076.java index eee767f4f18..b331ec8ada3 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_032076.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_032076.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; +import static java.util.function.Predicate.not; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomString; @@ -23,10 +25,10 @@ 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 java.io.InputStream; +import java.util.function.Predicate; import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.internal.resources.Resource; import org.eclipse.core.resources.IFile; @@ -49,6 +51,12 @@ */ public class Bug_032076 { + private static final Predicate isSynchronizedDepthInfinite = resource -> resource + .isSynchronized(IResource.DEPTH_INFINITE); + + private static final Predicate isSynchronizedDepthZero = resource -> resource + .isSynchronized(IResource.DEPTH_ZERO); + @Rule public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); @@ -81,27 +89,27 @@ public void testFileBugOnWindows() throws Exception { () -> sourceFile.move(destinationFile.getFullPath(), IResource.FORCE, createTestMonitor())); // the source parent is in sync - assertTrue("3.0", sourceParent.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(sourceParent).matches(isSynchronizedDepthInfinite, "is synchronized"); // the target parent is in sync - assertTrue("3.1", destinationParent.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(destinationParent).matches(isSynchronizedDepthInfinite, "is synchronized"); // file has been copied to destination - assertTrue("3.4", destinationFile.exists()); + assertThat(destinationFile).matches(IResource::exists, "exists"); // ensure marker info has not been lost IMarker marker = destinationFile.findMarker(markerId); - assertNotNull("3.6", marker); - assertEquals("3.7", attributeValue, marker.getAttribute(attributeKey)); + assertNotNull(marker); + assertEquals(attributeValue, marker.getAttribute(attributeKey)); // non-removable file has been moved (but not in file system - they are out-of-sync) - assertTrue("4.1", sourceFile.exists()); - assertTrue("4.2", sourceFile.isSynchronized(IResource.DEPTH_ZERO)); + assertThat(sourceFile).matches(IResource::exists, "exists"); + assertThat(sourceFile).matches(isSynchronizedDepthZero, "is synchronized"); // refresh the source parent sourceParent.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); // file is still found in source tree - assertTrue("4.7", sourceFile.exists()); + assertThat(sourceFile).matches(IResource::exists, "exists"); } } @@ -137,33 +145,33 @@ public void testFolderBugOnWindows() throws Exception { () -> folder.move(destinationFolder.getFullPath(), IResource.FORCE, createTestMonitor())); // the source parent is in sync - assertTrue("3.0", sourceParent.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(sourceParent).matches(isSynchronizedDepthInfinite, "is synchronized"); // the target parent is in-sync - assertTrue("3.1", destinationParent.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(destinationParent).matches(isSynchronizedDepthInfinite, "is synchronized"); // resources have been copied to destination - assertTrue("3.3", destinationFolder.exists()); - assertTrue("3.4", destinationFolder.getFile(file1.getName()).exists()); - assertTrue("3.5", destinationFolder.getFile(file2.getName()).exists()); + assertThat(destinationFolder).matches(IResource::exists, "exists"); + assertThat(destinationFolder.getFile(file1.getName())).matches(IResource::exists, "exists"); + assertThat(destinationFolder.getFile(file2.getName())).matches(IResource::exists, "exists"); // ensure marker info has not been lost IMarker marker = destinationFolder.getFile(file1.getName()).findMarker(markerId); - assertNotNull("3.6", marker); - assertEquals("3.7", attributeValue, marker.getAttribute(attributeKey)); + assertNotNull(marker); + assertEquals(attributeValue, marker.getAttribute(attributeKey)); // non-removable resources still exist in source - assertTrue("4.1", folder.exists()); - assertTrue("4.2", file1.exists()); + assertThat(folder).matches(IResource::exists, "exists"); + assertThat(file1).matches(IResource::exists, "exists"); //this file should be successfully moved - assertTrue("4.3", !file2.exists()); + assertThat(file2).matches(not(IResource::exists), "not exists"); // refresh the source parent sourceParent.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); // non-removable resources still in source tree - assertTrue("4.6", folder.exists()); - assertTrue("4.7", file1.exists()); - assertTrue("4.8", !file2.exists()); + assertThat(folder).matches(IResource::exists, "exists"); + assertThat(file1).matches(IResource::exists, "exists"); + assertThat(file2).matches(not(IResource::exists), "not exists"); } } @@ -197,21 +205,21 @@ public void testProjectBugOnWindows() throws Exception { () -> sourceProject.move(destinationProject.getFullPath(), IResource.FORCE, createTestMonitor())); // the source does not exist - assertTrue("3.0", !sourceProject.exists()); - assertTrue("3.1", sourceProject.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(sourceProject).matches(not(IResource::exists), "not exists"); + assertThat(sourceProject).matches(isSynchronizedDepthInfinite, "is synchronized"); // the target exists and is in sync - assertTrue("3.2", destinationProject.exists()); - assertTrue("3.3", destinationProject.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(destinationProject).matches(IResource::exists, "exists"); + assertThat(destinationProject).matches(isSynchronizedDepthInfinite, "is synchronized"); // resources have been copied to destination - assertTrue("3.4", destinationProject.getFile(file1.getProjectRelativePath()).exists()); - assertTrue("3.5", destinationProject.getFile(file2.getProjectRelativePath()).exists()); + assertThat(destinationProject.getFile(file1.getProjectRelativePath())).matches(IResource::exists, "exists"); + assertThat(destinationProject.getFile(file2.getProjectRelativePath())).matches(IResource::exists, "exists"); // ensure marker info has not been lost IMarker marker = destinationProject.getFile(file1.getProjectRelativePath()).findMarker(markerId); - assertNotNull("3.6", marker); - assertEquals("3.7", attributeValue, marker.getAttribute(attributeKey)); - assertTrue("5.0", workspace.getRoot().isSynchronized(IResource.DEPTH_INFINITE)); + assertNotNull(marker); + assertEquals(attributeValue, marker.getAttribute(attributeKey)); + assertThat(workspace.getRoot()).matches(isSynchronizedDepthInfinite, "is synchronized"); } } @@ -249,26 +257,26 @@ public void testFileBugOnLinux() throws CoreException { () -> sourceFile.move(destinationFile.getFullPath(), IResource.FORCE, createTestMonitor())); // the source parent is out-of-sync - assertTrue("3.0", !sourceParent.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(sourceParent).matches(not(isSynchronizedDepthInfinite), "is not synchronized"); // the target parent is in-sync - assertTrue("3.1", destinationParent.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(destinationParent).matches(isSynchronizedDepthInfinite, "is synchronized"); // file has been copied to destination - assertTrue("3.4", destinationFile.exists()); + assertThat(destinationFile).matches(IResource::exists, "exists"); // ensure marker info has not been lost IMarker marker = destinationFile.findMarker(markerId); - assertNotNull("3.6", marker); - assertEquals("3.7", attributeValue, marker.getAttribute(attributeKey)); + assertNotNull(marker); + assertEquals(attributeValue, marker.getAttribute(attributeKey)); // non-removable file has been moved (but not in file system - they are out-of-sync) - assertTrue("4.1", !sourceFile.exists()); + assertThat(sourceFile).matches(not(IResource::exists), "not exists"); // refresh the source parent sourceParent.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); // non-removable file now reappear in the resource tree - assertTrue("4.7", sourceFile.exists()); + assertThat(sourceFile).matches(IResource::exists, "exists"); } finally { setReadOnly(roFolderStore, false); } @@ -311,38 +319,38 @@ public void testFolderBugOnLinux() throws CoreException { .move(destinationParent.getFullPath().append(roFolder.getName()), IResource.FORCE, createTestMonitor())); // the source parent is out-of-sync - assertTrue("3.0", !sourceParent.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(sourceParent).matches(not(isSynchronizedDepthInfinite), "is not synchronized"); // the target parent is in-sync - assertTrue("3.1", destinationParent.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(destinationParent).matches(isSynchronizedDepthInfinite, "is synchronized"); // resources have been copied to destination IFolder destinationFolder = destinationROFolder.getFolder(folder.getName()); IFile destinationFile1 = destinationROFolder.getFile(file1.getName()); IFile destinationFile2 = destinationFolder.getFile(file2.getName()); - assertTrue("3.2", destinationROFolder.exists()); - assertTrue("3.4", destinationFolder.exists()); - assertTrue("3.5", destinationFile1.exists()); - assertTrue("3.6", destinationFile2.exists()); + assertThat(destinationROFolder).matches(IResource::exists, "exists"); + assertThat(destinationFolder).matches(IResource::exists, "exists"); + assertThat(destinationFile1).matches(IResource::exists, "exists"); + assertThat(destinationFile2).matches(IResource::exists, "exists"); // ensure marker info has not been lost IMarker marker = destinationROFolder.getFile(file1.getName()).findMarker(markerId); - assertNotNull("3.7", marker); - assertEquals("3.8", attributeValue, marker.getAttribute(attributeKey)); + assertNotNull(marker); + assertEquals(attributeValue, marker.getAttribute(attributeKey)); // non-removable resources have been moved (but not in file system - they are out-of-sync) - assertTrue("4.0", !roFolder.exists()); - assertTrue("4.1", !folder.exists()); - assertTrue("4.2", !file1.exists()); - assertTrue("4.3", !file2.exists()); + assertThat(roFolder).matches(not(IResource::exists), "not exists"); + assertThat(folder).matches(not(IResource::exists), "not exists"); + assertThat(file1).matches(not(IResource::exists), "not exists"); + assertThat(file2).matches(not(IResource::exists), "not exists"); // refresh the source parent sourceParent.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); // non-removed resources now reappear in the resource tree - assertTrue("4.5", roFolder.exists()); - assertTrue("4.6", folder.exists()); - assertTrue("4.7", file1.exists()); - assertTrue("4.8", !file2.exists()); + assertThat(roFolder).matches(IResource::exists, "exists"); + assertThat(folder).matches(IResource::exists, "exists"); + assertThat(file1).matches(IResource::exists, "exists"); + assertThat(file2).matches(not(IResource::exists), "not exists"); } finally { setReadOnly(roFolderLocation, false); setReadOnly(destinationROFolderLocation, false); @@ -390,22 +398,22 @@ public void testProjectBugOnLinux() throws CoreException { workspaceRule.deleteOnTearDown(destinationProject.getLocation()); // the source does not exist - assertTrue("3.0", !sourceProject.exists()); + assertThat(sourceProject).matches(not(IResource::exists), "not exists"); // the target exists and is in sync - assertTrue("3.1", destinationProject.exists()); - assertTrue("3.2", destinationProject.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(destinationProject).matches(IResource::exists, "exists"); + assertThat(destinationProject).matches(isSynchronizedDepthInfinite, "is synchronized"); // resources have been copied to destination - assertTrue("3.4", destinationProject.getFile(file1.getProjectRelativePath()).exists()); + assertThat(destinationProject.getFile(file1.getProjectRelativePath())).matches(IResource::exists, "exists"); // ensure marker info has not been lost IMarker marker = destinationProject.getFile(file1.getProjectRelativePath()).findMarker(markerId); - assertNotNull("3.6", marker); - assertEquals("3.7", attributeValue, marker.getAttribute(attributeKey)); + assertNotNull(marker); + assertEquals(attributeValue, marker.getAttribute(attributeKey)); // project's content area still exists in file system - assertTrue("4.0", projectStore.fetchInfo().exists()); + assertThat(projectStore).matches(it -> it.fetchInfo().exists(), "exists"); - assertTrue("5.0", workspace.getRoot().isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(workspace.getRoot()).matches(isSynchronizedDepthInfinite, "is synchronized"); } finally { setReadOnly(projectParentStore, false); } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_044106.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_044106.java index 9b208919ee2..1e2fcea714e 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_044106.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_044106.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.assertDoesNotExistInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInFileSystem; @@ -21,10 +22,10 @@ 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.assertTrue; import static org.junit.Assume.assumeTrue; import java.io.IOException; +import java.util.function.Predicate; import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -45,6 +46,8 @@ */ public class Bug_044106 { + private static final Predicate exists = store -> store.fetchInfo().exists(); + @Rule public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); @@ -61,7 +64,7 @@ private void doTestDeleteLinkedFile(int deleteFlags) throws Exception { // create the file/folder that we are going to link to IFileStore linkDestFile = workspaceRule.getTempStore(); createInFileSystem(linkDestFile); - assertTrue("0.1", linkDestFile.fetchInfo().exists()); + assertThat(linkDestFile).matches(exists, "exists"); // create some resources in the workspace IProject project = getWorkspace().getRoot().getProject(createUniqueString()); @@ -83,7 +86,7 @@ private void doTestDeleteLinkedFile(int deleteFlags) throws Exception { // ensure that the folder and file weren't deleted in the filesystem assertDoesNotExistInWorkspace(linkedFile); - assertTrue("4.1", linkDestFile.fetchInfo().exists()); + assertThat(linkDestFile).matches(exists, "exists"); } /** @@ -99,8 +102,8 @@ private void doTestDeleteLinkedFolder(IFolder linkedFolder, boolean deleteParent IFileStore linkDestLocation = workspaceRule.getTempStore(); IFileStore linkDestFile = linkDestLocation.getChild(createUniqueString()); createInFileSystem(linkDestFile); - assertTrue("0.1", linkDestLocation.fetchInfo().exists()); - assertTrue("0.2", linkDestFile.fetchInfo().exists()); + assertThat(linkDestLocation).matches(exists, "exists"); + assertThat(linkDestFile).matches(exists, "exists"); // create some resources in the workspace createInWorkspace(linkedFolder.getParent()); @@ -128,8 +131,8 @@ private void doTestDeleteLinkedFolder(IFolder linkedFolder, boolean deleteParent // ensure that the folder and file weren't deleted in the filesystem assertDoesNotExistInWorkspace(linkedFolder); assertDoesNotExistInWorkspace(linkedFile); - assertTrue("4.2", linkDestLocation.fetchInfo().exists()); - assertTrue("4.3", linkDestFile.fetchInfo().exists()); + assertThat(linkDestLocation).matches(exists, "exists"); + assertThat(linkDestFile).matches(exists, "exists"); } @Test diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_092108.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_092108.java index bd1428975e0..b65d0ec276d 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_092108.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_092108.java @@ -13,7 +13,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assume.assumeTrue; import org.eclipse.core.filesystem.EFS; @@ -39,8 +39,8 @@ public void testBug() throws CoreException { IFileStore root = EFS.getStore(new java.io.File("c:\\").toURI()); IFileInfo info = root.fetchInfo(); - assertTrue("1.0", info.exists()); - assertTrue("1.1", info.isDirectory()); + assertThat(info).matches(IFileInfo::exists, "exists"); + assertThat(info).matches(IFileInfo::isDirectory, "is directory"); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_126104.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_126104.java index bb27bd0a2aa..1a119076a5a 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_126104.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_126104.java @@ -13,11 +13,12 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; +import static java.util.function.Predicate.not; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromWorkspace; -import static org.junit.Assert.assertTrue; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; @@ -48,14 +49,14 @@ public void testBug() throws CoreException { link.createLink(location.toURI(), IResource.ALLOW_MISSING_LOCAL, createTestMonitor()); IFile destination = link.getFile(source.getName()); source.copy(destination.getFullPath(), IResource.NONE, createTestMonitor()); - assertTrue("1.0", destination.exists()); + assertThat(destination).matches(IResource::exists, "exists"); //try the same thing with move removeFromWorkspace(destination); location.delete(EFS.NONE, createTestMonitor()); source.move(destination.getFullPath(), IResource.NONE, createTestMonitor()); - assertTrue("3.0", !source.exists()); - assertTrue("3.1", destination.exists()); + assertThat(source).matches(not(IResource::exists), "not exists"); + assertThat(destination).matches(IResource::exists, "exists"); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_147232.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_147232.java index 1fa9829d9b8..8a68fbd9f1d 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_147232.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_147232.java @@ -90,7 +90,7 @@ public void testBug() throws CoreException { //create a file in the project to trigger a build createInWorkspace(file); waitForBuild(); - assertEquals("2.0", 1, deltaSeenCount); + assertEquals(1, deltaSeenCount); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_160251.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_160251.java index 7630af00b4d..9ab5da995c2 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_160251.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_160251.java @@ -13,13 +13,16 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; +import static org.assertj.core.api.Assertions.assertThat; 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.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; +import java.util.function.Predicate; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.filesystem.URIUtil; @@ -39,6 +42,9 @@ */ public class Bug_160251 { + private static final Predicate isSynchronizedDepthInfinite = resource -> resource + .isSynchronized(IResource.DEPTH_INFINITE); + @Rule public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); @@ -60,11 +66,11 @@ public void testNonExistentDestination() throws CoreException { source.move(description, IResource.NONE, createTestMonitor()); //ensure project still exists - assertTrue("2.0", source.exists()); - assertTrue("2.1", sourceFile.exists()); - assertTrue("2.2", source.isSynchronized(IResource.DEPTH_INFINITE)); - assertTrue("2.3", URIUtil.equals(source.getLocationURI(), destination.toURI())); - assertTrue("2.4", URIUtil.equals(sourceFile.getLocationURI(), destinationFile.toURI())); + assertThat(source).matches(IResource::exists, "exists"); + assertThat(sourceFile).matches(IResource::exists, "exists"); + assertThat(source).matches(isSynchronizedDepthInfinite, "is synchronized"); + assertTrue(URIUtil.equals(source.getLocationURI(), destination.toURI())); + assertTrue(URIUtil.equals(sourceFile.getLocationURI(), destinationFile.toURI())); } /** @@ -86,11 +92,11 @@ public void testEmptyDestination() throws CoreException { source.move(description, IResource.NONE, createTestMonitor()); //ensure project still exists - assertTrue("2.0", source.exists()); - assertTrue("2.1", sourceFile.exists()); - assertTrue("2.2", source.isSynchronized(IResource.DEPTH_INFINITE)); - assertTrue("2.3", URIUtil.equals(source.getLocationURI(), destination.toURI())); - assertTrue("2.4", URIUtil.equals(sourceFile.getLocationURI(), destinationFile.toURI())); + assertThat(source).matches(IResource::exists, "exists"); + assertThat(sourceFile).matches(IResource::exists, "exists"); + assertThat(source).matches(isSynchronizedDepthInfinite, "is synchronized"); + assertTrue(URIUtil.equals(source.getLocationURI(), destination.toURI())); + assertTrue(URIUtil.equals(sourceFile.getLocationURI(), destinationFile.toURI())); } /** @@ -113,11 +119,11 @@ public void testOccupiedDestination() throws Exception { assertThrows(CoreException.class, () -> source.move(description, IResource.NONE, createTestMonitor())); //ensure project still exists in old location - assertTrue("2.0", source.exists()); - assertTrue("2.1", sourceFile.exists()); - assertTrue("2.2", source.isSynchronized(IResource.DEPTH_INFINITE)); - assertTrue("2.3", !URIUtil.equals(source.getLocationURI(), destination.toURI())); - assertTrue("2.4", !URIUtil.equals(sourceFile.getLocationURI(), destinationFile.toURI())); + assertThat(source).matches(IResource::exists, "exists"); + assertThat(sourceFile).matches(IResource::exists, "exists"); + assertThat(source).matches(isSynchronizedDepthInfinite, "is synchronized"); + assertFalse(URIUtil.equals(source.getLocationURI(), destination.toURI())); + assertFalse(URIUtil.equals(sourceFile.getLocationURI(), destinationFile.toURI())); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_165892.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_165892.java index 521f9e42926..a779d0c76e6 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_165892.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_165892.java @@ -61,16 +61,16 @@ public void testCopyFile() throws CoreException { sourceFile.copy(destinationFile.getFullPath(), IResource.NONE, createTestMonitor()); //make sure the persistent properties were copied - assertEquals("2.0", sourceValue, sourceFile.getPersistentProperty(name)); - assertEquals("2.1", sourceValue, destinationFile.getPersistentProperty(name)); + assertEquals(sourceValue, sourceFile.getPersistentProperty(name)); + assertEquals(sourceValue, destinationFile.getPersistentProperty(name)); //change the values of the persistent property on the copied resource final String destinationValue = "DestinationValue"; destinationFile.setPersistentProperty(name, destinationValue); //make sure the persistent property values are correct - assertEquals("3.0", sourceValue, sourceFile.getPersistentProperty(name)); - assertEquals("3.1", destinationValue, destinationFile.getPersistentProperty(name)); + assertEquals(sourceValue, sourceFile.getPersistentProperty(name)); + assertEquals(destinationValue, destinationFile.getPersistentProperty(name)); } /** @@ -127,11 +127,11 @@ public void testCopyFolder() throws CoreException { sourceFolder.copy(destinationFolder.getFullPath(), IResource.NONE, createTestMonitor()); //make sure the persistent properties were copied - assertEquals("2.0", sourceValue, source.getPersistentProperty(name)); - assertEquals("2.1", sourceValue, sourceFolder.getPersistentProperty(name)); - assertEquals("2.2", sourceValue, sourceFile.getPersistentProperty(name)); - assertEquals("2.3", sourceValue, destinationFolder.getPersistentProperty(name)); - assertEquals("2.4", sourceValue, destinationFile.getPersistentProperty(name)); + assertEquals(sourceValue, source.getPersistentProperty(name)); + assertEquals(sourceValue, sourceFolder.getPersistentProperty(name)); + assertEquals(sourceValue, sourceFile.getPersistentProperty(name)); + assertEquals(sourceValue, destinationFolder.getPersistentProperty(name)); + assertEquals(sourceValue, destinationFile.getPersistentProperty(name)); //change the values of the persistent property on the copied resource final String destinationValue = "DestinationValue"; @@ -139,11 +139,11 @@ public void testCopyFolder() throws CoreException { destinationFile.setPersistentProperty(name, destinationValue); //make sure the persistent property values are correct - assertEquals("3.0", sourceValue, source.getPersistentProperty(name)); - assertEquals("3.1", sourceValue, sourceFolder.getPersistentProperty(name)); - assertEquals("3.2", sourceValue, sourceFile.getPersistentProperty(name)); - assertEquals("3.3", destinationValue, destinationFolder.getPersistentProperty(name)); - assertEquals("3.4", destinationValue, destinationFile.getPersistentProperty(name)); + assertEquals(sourceValue, source.getPersistentProperty(name)); + assertEquals(sourceValue, sourceFolder.getPersistentProperty(name)); + assertEquals(sourceValue, sourceFile.getPersistentProperty(name)); + assertEquals(destinationValue, destinationFolder.getPersistentProperty(name)); + assertEquals(destinationValue, destinationFile.getPersistentProperty(name)); } /** @@ -170,12 +170,12 @@ public void testCopyProject() throws CoreException { source.copy(destination.getFullPath(), IResource.NONE, createTestMonitor()); //make sure the persistent properties were copied - assertEquals("2.0", sourceValue, source.getPersistentProperty(name)); - assertEquals("2.1", sourceValue, sourceFolder.getPersistentProperty(name)); - assertEquals("2.2", sourceValue, sourceFile.getPersistentProperty(name)); - assertEquals("2.3", sourceValue, destination.getPersistentProperty(name)); - assertEquals("2.4", sourceValue, destinationFolder.getPersistentProperty(name)); - assertEquals("2.5", sourceValue, destinationFile.getPersistentProperty(name)); + assertEquals(sourceValue, source.getPersistentProperty(name)); + assertEquals(sourceValue, sourceFolder.getPersistentProperty(name)); + assertEquals(sourceValue, sourceFile.getPersistentProperty(name)); + assertEquals(sourceValue, destination.getPersistentProperty(name)); + assertEquals(sourceValue, destinationFolder.getPersistentProperty(name)); + assertEquals(sourceValue, destinationFile.getPersistentProperty(name)); //change the values of the persistent property on the copied resource final String destinationValue = "DestinationValue"; @@ -184,11 +184,11 @@ public void testCopyProject() throws CoreException { destinationFile.setPersistentProperty(name, destinationValue); //make sure the persistent property values are correct - assertEquals("3.0", sourceValue, source.getPersistentProperty(name)); - assertEquals("3.1", sourceValue, sourceFolder.getPersistentProperty(name)); - assertEquals("3.2", sourceValue, sourceFile.getPersistentProperty(name)); - assertEquals("3.3", destinationValue, destination.getPersistentProperty(name)); - assertEquals("3.4", destinationValue, destinationFolder.getPersistentProperty(name)); - assertEquals("3.5", destinationValue, destinationFile.getPersistentProperty(name)); + assertEquals(sourceValue, source.getPersistentProperty(name)); + assertEquals(sourceValue, sourceFolder.getPersistentProperty(name)); + assertEquals(sourceValue, sourceFile.getPersistentProperty(name)); + assertEquals(destinationValue, destination.getPersistentProperty(name)); + assertEquals(destinationValue, destinationFolder.getPersistentProperty(name)); + assertEquals(destinationValue, destinationFile.getPersistentProperty(name)); } } \ No newline at end of file diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_192631.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_192631.java index 6b2b5afec5e..bb581689cf8 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_192631.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_192631.java @@ -13,10 +13,10 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import java.net.URI; import java.net.URISyntaxException; @@ -101,14 +101,14 @@ public void testCompareHost() throws CoreException, URISyntaxException { toVisit.addAll(Arrays.asList(new URI[] {projectA.getLocationURI(), commonA, folderA, projectA.getFile(".project").getLocationURI()})); toVisitCount[0] = 6; projectA.accept(visitor); - assertTrue("1.1", toVisit.isEmpty()); - assertEquals("1.2", 0, toVisitCount[0]); + assertThat(toVisit).isEmpty(); + assertEquals(0, toVisitCount[0]); toVisit.addAll(Arrays.asList(new URI[] {projectB.getLocationURI(), commonB, folderB, projectB.getFile(".project").getLocationURI()})); toVisitCount[0] = 6; projectB.accept(visitor); - assertTrue("2.1", toVisit.isEmpty()); - assertEquals("2.2", 0, toVisitCount[0]); + assertThat(toVisit).isEmpty(); + assertEquals(0, toVisitCount[0]); projectA.delete(true, createTestMonitor()); projectB.delete(true, createTestMonitor()); @@ -147,14 +147,14 @@ public void testCompareUserInfo() throws CoreException, URISyntaxException { toVisit.addAll(Arrays.asList(new URI[] {projectA.getLocationURI(), commonA, folderA, projectA.getFile(".project").getLocationURI()})); toVisitCount[0] = 6; projectA.accept(visitor); - assertTrue("1.1", toVisit.isEmpty()); - assertEquals("1.2", 0, toVisitCount[0]); + assertThat(toVisit).isEmpty(); + assertEquals(0, toVisitCount[0]); toVisit.addAll(Arrays.asList(new URI[] {projectB.getLocationURI(), commonB, folderB, projectB.getFile(".project").getLocationURI()})); toVisitCount[0] = 6; projectB.accept(visitor); - assertTrue("2.1", toVisit.isEmpty()); - assertEquals("2.2", 0, toVisitCount[0]); + assertThat(toVisit).isEmpty(); + assertEquals(0, toVisitCount[0]); projectA.delete(true, createTestMonitor()); projectB.delete(true, createTestMonitor()); @@ -193,14 +193,14 @@ public void testComparePort() throws CoreException, URISyntaxException { toVisit.addAll(Arrays.asList(new URI[] {projectA.getLocationURI(), commonA, folderA, projectA.getFile(".project").getLocationURI()})); toVisitCount[0] = 6; projectA.accept(visitor); - assertTrue("1.1", toVisit.isEmpty()); - assertEquals("1.2", 0, toVisitCount[0]); + assertThat(toVisit).isEmpty(); + assertEquals(0, toVisitCount[0]); toVisit.addAll(Arrays.asList(new URI[] {projectB.getLocationURI(), commonB, folderB, projectB.getFile(".project").getLocationURI()})); toVisitCount[0] = 6; projectB.accept(visitor); - assertTrue("2.1", toVisit.isEmpty()); - assertEquals("2.2", 0, toVisitCount[0]); + assertThat(toVisit).isEmpty(); + assertEquals(0, toVisitCount[0]); projectA.delete(true, createTestMonitor()); projectB.delete(true, createTestMonitor()); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_226264.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_226264.java index 60c9b178e91..be5c1f03d37 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_226264.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_226264.java @@ -13,8 +13,8 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.tests.resources.ResourceTestUtil.assertDoesNotExistInWorkspace; -import static org.junit.Assert.assertTrue; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResourceChangeEvent; @@ -78,7 +78,7 @@ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { workspace.removeResourceChangeListener(projectDeletingChangeListener); } - assertTrue("2.0: " + job.getResult(), job.getResult().isOK()); + assertThat(job.getResult()).matches(IStatus::isOK, "is okay"); assertDoesNotExistInWorkspace(project1); assertDoesNotExistInWorkspace(project2); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_231301.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_231301.java index 842ab759f7f..0881c109780 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_231301.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_231301.java @@ -13,9 +13,10 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; -import static org.junit.Assert.assertTrue; +import java.util.function.Predicate; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResourceChangeEvent; import org.eclipse.core.resources.IResourceChangeListener; @@ -78,9 +79,9 @@ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { workspace.removeResourceChangeListener(projectClosingChangeListener); } - assertTrue("2.0: " + job.getResult(), job.getResult().isOK()); - assertTrue("3.0", !project1.isOpen()); - assertTrue("4.0", !project2.isOpen()); + assertThat(job.getResult().isOK()).withFailMessage(job.getResult().toString()).isTrue(); + assertThat(project1).matches(Predicate.not(IProject::isOpen), "is not open"); + assertThat(project2).matches(Predicate.not(IProject::isOpen), "is not open"); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_233939.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_233939.java index 0c910221a91..0be2ede790f 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_233939.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_233939.java @@ -22,7 +22,6 @@ 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.assertTrue; import static org.junit.Assume.assumeTrue; import java.io.IOException; @@ -63,7 +62,7 @@ protected void symLinkAndRefresh(IContainer container, String linkName, IPath li container.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); IResource theLink = container.findMember(linkName); assertExistsInWorkspace(theLink); - assertTrue(theLink.getResourceAttributes().isSymbolicLink()); + assertThat(theLink).matches(it -> it.getResourceAttributes().isSymbolicLink(), "is symbolic link"); } /** diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_265810.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_265810.java index 303bda544d7..ff5cc5ed2fe 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_265810.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_265810.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.harness.FileSystemHelper.getRandomLocation; import static org.eclipse.core.tests.resources.ResourceTestUtil.assertDoesNotExistInWorkspace; @@ -108,9 +109,9 @@ public void testBug() throws Throwable { // restore .project [1] restoreDotProject(project, dotProject1); - assertEquals("9.0", 1, resourceDeltas.size()); - assertEquals("9.1", newFile, resourceDeltas.get(0).getResource()); - assertEquals("9.2", IResourceDelta.REMOVED, resourceDeltas.get(0).getKind()); + assertThat(resourceDeltas).hasSize(1); + assertEquals(newFile, resourceDeltas.get(0).getResource()); + assertEquals(IResourceDelta.REMOVED, resourceDeltas.get(0).getKind()); } finally { getWorkspace().removeResourceChangeListener(listener); } @@ -127,9 +128,9 @@ public void testBug() throws Throwable { // restore .project [2] restoreDotProject(project, dotProject2); - assertEquals("11.0", 1, resourceDeltas.size()); - assertEquals("11.1", newFile, resourceDeltas.get(0).getResource()); - assertEquals("11.2", IResourceDelta.REPLACED, resourceDeltas.get(0).getFlags() & IResourceDelta.REPLACED); + assertThat(resourceDeltas).hasSize(1); + assertEquals(newFile, resourceDeltas.get(0).getResource()); + assertEquals(IResourceDelta.REPLACED, resourceDeltas.get(0).getFlags() & IResourceDelta.REPLACED); } finally { getWorkspace().removeResourceChangeListener(listener); } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_303517.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_303517.java index ec71d556193..df4c2cdb968 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_303517.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_303517.java @@ -14,18 +14,19 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; +import static java.util.function.Predicate.not; +import static org.assertj.core.api.Assertions.assertThat; 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.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import static org.eclipse.core.tests.resources.ResourceTestUtil.touchInFilesystem; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; import java.io.File; import java.io.InputStream; +import java.util.function.Predicate; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceStatus; @@ -50,6 +51,12 @@ public class Bug_303517 { @Rule public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); + private static final Predicate isSynchronizedDepthInfinite = resource -> resource + .isSynchronized(IResource.DEPTH_INFINITE); + + private static final Predicate isSynchronizedDepthOne = resource -> resource + .isSynchronized(IResource.DEPTH_ONE); + private final String[] resourcePaths = new String[] { "/", "/Bug303517/", "/Bug303517/Folder/", "/Bug303517/Folder/Resource", }; private boolean originalRefreshSetting; @@ -77,13 +84,13 @@ public void tearDown() throws Exception { @Test public void testExists() throws Exception { IFile f = getWorkspace().getRoot().getFile(IPath.fromOSString(resourcePaths[resourcePaths.length - 1])); - assertTrue("1.0", f.exists()); - assertTrue("1.1", f.isSynchronized(IResource.DEPTH_ONE)); + assertThat(f).matches(IResource::exists, "exists"); + assertThat(f).matches(isSynchronizedDepthOne, "is synchronized"); // Touch on file-system f.getLocation().toFile().delete(); // Core.resources still thinks the file exists - assertTrue("1.2", f.exists()); + assertThat(f).matches(IResource::exists, "exists"); assertThrows(CoreException.class, () -> { try(InputStream in = f.getContents()) {} }); @@ -93,7 +100,7 @@ public void testExists() throws Exception { Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, createTestMonitor()); // Core.resources should be aware that the file no longer exists... - assertFalse("1.4", f.exists()); + assertThat(f).matches(not(IResource::exists), "not exists"); } /** @@ -102,8 +109,8 @@ public void testExists() throws Exception { @Test public void testGetContents() throws Exception { IFile f = getWorkspace().getRoot().getFile(IPath.fromOSString(resourcePaths[resourcePaths.length - 1])); - assertTrue("1.0", f.exists()); - assertTrue("1.1", f.isSynchronized(IResource.DEPTH_ONE)); + assertThat(f).matches(IResource::exists, "exists"); + assertThat(f).matches(isSynchronizedDepthOne, "is synchronized"); // Touch on file-system touchInFilesystem(f); @@ -112,7 +119,7 @@ public void testGetContents() throws Exception { } }); // File is out-of-sync, so this is good. - assertEquals("2.1", IResourceStatus.OUT_OF_SYNC_LOCAL, exception.getStatus().getCode()); + assertEquals(IResourceStatus.OUT_OF_SYNC_LOCAL, exception.getStatus().getCode()); // Wait for auto-refresh to happen Job.getJobManager().wakeUp(ResourcesPlugin.FAMILY_AUTO_REFRESH); @@ -129,8 +136,8 @@ public void testGetContents() throws Exception { @Test public void testGetContentsTrue() throws Exception { IFile f = getWorkspace().getRoot().getFile(IPath.fromOSString(resourcePaths[resourcePaths.length - 1])); - assertTrue("1.0", f.exists()); - assertTrue("1.1", f.isSynchronized(IResource.DEPTH_ONE)); + assertThat(f).matches(IResource::exists, "exists"); + assertThat(f).matches(isSynchronizedDepthOne, "is synchronized"); // Touch on file-system touchInFilesystem(f); @@ -150,7 +157,7 @@ public void testGetContentsTrue() throws Exception { try (InputStream in = f.getContents(true)) { } }); - assertEquals("2.1", IResourceStatus.RESOURCE_NOT_FOUND, exception.getStatus().getCode()); + assertEquals(IResourceStatus.RESOURCE_NOT_FOUND, exception.getStatus().getCode()); } /** @@ -159,19 +166,19 @@ public void testGetContentsTrue() throws Exception { @Test public void testIsSynchronized() throws Exception { IFile f = getWorkspace().getRoot().getFile(IPath.fromOSString(resourcePaths[resourcePaths.length - 1])); - assertTrue("1.0", f.exists()); - assertTrue("1.1", f.isSynchronized(IResource.DEPTH_ONE)); + assertThat(f).matches(IResource::exists, "exists"); + assertThat(f).matches(isSynchronizedDepthOne, "is synchronized"); // Touch on file-system touchInFilesystem(f); - assertFalse("1.2", f.isSynchronized(IResource.DEPTH_ONE)); + assertThat(f).matches(not(isSynchronizedDepthOne), "is not synchronized"); // Wait for auto-refresh to happen Job.getJobManager().wakeUp(ResourcesPlugin.FAMILY_AUTO_REFRESH); Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, createTestMonitor()); // File is now in sync. - assertTrue("1.3", f.isSynchronized(IResource.DEPTH_ONE)); + assertThat(f).matches(isSynchronizedDepthOne, "is synchronized"); } /** @@ -180,31 +187,31 @@ public void testIsSynchronized() throws Exception { @Test public void testChangeResourceGender() throws Exception { IResource f = getWorkspace().getRoot().getFile(IPath.fromOSString(resourcePaths[resourcePaths.length - 1])); - assertTrue("1.0", f.exists()); - assertTrue("1.1", f.isSynchronized(IResource.DEPTH_ONE)); + assertThat(f).matches(IResource::exists, "exists"); + assertThat(f).matches(isSynchronizedDepthOne, "is synchronized"); // Replace the file with a folder File osResource = f.getLocation().toFile(); osResource.delete(); osResource.mkdir(); - assertTrue(osResource.exists()); + assertThat(osResource).matches(File::exists, "exists"); File osChild = new File(osResource, "child"); osChild.createNewFile(); - assertTrue(osChild.exists()); + assertThat(osChild).matches(File::exists, "exists"); - assertFalse("1.2", f.isSynchronized(IResource.DEPTH_ONE)); + assertThat(f).matches(not(isSynchronizedDepthOne), "is not synchronized"); // Wait for auto-refresh to happen Job.getJobManager().wakeUp(ResourcesPlugin.FAMILY_AUTO_REFRESH); Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, createTestMonitor()); // File is no longer a file - i.e. still out-of-sync - assertFalse("1.3", f.exists()); - assertFalse("1.4", f.isSynchronized(IResource.DEPTH_ONE)); + assertThat(f).matches(not(IResource::exists), "not exists"); + assertThat(f).matches(not(isSynchronizedDepthOne), "is not synchronized"); // Folder + child are now in-sync f = getWorkspace().getRoot().getFolder(IPath.fromOSString(resourcePaths[resourcePaths.length - 1])); - assertTrue("1.5", f.exists()); - assertTrue("1.6", f.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(f).matches(IResource::exists, "exists"); + assertThat(f).matches(isSynchronizedDepthInfinite, "is synchronized"); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_329836.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_329836.java index ae43727b18d..a3ed7d4f892 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_329836.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_329836.java @@ -14,12 +14,11 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; +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.createTestMonitor; import static org.eclipse.core.tests.resources.ResourceTestUtil.createUniqueString; import static org.eclipse.core.tests.resources.ResourceTestUtil.isAttributeSupported; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import org.eclipse.core.filesystem.EFS; @@ -54,9 +53,9 @@ public void testBug() throws Exception { info = fileStore.fetchInfo(); // check that attributes are really set - assertTrue("2.0", info.getAttribute(EFS.ATTRIBUTE_READ_ONLY)); + assertThat(info).matches(it -> it.getAttribute(EFS.ATTRIBUTE_READ_ONLY), "is read only"); if (isAttributeSupported(EFS.ATTRIBUTE_IMMUTABLE)) { - assertTrue("3.0", info.getAttribute(EFS.ATTRIBUTE_IMMUTABLE)); + assertThat(info).matches(it -> it.getAttribute(EFS.ATTRIBUTE_IMMUTABLE), "is immutable"); } // unset EFS.ATTRIBUTE_READ_ONLY which also unsets EFS.IMMUTABLE on Mac @@ -68,9 +67,9 @@ public void testBug() throws Exception { info = fileStore.fetchInfo(); // check that attributes are really unset - assertFalse("5.0", info.getAttribute(EFS.ATTRIBUTE_READ_ONLY)); + assertThat(info).matches(it -> !it.getAttribute(EFS.ATTRIBUTE_READ_ONLY), "is not read only"); if (isAttributeSupported(EFS.ATTRIBUTE_IMMUTABLE)) { - assertFalse("6.0", info.getAttribute(EFS.ATTRIBUTE_IMMUTABLE)); + assertThat(info).matches(it -> !it.getAttribute(EFS.ATTRIBUTE_IMMUTABLE), "is not immutable"); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_331445.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_331445.java index 041482de692..6b00520fa27 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_331445.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_331445.java @@ -53,10 +53,10 @@ public void testBug() throws CoreException, URISyntaxException { project.getPathVariableManager().setURIValue(variableName, new URI(variablePath)); IFolder folder = project.getFolder(createUniqueString()); folder.createLink(IPath.fromOSString(rawLinkFolderLocation), IResource.ALLOW_MISSING_LOCAL, createTestMonitor()); - assertNull("3.0", folder.getLocation()); - assertEquals("4.0", IPath.fromOSString(rawLinkFolderLocation), folder.getRawLocation()); - assertEquals("5.0", new URI(linkFolderLocation), folder.getLocationURI()); - assertEquals("6.0", new URI(rawLinkFolderLocation), folder.getRawLocationURI()); + assertNull(folder.getLocation()); + assertEquals(IPath.fromOSString(rawLinkFolderLocation), folder.getRawLocation()); + assertEquals(new URI(linkFolderLocation), folder.getLocationURI()); + assertEquals(new URI(rawLinkFolderLocation), folder.getRawLocationURI()); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_378156.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_378156.java index 66cc6945c9b..578d559a4b2 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_378156.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_378156.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; @@ -20,7 +21,6 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomString; import static org.eclipse.core.tests.resources.ResourceTestUtil.updateProjectDescription; import static org.eclipse.core.tests.resources.ResourceTestUtil.waitForBuild; -import static org.junit.Assert.assertTrue; import java.util.concurrent.Semaphore; import org.eclipse.core.resources.IFile; @@ -123,7 +123,7 @@ public void testBugTwoThreads() throws Exception { waitForBuild(); //the builder should have run if the bug is fixed - assertTrue("1.0", builder.wasExecuted()); + assertThat(builder).matches(SignaledBuilder::wasExecuted, "was executed"); } @Test @@ -156,7 +156,7 @@ public void testBugOneThread() throws Exception { }, null); waitForBuild(); //the builder should have run if the bug is fixed - assertTrue("1.0", builder.wasExecuted()); + assertThat(builder).matches(SignaledBuilder::wasExecuted, "was executed"); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_380386.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_380386.java index 73003f0cf17..36373b936c5 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_380386.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_380386.java @@ -58,11 +58,11 @@ public void testBug() throws Exception { } } - assertNotNull("1.0", statusName); - assertNotNull("2.0", statusValue); + assertNotNull(statusName); + assertNotNull(statusValue); - assertTrue("3.0", statusName.isOK()); - assertNotNull("4.0", statusValue.isOK()); + assertTrue(statusName.isOK()); + assertNotNull(statusValue.isOK()); pathManager.setURIValue(name, value); } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFileTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFileTest.java index 787d7f1e5d2..f75eb601202 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFileTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFileTest.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomContentsStream; @@ -20,7 +21,6 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.isReadOnlySupported; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; @@ -64,7 +64,7 @@ public void testBug25658() throws CoreException { try { folder.setReadOnly(true); - assertTrue(folder.isReadOnly()); + assertThat(folder).matches(IResource::isReadOnly, "is read only"); CoreException exception = assertThrows(CoreException.class, () -> file.create(createRandomContentsStream(), true, createTestMonitor())); assertEquals(IResourceStatus.FAILED_WRITE_LOCAL, exception.getStatus().getCode()); @@ -96,7 +96,7 @@ public void testBug25662() throws CoreException { try { folder.setReadOnly(true); - assertTrue(folder.isReadOnly()); + assertThat(folder).matches(IResource::isReadOnly, "is read only"); CoreException exception = assertThrows(CoreException.class, () -> file.create(createRandomContentsStream(), true, createTestMonitor())); assertEquals(IResourceStatus.PARENT_READ_ONLY, exception.getStatus().getCode()); @@ -113,7 +113,7 @@ public void testBug43936() throws CoreException { IProject project = getWorkspace().getRoot().getProject("MyProject"); IFile descFile = project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME); createInWorkspace(project); - assertTrue("1.0", descFile.exists()); + assertThat(descFile).matches(IResource::exists, "exists"); IProjectDescription desc = project.getDescription(); @@ -121,7 +121,7 @@ public void testBug43936() throws CoreException { long newTime = System.currentTimeMillis() + 10000; descFile.setLocalTimeStamp(newTime); - assertTrue("2.0", descFile.isSynchronized(IResource.DEPTH_ZERO)); + assertThat(descFile).matches(it -> it.isSynchronized(IResource.DEPTH_ZERO), "is synchronized"); // try setting the description -- shouldn't fail project.setDescription(desc, createTestMonitor()); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFolderTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFolderTest.java index 79e0d1d71cb..d9e37be6d53 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFolderTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFolderTest.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; +import static java.util.function.Predicate.not; +import static org.assertj.core.api.Assertions.assertThat; 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; @@ -20,9 +22,9 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.isReadOnlySupported; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; +import java.util.function.Predicate; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.resources.IFile; @@ -64,7 +66,7 @@ public void testBug25662() throws CoreException { try { parentFolder.setReadOnly(true); - assertTrue(parentFolder.isReadOnly()); + assertThat(parentFolder).matches(IResource::isReadOnly, "is read only"); CoreException exception = assertThrows(CoreException.class, () -> folder.create(true, true, createTestMonitor())); assertEquals(IResourceStatus.PARENT_READ_ONLY, exception.getStatus().getCode()); } finally { @@ -87,29 +89,30 @@ public void testBug11510() throws Exception { file.create(null, true, createTestMonitor()); subFile.create(null, true, createTestMonitor()); - assertTrue("1.0", !folder.isLocal(IResource.DEPTH_ZERO)); - assertTrue("1.1", !file.isLocal(IResource.DEPTH_ZERO)); - assertTrue("1.1", !subFile.isLocal(IResource.DEPTH_ZERO)); + Predicate isLocal = resource -> resource.isLocal(IResource.DEPTH_ZERO); + + assertThat(folder).matches(not(isLocal), "not is local"); + assertThat(file).matches(not(isLocal), "not is local"); + assertThat(subFile).matches(not(isLocal), "not is local"); // now create the resources in the local file system and refresh createInFileSystem(file); project.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); - assertTrue("2.1", file.isLocal(IResource.DEPTH_ZERO)); - assertTrue("2.2", !folder.isLocal(IResource.DEPTH_ZERO)); - assertTrue("2.3", !subFile.isLocal(IResource.DEPTH_ZERO)); + assertThat(file).matches(isLocal, "is local"); + assertThat(folder).matches(not(isLocal), "not is local"); + assertThat(subFile).matches(not(isLocal), "not is local"); folder.getLocation().toFile().mkdir(); project.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); - assertTrue("3.1", folder.isLocal(IResource.DEPTH_ZERO)); - assertTrue("3.2", file.isLocal(IResource.DEPTH_ZERO)); - assertTrue("3.3", !subFile.isLocal(IResource.DEPTH_ZERO)); + assertThat(folder).matches(isLocal, "is local"); + assertThat(file).matches(isLocal, "is local"); + assertThat(subFile).matches(not(isLocal), "not is local"); createInFileSystem(subFile); project.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); - assertTrue("4.1", subFile.isLocal(IResource.DEPTH_ZERO)); - assertTrue("4.2", folder.isLocal(IResource.DEPTH_ZERO)); - assertTrue("4.3", file.isLocal(IResource.DEPTH_ZERO)); - + assertThat(folder).matches(isLocal, "is local"); + assertThat(file).matches(isLocal, "is local"); + assertThat(subFile).matches(isLocal, "is local"); } /** @@ -125,7 +128,7 @@ public void testBug514831() throws CoreException { createInWorkspace(new IResource[] {folder}); IFileStore dir = EFS.getLocalFileSystem().fromLocalFile(folder.getLocation().toFile()); - assertTrue(dir.fetchInfo().exists()); + assertThat(dir).matches(it -> it.fetchInfo().exists(), "exists"); dir.mkdir(EFS.NONE, null); dir.mkdir(EFS.SHALLOW, null); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IProjectTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IProjectTest.java index 397f0b8a8a5..5888ea0f0db 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IProjectTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IProjectTest.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; +import static java.util.function.Predicate.not; +import static org.assertj.core.api.Assertions.assertThat; 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.createInFileSystem; @@ -22,7 +24,6 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.touchInFilesystem; import static org.eclipse.core.tests.resources.ResourceTestUtil.waitForBuild; import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; import org.eclipse.core.resources.ICommand; import org.eclipse.core.resources.IFile; @@ -126,23 +127,23 @@ public void testAutoBuild_1GC2FKV() throws CoreException { projectTWObuilder.reset(); projectONE.build(IncrementalProjectBuilder.FULL_BUILD, null); waitForBuild(); - assertTrue("1.1", projectONEbuilder.wasExecuted()); - assertTrue("1.2", !projectTWObuilder.wasExecuted()); + assertThat(projectONEbuilder).matches(SignaledBuilder::wasExecuted, "was executed"); + assertThat(projectTWObuilder).matches(not(SignaledBuilder::wasExecuted), "was not executed"); projectONEbuilder.reset(); projectTWObuilder.reset(); projectTWO.build(IncrementalProjectBuilder.FULL_BUILD, SignaledBuilder.BUILDER_ID, null, null); waitForBuild(); - assertTrue("2.1", !projectONEbuilder.wasExecuted()); - assertTrue("2.2", projectTWObuilder.wasExecuted()); + assertThat(projectONEbuilder).matches(not(SignaledBuilder::wasExecuted), "was not executed"); + assertThat(projectTWObuilder).matches(SignaledBuilder::wasExecuted, "was executed"); projectONEbuilder.reset(); projectTWObuilder.reset(); projectTWO.touch(null); waitForBuild(); //project one won't be executed because project didn't change. - assertTrue("3.1", !projectONEbuilder.wasExecuted()); - assertTrue("3.2", projectTWObuilder.wasExecuted()); + assertThat(projectONEbuilder).matches(not(SignaledBuilder::wasExecuted), "was not executed"); + assertThat(projectTWObuilder).matches(SignaledBuilder::wasExecuted, "was executed"); } /* @@ -170,10 +171,10 @@ public void testBug78711() throws Exception { project.open(createTestMonitor()); // verify discovery - assertTrue("2.0", project.isAccessible()); - assertTrue("2.1", folder.exists()); - assertTrue("2.2", file1.exists()); - assertTrue("2.3", file2.exists()); + assertThat(project).matches(IProject::isAccessible, "is accessible"); + assertThat(folder).matches(IFolder::exists, "exists"); + assertThat(file1).matches(IFile::exists, "exists"); + assertThat(file2).matches(IFile::exists, "exists"); } /** diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IResourceTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IResourceTest.java index 02b1e4c5e26..f8b2a8140a8 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IResourceTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IResourceTest.java @@ -14,6 +14,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; +import static java.util.function.Predicate.not; import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInFileSystem; @@ -26,6 +27,8 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.isAttributeSupported; import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromWorkspace; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; @@ -98,9 +101,9 @@ public void testBug25686() throws CoreException { IFile destination = outputFolder.getFile(".project"); createInWorkspace(new IResource[] {project, outputFolder}); - assertTrue("0.0", description.exists()); + assertThat(description).matches(IFile::exists, "exists"); description.copy(destination.getFullPath(), IResource.NONE, createTestMonitor()); - assertTrue("0.1", destination.exists()); + assertThat(destination).matches(IFile::exists, "exists"); } @Test @@ -115,12 +118,12 @@ public void testBug28790() throws CoreException { ResourceAttributes attributes = file.getResourceAttributes(); attributes.setArchive(false); file.setResourceAttributes(attributes); - assertTrue("1.0", !file.getResourceAttributes().isArchive()); + assertThat(file).matches(it -> !it.getResourceAttributes().isArchive(), "is archive"); // modify the file file.setContents(createRandomContentsStream(), IResource.KEEP_HISTORY, createTestMonitor()); //now the archive bit should be set - assertTrue("2.0", file.getResourceAttributes().isArchive()); + assertThat(file).matches(it -> it.getResourceAttributes().isArchive(), "is archive"); } /** @@ -193,8 +196,8 @@ public boolean visit(IResourceDelta aDelta) { synchronizer.setSyncInfo(name, file, new byte[] { 1 }); }, null, IWorkspace.AVOID_UPDATE, createTestMonitor()); // ensure file was only seen by phantom listener - assertTrue("1.0", !seen[0]); - assertTrue("1.0", phantomSeen[0]); + assertFalse(seen[0]); + assertTrue(phantomSeen[0]); } finally { getWorkspace().removeResourceChangeListener(listener); } @@ -212,7 +215,7 @@ public void testBug83777() throws CoreException { createInWorkspace(folder); folder.setLocal(false, IResource.DEPTH_ZERO, createTestMonitor()); // non-local resource is never synchronized because it doesn't exist on disk - assertTrue("1.0", !project.isSynchronized(IResource.DEPTH_INFINITE)); + assertThat(project).matches(it -> !it.isSynchronized(IResource.DEPTH_INFINITE), "is synchronized"); } @Test @@ -269,7 +272,7 @@ public void testCreate_1FW87XF() throws Throwable { file.create(createRandomContentsStream(), true, null); // force = true - assertTrue("2.0", file.exists()); + assertThat(file).matches(IFile::exists, "exists"); IFile anotherFile = project.getFile("File"); ThrowingRunnable forcedFileCreation = () -> anotherFile.create(createRandomContentsStream(), true, null); @@ -315,18 +318,18 @@ public void testCreate_1FWYTKT() throws CoreException { sb.append('b'); IFolder folder = project.getFolder(sb.toString()); assertThrows(CoreException.class, () -> folder.create(true, true, null)); - assertTrue("2.2", !folder.exists()); + assertThat(folder).matches(not(IFolder::exists), "not exists"); IFile file = project.getFile(sb.toString()); assertThrows(CoreException.class, () -> file.create(createRandomContentsStream(), true, null)); - assertTrue("3.1", !file.exists()); + assertThat(file).matches(not(IFile::exists), "not exists"); // clean up project.delete(true, true, null); IProject finalProject = project = getWorkspace().getRoot().getProject(sb.toString()); assertThrows(CoreException.class, () -> finalProject.create(null)); - assertTrue("4.1", !finalProject.exists()); + assertThat(finalProject).matches(not(IProject::exists), "not exists"); } /** @@ -363,7 +366,7 @@ public void testDelete_1GD3ZUZ() throws CoreException { ResourceAttributes attributes = file.getResourceAttributes(); attributes.setReadOnly(true); file.setResourceAttributes(attributes); - assertTrue("2.0", file.isReadOnly()); + assertThat(file).matches(IFile::isReadOnly, "is read-only"); // doit assertThrows(CoreException.class, () -> file.delete(false, createTestMonitor())); @@ -372,7 +375,7 @@ public void testDelete_1GD3ZUZ() throws CoreException { attributes = file.getResourceAttributes(); attributes.setReadOnly(false); file.setResourceAttributes(attributes); - assertTrue("4.0", !file.isReadOnly()); + assertThat(file).matches(not(IFile::isReadOnly), "is not read-only"); removeFromWorkspace(new IResource[] {project, file}); } @@ -396,7 +399,7 @@ public void testDelete_Bug8754() throws Exception { assertThat(children).hasSize(1); status = children[0]; } - assertEquals("1.2", IResourceStatus.OUT_OF_SYNC_LOCAL, status.getCode()); + assertEquals(IResourceStatus.OUT_OF_SYNC_LOCAL, status.getCode()); //cleanup removeFromWorkspace(new IResource[] {project, file}); } @@ -405,7 +408,7 @@ public void testDelete_Bug8754() throws Exception { public void testEquals_1FUOU25() { IResource fileResource = getWorkspace().getRoot().getFile(IPath.fromOSString("a/b/c/d")); IResource folderResource = getWorkspace().getRoot().getFolder(IPath.fromOSString("a/b/c/d")); - assertTrue("1FUOU25: ITPCORE:ALL - Bug in Resource.equals()", !fileResource.equals(folderResource)); + assertNotEquals(fileResource, folderResource); } @Test @@ -416,7 +419,7 @@ public void testExists_1FUP8U6() throws CoreException { project.open(null); folder.create(true, true, null); IFile file = project.getFile("folder"); - assertTrue("2.0", !file.exists()); + assertThat(file).matches(not(IFile::exists), "not exists"); } /** @@ -437,11 +440,11 @@ public void testFindMember_1GA6QYV() throws CoreException { IPath targetPath = IPath.fromOSString("Folder2/Folder3"); IFolder target = (IFolder) folder1.findMember(targetPath); - assertTrue("3.0", folder3.equals(target)); + assertEquals(target, folder3); targetPath = IPath.fromOSString("/Folder2/Folder3"); target = (IFolder) folder1.findMember(targetPath); - assertTrue("4.0", folder3.equals(target)); + assertEquals(target, folder3); } /** @@ -471,7 +474,7 @@ public void testGetContents_1GBZD4S() throws Throwable { }); IResourceChangeListener listener = event -> { listenerInMainThreadCallback.set(() -> { - assertEquals("4.0", newContents, target.readString()); + assertEquals(newContents, target.readString()); }); }; try { @@ -487,7 +490,7 @@ public void testGetContents_1GBZD4S() throws Throwable { try (InputStream is = target.getContents(false)) { } }); - assertEquals("5.1", IResourceStatus.OUT_OF_SYNC_LOCAL, exception.getStatus().getCode()); + assertEquals(IResourceStatus.OUT_OF_SYNC_LOCAL, exception.getStatus().getCode()); try (InputStream is = target.getContents(true)) { assertThat(is).hasContent(newContents); @@ -506,9 +509,10 @@ public void testRefreshLocal_1G60AFG() throws CoreException { project.open(null); folder.create(true, true, null); file.create(createRandomContentsStream(), true, null); - assertTrue("2.0", file.exists()); + + assertThat(file).matches(IFile::exists, "exists"); folder.refreshLocal(IResource.DEPTH_ZERO, null); - assertTrue("2.2", file.exists()); + assertThat(file).matches(IFile::exists, "exists"); } /** @@ -525,7 +529,7 @@ public void testBug553269() throws Exception { project.open(null); project.setDefaultCharset(StandardCharsets.UTF_8.name(), null); - assertTrue("Preferences saved", settingsFile.exists()); + assertThat(settingsFile.exists()).withFailMessage("Preferences saved").isTrue(); project.close(null); @@ -542,7 +546,7 @@ public void testBug553269() throws Exception { verifier.addExpectedChange(project.getFile(".project"), IResourceDelta.ADDED, 0); project.open(null); - assertTrue(verifier.getMessage(), verifier.isDeltaValid()); + assertThat(verifier.isDeltaValid()).withFailMessage(verifier.getMessage()).isTrue(); } finally { workspace.removeResourceChangeListener(verifier); } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/LocalStoreRegressionTests.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/LocalStoreRegressionTests.java index 95db16bfe03..718d0b5ad90 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/LocalStoreRegressionTests.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/LocalStoreRegressionTests.java @@ -13,13 +13,14 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; +import static java.util.function.Predicate.not; +import static org.assertj.core.api.Assertions.assertThat; 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.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.assertTrue; import java.io.DataInputStream; import java.io.DataOutputStream; @@ -54,9 +55,9 @@ public void test_1FU4PJA() throws Throwable { /* */ IFile file = project.getFile("file"); createInFileSystem(file); - assertTrue("1.0", !file.exists()); + assertThat(file).matches(not(IFile::exists), "not exists"); file.refreshLocal(IResource.DEPTH_ZERO, null); - assertTrue("1.1", file.exists()); + assertThat(file).matches(IFile::exists, "exists"); } /** @@ -72,8 +73,8 @@ public void test_1FU4TW7() throws Throwable { createInFileSystem(folder); createInFileSystem(file); file.refreshLocal(IResource.DEPTH_INFINITE, null); - assertTrue("1.1", folder.exists()); - assertTrue("1.2", file.exists()); + assertThat(folder).matches(IFolder::exists, "exists"); + assertThat(file).matches(IFile::exists, "exists"); removeFromWorkspace(folder); removeFromFileSystem(folder); } @@ -91,7 +92,7 @@ public void test_1G65KR1() throws IOException { File target = new File(temp, "target"); Workspace.clear(target); // make sure there was nothing here before - assertTrue("1.0", !target.exists()); + assertThat(target).matches(not(File::exists), "not exists"); // write chunks try (SafeChunkyOutputStream output = new SafeChunkyOutputStream(target); @@ -103,7 +104,7 @@ public void test_1G65KR1() throws IOException { // read chunks try (SafeChunkyInputStream input = new SafeChunkyInputStream(target); DataInputStream dis = new DataInputStream(input)) { - assertEquals("3.0", dis.readLong(), 1234567890l); + assertEquals(dis.readLong(), 1234567890l); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GEAB3C_Test.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GEAB3C_Test.java index 11af8b2071a..806abf8ea88 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GEAB3C_Test.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GEAB3C_Test.java @@ -45,17 +45,6 @@ public class PR_1GEAB3C_Test { protected static final String VERIFIER_NAME = "TestListener"; - public void assertDelta() { - assertTrue(verifier.getMessage(), verifier.isDeltaValid()); - } - - /** - * Runs code to handle a core exception - */ - protected void handleCoreException(CoreException e) { - assertTrue("CoreException: " + e.getMessage(), false); - } - /** * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. @@ -102,7 +91,7 @@ public void test_1GEAB3C() throws CoreException { } }; getWorkspace().run(body, createTestMonitor()); - assertDelta(); + assertTrue(verifier.getMessage(), verifier.isDeltaValid()); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GH2B0N_Test.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GH2B0N_Test.java index 354d373e7ac..d665a6dc57f 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GH2B0N_Test.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GH2B0N_Test.java @@ -47,7 +47,7 @@ public void test_1GH2B0N() throws CoreException { IStatus status = getWorkspace().validateProjectLocation(project2, project.getLocation().append(project2.getName())); //Note this is not the original error case - //since Eclipse 3.2 a project is allowed to be nested in another project - assertTrue("2.0", status.isOK()); + assertTrue(status.isOK()); } }