From 6a574c3bab3d6382788f6072feac621c18c16f63 Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Fri, 5 Jan 2024 12:00:05 +0100 Subject: [PATCH] Improve array length assertions in resource tests In order to reduce/avoid usage of ambiguous `assertEquals` (hard to distinguish expected/actual) and prepare for a migration to JUnit 5 with swapped expected/actual parameters in the `assertEquals` signature, this change replaces certain `assertEquals` calls with AssertJ assertions: * Replace `assertEquals(MESSAGE, EXPECTED, ACTUAL.length)` with `assertThat(ACTUAL).as(MESSAGE).hasSize(EXPECTED))` and remove obsolete message where possible * Replace `assertEquals(EXPECTED, ACTUAL.length)` with `assertThat(ACTUAL).hasSize(EXPECTED)) * Replace `hasSize(0)` with `isEmpty()` to improve failure messages * Combine array size comparison with array contents comparison where possible --- .../core/tests/filesystem/SymlinkTest.java | 73 +-- .../tests/internal/alias/BasicAliasTest.java | 74 +-- .../tests/internal/builders/BuilderTest.java | 6 +- .../tests/internal/builders/RebuildTest.java | 25 +- .../internal/dtree/DeltaDataTreeTest.java | 44 +- .../internal/localstore/HistoryStoreTest.java | 490 ++++++-------- .../internal/localstore/RefreshLocalTest.java | 3 +- .../SafeChunkyInputOutputStreamTest.java | 26 +- .../resources/ProjectPreferencesTest.java | 15 +- .../resources/WorkspacePreferencesTest.java | 2 +- .../tests/internal/utils/ObjectMapTest.java | 3 +- .../core/tests/internal/watson/TestUtil.java | 27 +- .../core/tests/resources/CharsetTest.java | 22 +- .../tests/resources/FilteredResourceTest.java | 614 ++++++++++-------- .../tests/resources/HiddenResourceTest.java | 35 +- .../resources/IProjectDescriptionTest.java | 13 +- .../core/tests/resources/IProjectTest.java | 37 +- .../resources/IResourceChangeEventTest.java | 70 +- .../IResourceChangeListenerTest.java | 7 +- .../tests/resources/IWorkspaceRootTest.java | 37 +- .../core/tests/resources/IWorkspaceTest.java | 131 ++-- .../tests/resources/LinkedResourceTest.java | 35 +- .../core/tests/resources/MarkerSetTest.java | 13 +- .../tests/resources/ProjectEncodingTest.java | 4 +- .../tests/resources/ProjectOrderTest.java | 345 +++++----- .../tests/resources/VirtualFolderTest.java | 3 +- .../core/tests/resources/WorkspaceTest.java | 3 +- .../content/IContentTypeManagerTest.java | 315 ++++----- .../content/LazyInputStreamTest.java | 3 +- .../resources/content/LazyReaderTest.java | 3 +- .../content/SpecificContextTest.java | 13 +- .../tests/resources/content/TestBug94498.java | 11 +- .../refresh/RefreshProviderTest.java | 17 +- .../resources/regression/Bug_027271.java | 13 +- .../resources/regression/Bug_079398.java | 16 +- .../resources/regression/Bug_165892.java | 11 +- .../resources/regression/Bug_233939.java | 7 +- .../resources/regression/IResourceTest.java | 3 +- .../resources/regression/IWorkspaceTest.java | 13 +- .../TestMultipleBuildersOfSameType.java | 9 +- .../session/FindDeletedMembersTest.java | 218 ++----- .../TestBuilderDeltaSerialization.java | 9 +- .../resources/session/TestCloseNoSave.java | 6 +- .../resources/session/TestMultiSnap.java | 4 +- .../tests/resources/session/TestSave.java | 15 +- .../session/TestSaveCreateProject.java | 13 +- .../tests/resources/session/TestSaveSnap.java | 4 +- .../resources/session/TestSnapSaveSnap.java | 4 +- .../resources/usecase/Snapshot3Test.java | 3 +- .../resources/usecase/Snapshot4Test.java | 3 +- 50 files changed, 1276 insertions(+), 1594 deletions(-) diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/SymlinkTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/SymlinkTest.java index 70e8b372291..fcd522de5d7 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/SymlinkTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/SymlinkTest.java @@ -21,6 +21,8 @@ *******************************************************************************/ package org.eclipse.core.tests.filesystem; +import static java.util.function.Predicate.not; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.tests.filesystem.FileSystemTestUtil.ensureDoesNotExist; import static org.eclipse.core.tests.filesystem.FileSystemTestUtil.ensureExists; import static org.eclipse.core.tests.filesystem.FileSystemTestUtil.getMonitor; @@ -33,6 +35,8 @@ import java.io.IOException; import java.io.OutputStream; +import java.util.function.Consumer; +import java.util.function.Function; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileInfo; import org.eclipse.core.filesystem.IFileStore; @@ -156,40 +160,32 @@ public void testBrokenSymlinkMove() throws Exception { ensureDoesNotExist(aFile); ensureDoesNotExist(aDir); IFileInfo[] infos = baseStore.childInfos(EFS.NONE, getMonitor()); - assertEquals(infos.length, 4); + assertThat(infos).hasSize(4); + + Function> isSymLinkCheckProvider = link -> (info -> { + assertThat(link).isEqualTo(info.getName()); + assertThat(info.getAttribute(EFS.ATTRIBUTE_SYMLINK)).isTrue(); + }); IFileStore _llFile = baseStore.getChild("_llFile"); IFileStore _llDir = baseStore.getChild("_llDir"); llFile.move(_llFile, EFS.NONE, getMonitor()); llDir.move(_llDir, EFS.NONE, getMonitor()); infos = baseStore.childInfos(EFS.NONE, getMonitor()); - assertEquals(infos.length, 4); - assertFalse("1.0", containsSymlink(infos, llFile.getName())); - assertFalse("1.1", containsSymlink(infos, llDir.getName())); - assertTrue("1.2", containsSymlink(infos, _llFile.getName())); - assertTrue("1.3", containsSymlink(infos, _llFile.getName())); + assertThat(infos).hasSize(4) // + .noneSatisfy(isSymLinkCheckProvider.apply(llFile.getName())) + .noneSatisfy(isSymLinkCheckProvider.apply(llDir.getName())) + .anySatisfy(isSymLinkCheckProvider.apply(_llFile.getName())); IFileStore _lFile = baseStore.getChild("_lFile"); IFileStore _lDir = baseStore.getChild("_lDir"); lFile.move(_lFile, EFS.NONE, getMonitor()); lDir.move(_lDir, EFS.NONE, getMonitor()); infos = baseStore.childInfos(EFS.NONE, getMonitor()); - assertEquals(infos.length, 4); - assertFalse("1.4", containsSymlink(infos, lFile.getName())); - assertFalse("1.5", containsSymlink(infos, lDir.getName())); - assertTrue("1.6", containsSymlink(infos, _lFile.getName())); - assertTrue("1.7", containsSymlink(infos, _lFile.getName())); - } - - private boolean containsSymlink(IFileInfo[] infos, String link) { - for (IFileInfo info : infos) { - if (link.equals(info.getName())) { - if (info.getAttribute(EFS.ATTRIBUTE_SYMLINK)) { - return true; - } - } - } - return false; + assertThat(infos).hasSize(4) // + .noneSatisfy(isSymLinkCheckProvider.apply(lFile.getName())) + .noneSatisfy(isSymLinkCheckProvider.apply(lDir.getName())) + .anySatisfy(isSymLinkCheckProvider.apply(_lFile.getName())); } // Removing a broken symlink is possible. @@ -200,15 +196,15 @@ public void testBrokenSymlinkRemove() throws Exception { ensureDoesNotExist(aFile); ensureDoesNotExist(aDir); IFileInfo[] infos = baseStore.childInfos(EFS.NONE, getMonitor()); - assertEquals(infos.length, 4); + assertThat(infos).hasSize(4); llFile.delete(EFS.NONE, getMonitor()); llDir.delete(EFS.NONE, getMonitor()); infos = baseStore.childInfos(EFS.NONE, getMonitor()); - assertEquals(infos.length, 2); + assertThat(infos).hasSize(2); lFile.delete(EFS.NONE, getMonitor()); lDir.delete(EFS.NONE, getMonitor()); infos = baseStore.childInfos(EFS.NONE, getMonitor()); - assertEquals(infos.length, 0); + assertThat(infos).isEmpty(); } @Test @@ -225,7 +221,7 @@ public void testRecursiveSymlink() throws Exception { assertEquals("l2", i1.getStringAttribute(EFS.ATTRIBUTE_LINK_TARGET)); IFileInfo[] infos = baseStore.childInfos(EFS.NONE, getMonitor()); - assertEquals(infos.length, 2); + assertThat(infos).hasSize(2); i1.setAttribute(EFS.ATTRIBUTE_READ_ONLY, true); boolean exceptionThrown = false; try { @@ -257,7 +253,7 @@ public void testRecursiveSymlink() throws Exception { l1.delete(EFS.NONE, getMonitor()); infos = baseStore.childInfos(EFS.NONE, getMonitor()); - assertEquals(infos.length, 1); + assertThat(infos).hasSize(1); } @Test @@ -304,7 +300,7 @@ public void testSymlinkDirRead() throws Exception { IFileStore childDir = aDir.getChild("subDir"); ensureExists(childDir, true); IFileInfo[] infos = llDir.childInfos(EFS.NONE, getMonitor()); - assertEquals(infos.length, 1); + assertThat(infos).hasSize(1); assertTrue(infos[0].isDirectory()); assertFalse(infos[0].getAttribute(EFS.ATTRIBUTE_SYMLINK)); assertNull(infos[0].getStringAttribute(EFS.ATTRIBUTE_LINK_TARGET)); @@ -319,7 +315,7 @@ public void testSymlinkDirWrite() throws Exception { IFileStore childFile = llDir.getChild("subFile"); ensureExists(childFile, false); IFileInfo[] infos = aDir.childInfos(EFS.NONE, getMonitor()); - assertEquals(infos.length, 1); + assertThat(infos).hasSize(1); assertFalse(infos[0].isDirectory()); assertFalse(infos[0].getAttribute(EFS.ATTRIBUTE_SYMLINK)); assertNull(infos[0].getStringAttribute(EFS.ATTRIBUTE_LINK_TARGET)); @@ -359,21 +355,20 @@ public void _testSymlinkExtendedChars() throws Exception { mkLink(baseStore, "l" + specialCharName, specialCharName, true); mkLink(baseStore, "lf" + specialCharName, "ff" + specialCharName, false); IFileInfo[] infos = baseStore.childInfos(EFS.NONE, getMonitor()); - assertEquals("0.1", infos.length, 4); - for (IFileInfo info : infos) { - String infoName = info.getName(); - assertTrue("1." + infoName, infoName.endsWith(specialCharName)); - assertTrue("2." + infoName, info.exists()); + assertThat(infos).hasSize(4); + assertThat(infos).allSatisfy(info -> { + assertThat(info.getName()).endsWith(specialCharName); + assertThat(info).matches(IFileInfo::exists, "exists"); if (info.getName().charAt(1) == 'f') { - assertFalse("3." + infoName, info.isDirectory()); + assertThat(info).matches(not(IFileInfo::isDirectory), "is not a directory"); } else { - assertTrue("4." + infoName, info.isDirectory()); + assertThat(info).matches(IFileInfo::isDirectory, "is a directory"); } if (info.getName().charAt(0) == 'l') { - assertTrue("5." + infoName, info.getAttribute(EFS.ATTRIBUTE_SYMLINK)); - assertTrue("6." + infoName, info.getStringAttribute(EFS.ATTRIBUTE_LINK_TARGET).endsWith(specialCharName)); + assertThat(info).matches(it -> it.getAttribute(EFS.ATTRIBUTE_SYMLINK), "is symlink"); + assertThat(info.getStringAttribute(EFS.ATTRIBUTE_LINK_TARGET).endsWith(specialCharName)); } - } + }); } @Test diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/alias/BasicAliasTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/alias/BasicAliasTest.java index cab5efa9aba..9f93ce95698 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/alias/BasicAliasTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/alias/BasicAliasTest.java @@ -14,6 +14,7 @@ *******************************************************************************/ package org.eclipse.core.tests.internal.alias; +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.assertDoesNotExistInFileSystem; @@ -137,19 +138,18 @@ public URI toURI() { * that both resources are in sync with the file system. The resource names * in the tree may be different. The resources may not necessarily exist. */ - public void assertOverlap(String message, IResource resource1, IResource resource2) throws CoreException { - String errMsg = message + resource1.getFullPath().toString(); - assertEquals(errMsg + "(location)", resource1.getLocation(), resource2.getLocation()); - assertTrue(errMsg + "(sync)", resource1.isSynchronized(IResource.DEPTH_ZERO)); - assertTrue(errMsg + "(sync)", resource2.isSynchronized(IResource.DEPTH_ZERO)); + public void assertOverlap(IResource resource1, IResource resource2) throws CoreException { + assertThat(resource1.getLocation()).isEqualTo(resource2.getLocation()); + assertThat(resource1).matches(it -> it.isSynchronized(IResource.DEPTH_ZERO), "is synchronized"); + assertThat(resource2).matches(it -> it.isSynchronized(IResource.DEPTH_ZERO), "is synchronized"); IResource[] children1 = null; IResource[] children2 = null; children1 = getSortedChildren(resource1); children2 = getSortedChildren(resource2); - assertEquals(errMsg + "(child count)", children1.length, children2.length); + assertThat(children1).as("number of children").hasSameSizeAs(children2); for (int i = 0; i < children2.length; i++) { - assertOverlap(message, children1[i], children2[i]); + assertOverlap(children1[i], children2[i]); } } @@ -435,12 +435,10 @@ public void testBug256837() throws CoreException { // now p2 and link2TempFolder should be aliases IResource[] resources = aliasManager.computeAliases(link2TempFolder, ((Folder) link2TempFolder).getStore()); - assertEquals("5.0", 1, resources.length); - assertEquals("6.0", p2, resources[0]); + assertThat(resources).containsExactly(p2); resources = aliasManager.computeAliases(p2, ((Project) p2).getStore()); - assertEquals("7.0", 1, resources.length); - assertEquals("8.0", link2TempFolder, resources[0]); + assertThat(resources).containsExactly(link2TempFolder); } @Test @@ -509,12 +507,12 @@ public void testCopyFile() throws CoreException { sourceFile.copy(linkDest.getFullPath(), IResource.NONE, createTestMonitor()); assertTrue("1.1", linkDest.exists()); assertTrue("1.2", overlapDest.exists()); - assertOverlap("1.3", linkDest, overlapDest); + assertOverlap(linkDest, overlapDest); linkDest.delete(IResource.NONE, createTestMonitor()); assertFalse("1.4", linkDest.exists()); assertFalse("1.5", overlapDest.exists()); - assertOverlap("1.6", linkDest, overlapDest); + assertOverlap(linkDest, overlapDest); // duplicate file linkDest = lLinked; @@ -530,7 +528,7 @@ public void testCopyFile() throws CoreException { sourceFile.copy(overlapDest.getFullPath(), IResource.NONE, createTestMonitor()); assertTrue("2.4", linkDest.exists()); assertTrue("2.5", overlapDest.exists()); - assertOverlap("2.6", linkDest, overlapDest); + assertOverlap(linkDest, overlapDest); // file in duplicate folder linkDest = fLinked.getFile("CopyDestination"); @@ -539,12 +537,12 @@ public void testCopyFile() throws CoreException { sourceFile.copy(overlapDest.getFullPath(), IResource.NONE, createTestMonitor()); assertTrue("3.1", linkDest.exists()); assertTrue("3.2", overlapDest.exists()); - assertOverlap("3.3", linkDest, overlapDest); + assertOverlap(linkDest, overlapDest); overlapDest.delete(IResource.NONE, createTestMonitor()); assertFalse("3.4", linkDest.exists()); assertFalse("3.5", overlapDest.exists()); - assertOverlap("3.6", linkDest, overlapDest); + assertOverlap(linkDest, overlapDest); } @Test @@ -596,9 +594,9 @@ public void testCopyToChild() throws CoreException { public void testCreateDeleteFile() throws CoreException { // file in linked folder lChildLinked.delete(IResource.NONE, createTestMonitor()); - assertOverlap("1.1", lChildLinked, lChildOverlap); + assertOverlap(lChildLinked, lChildOverlap); lChildLinked.create(createRandomContentsStream(), IResource.NONE, createTestMonitor()); - assertOverlap("1.2", lChildLinked, lChildOverlap); + assertOverlap(lChildLinked, lChildOverlap); //duplicate file lOverlap.delete(IResource.NONE, createTestMonitor()); assertEquals("2.0", lLinked.getLocation(), lOverlap.getLocation()); @@ -614,13 +612,13 @@ public void testCreateDeleteFile() throws CoreException { assertThrows(CoreException.class, () -> lLinked.setContents(createRandomContentsStream(), IResource.NONE, createTestMonitor())); lOverlap.create(createRandomContentsStream(), IResource.NONE, createTestMonitor()); - assertOverlap("2.8", lLinked, lOverlap); + assertOverlap(lLinked, lOverlap); //file in duplicate folder lChildOverlap.delete(IResource.NONE, createTestMonitor()); - assertOverlap("1.1", lChildLinked, lChildOverlap); + assertOverlap(lChildLinked, lChildOverlap); lChildOverlap.create(createRandomContentsStream(), IResource.NONE, createTestMonitor()); - assertOverlap("1.2", lChildLinked, lChildOverlap); + assertOverlap(lChildLinked, lChildOverlap); } @Test @@ -632,7 +630,7 @@ public void testCreateDeleteFolder() throws CoreException { assertFalse("1.1", fLinked.getLocation().toFile().exists()); fOverlap.create(IResource.NONE, true, createTestMonitor()); - assertOverlap("1.2", fOverlap, fLinked); + assertOverlap(fOverlap, fLinked); //linked folder fLinked.delete(IResource.NONE, createTestMonitor()); @@ -641,20 +639,20 @@ public void testCreateDeleteFolder() throws CoreException { assertTrue("2.1", fOverlap.getLocation().toFile().exists()); fLinked.createLink(fOverlap.getLocation(), IResource.NONE, createTestMonitor()); - assertOverlap("1.4", fOverlap, fLinked); + assertOverlap(fOverlap, fLinked); //child of linked folders IFolder child1 = fLinkOverlap1.getFolder("LinkChild"); IFolder child2 = fLinkOverlap2.getFolder(child1.getName()); child1.create(IResource.NONE, true, createTestMonitor()); - assertOverlap("3.0", child1, child2); + assertOverlap(child1, child2); child1.delete(IResource.NONE, createTestMonitor()); assertFalse("3.1", child1.exists()); assertFalse("3.2", child2.exists()); child2.create(IResource.NONE, true, createTestMonitor()); - assertOverlap("3.3", child1, child2); + assertOverlap(child1, child2); child2.delete(IResource.NONE, createTestMonitor()); assertFalse("3.4", child1.exists()); assertFalse("3.5", child2.exists()); @@ -818,34 +816,34 @@ public void testDeleteProjectContents() throws CoreException { public void testFileAppendContents() throws CoreException { //linked file lLinked.appendContents(createRandomContentsStream(), IResource.NONE, createTestMonitor()); - assertOverlap("1.1", lLinked, lOverlap); + assertOverlap(lLinked, lOverlap); //file in linked folder lChildLinked.appendContents(createRandomContentsStream(), IResource.NONE, createTestMonitor()); - assertOverlap("2.1", lChildLinked, lChildOverlap); + assertOverlap(lChildLinked, lChildOverlap); //duplicate file lOverlap.appendContents(createRandomContentsStream(), IResource.NONE, createTestMonitor()); - assertOverlap("3.1", lLinked, lOverlap); + assertOverlap(lLinked, lOverlap); //file in duplicate folder lChildOverlap.appendContents(createRandomContentsStream(), IResource.NONE, createTestMonitor()); - assertOverlap("3.1", lChildLinked, lChildOverlap); + assertOverlap(lChildLinked, lChildOverlap); } @Test public void testFileSetContents() throws CoreException { //linked file lLinked.setContents(createRandomContentsStream(), IResource.NONE, createTestMonitor()); - assertOverlap("1.1", lLinked, lOverlap); + assertOverlap(lLinked, lOverlap); //file in linked folder lChildLinked.setContents(createRandomContentsStream(), IResource.NONE, createTestMonitor()); - assertOverlap("2.1", lChildLinked, lChildOverlap); + assertOverlap(lChildLinked, lChildOverlap); //duplicate file lOverlap.setContents(createRandomContentsStream(), IResource.NONE, createTestMonitor()); - assertOverlap("3.1", lLinked, lOverlap); + assertOverlap(lLinked, lOverlap); //file in duplicate folder lChildOverlap.setContents(createRandomContentsStream(), IResource.NONE, createTestMonitor()); - assertOverlap("3.1", lChildLinked, lChildOverlap); + assertOverlap(lChildLinked, lChildOverlap); } /** @@ -860,7 +858,7 @@ public void testMoveFile() throws CoreException { assertDoesNotExistInWorkspace(lChildLinked); assertDoesNotExistInWorkspace(lChildOverlap); assertExistsInWorkspace(destination); - assertOverlap("1.4", lChildLinked, lChildOverlap); + assertOverlap(lChildLinked, lChildOverlap); assertTrue("1.5", lChildLinked.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("1.6", destination.isSynchronized(IResource.DEPTH_INFINITE)); @@ -868,7 +866,7 @@ public void testMoveFile() throws CoreException { assertExistsInWorkspace(lChildLinked); assertExistsInWorkspace(lChildOverlap); assertDoesNotExistInWorkspace(destination); - assertOverlap("2.4", lChildLinked, lChildOverlap); + assertOverlap(lChildLinked, lChildOverlap); //duplicate file lOverlap.move(destination.getFullPath(), IResource.NONE, createTestMonitor()); assertDoesNotExistInWorkspace(lOverlap); @@ -882,19 +880,19 @@ public void testMoveFile() throws CoreException { assertExistsInWorkspace(lLinked); assertExistsInWorkspace(lOverlap); assertDoesNotExistInWorkspace(destination); - assertOverlap("3.8", lLinked, lOverlap); + assertOverlap(lLinked, lOverlap); //file in duplicate folder lChildOverlap.move(destination.getFullPath(), IResource.NONE, createTestMonitor()); assertDoesNotExistInWorkspace(lChildLinked); assertDoesNotExistInWorkspace(lChildOverlap); assertExistsInWorkspace(destination); - assertOverlap("3.4", lChildLinked, lChildOverlap); + assertOverlap(lChildLinked, lChildOverlap); destination.move(lChildOverlap.getFullPath(), IResource.NONE, createTestMonitor()); assertExistsInWorkspace(lChildLinked); assertExistsInWorkspace(lChildOverlap); assertDoesNotExistInWorkspace(destination); - assertOverlap("3.8", lChildLinked, lChildOverlap); + assertOverlap(lChildLinked, lChildOverlap); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuilderTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuilderTest.java index 536277ea156..a2feddeded7 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuilderTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuilderTest.java @@ -14,6 +14,7 @@ *******************************************************************************/ package org.eclipse.core.tests.internal.builders; +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; @@ -647,9 +648,8 @@ public void testCloseOpenProject() throws CoreException { //ensure the build spec hasn't changed desc = project.getDescription(); ICommand[] commands = desc.getBuildSpec(); - assertEquals(2, commands.length); - assertEquals(commands[0].getBuilderName(), SortBuilder.BUILDER_NAME); - assertEquals(commands[1].getBuilderName(), SortBuilder.BUILDER_NAME); + assertThat(commands).hasSize(2) + .allSatisfy(command -> assertThat(command.getBuilderName()).isEqualTo(SortBuilder.BUILDER_NAME)); Map args = commands[0].getArguments(); assertEquals("Build1", args.get(TestBuilder.BUILD_ID)); args = commands[1].getArguments(); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/RebuildTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/RebuildTest.java index 0b926410231..6a1a41cd628 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/RebuildTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/RebuildTest.java @@ -14,6 +14,7 @@ *******************************************************************************/ package org.eclipse.core.tests.internal.builders; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import static org.eclipse.core.tests.resources.ResourceTestUtil.setAutoBuilding; @@ -90,7 +91,7 @@ public void testSingleProjectPropagationAndNoOtherBuilders() throws Exception { // do an initial build to create builders project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, createTestMonitor()); List builders = RebuildingBuilder.getInstances(); - assertEquals(project.getDescription().getBuildSpec().length, builders.size()); + assertThat(project.getDescription().getBuildSpec()).hasSameSizeAs(builders); RebuildingBuilder b1 = builders.get(0); RebuildingBuilder b2 = builders.get(1); RebuildingBuilder b3 = builders.get(2); @@ -221,7 +222,7 @@ public void testSingleProjectPropagationAndOtherBuilders() throws Exception { // do an initial build to create builders project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, createTestMonitor()); List builders = RebuildingBuilder.getInstances(); - assertEquals(project.getDescription().getBuildSpec().length, builders.size()); + assertThat(project.getDescription().getBuildSpec()).hasSameSizeAs(builders); RebuildingBuilder b1 = builders.get(0); RebuildingBuilder b2 = builders.get(1); RebuildingBuilder b3 = builders.get(2); @@ -343,7 +344,7 @@ public void testSingleProjectNoPropagationAndProcessOtherBuilder() throws Except // do an initial build to create builders project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, createTestMonitor()); List builders = RebuildingBuilder.getInstances(); - assertEquals(project.getDescription().getBuildSpec().length, builders.size()); + assertThat(project.getDescription().getBuildSpec()).hasSameSizeAs(builders); RebuildingBuilder b1 = builders.get(0); RebuildingBuilder b2 = builders.get(1); RebuildingBuilder b3 = builders.get(2); @@ -469,7 +470,7 @@ public void testSingleProjectNoPropagationNoOtherBuilders() throws Exception { // do an initial build to create builders project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, createTestMonitor()); List builders = RebuildingBuilder.getInstances(); - assertEquals(project.getDescription().getBuildSpec().length, builders.size()); + assertThat(project.getDescription().getBuildSpec()).hasSameSizeAs(builders); RebuildingBuilder b1 = builders.get(0); RebuildingBuilder b2 = builders.get(1); RebuildingBuilder b3 = builders.get(2); @@ -605,7 +606,7 @@ public void testMultipleProjectsPropagationAndNoOtherBuilders() throws Exception // do an initial build to create builders project1.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, createTestMonitor()); List builders = RebuildingBuilder.getInstances(); - assertEquals(project1.getDescription().getBuildSpec().length, builders.size()); + assertThat(project1.getDescription().getBuildSpec()).hasSameSizeAs(builders); RebuildingBuilder b1 = builders.get(0); RebuildingBuilder b2 = builders.get(1); RebuildingBuilder b3 = builders.get(2); @@ -740,7 +741,7 @@ public void testMultipleProjectsPropagationAndProcessOtherBuilders() throws Exce // do an initial build to create builders project1.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, createTestMonitor()); List builders = RebuildingBuilder.getInstances(); - assertEquals(project1.getDescription().getBuildSpec().length, builders.size()); + assertThat(project1.getDescription().getBuildSpec()).hasSameSizeAs(builders); RebuildingBuilder b1 = builders.get(0); RebuildingBuilder b2 = builders.get(1); RebuildingBuilder b3 = builders.get(2); @@ -881,7 +882,7 @@ public void testMultipleProjectsPropagationAndNoOtherBuildersWithEarlyExit() thr // do an initial build to create builders project1.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, createTestMonitor()); List builders = RebuildingBuilder.getInstances(); - assertEquals(project1.getDescription().getBuildSpec().length, builders.size()); + assertThat(project1.getDescription().getBuildSpec()).hasSameSizeAs(builders); RebuildingBuilder b1 = builders.get(0); RebuildingBuilder b2 = builders.get(1); RebuildingBuilder b3 = builders.get(2); @@ -1037,7 +1038,7 @@ public void testMultipleProjectsNoPropagationNoOtherBuilders() throws Exception // do an initial build to create builders project1.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, createTestMonitor()); List builders = RebuildingBuilder.getInstances(); - assertEquals(project1.getDescription().getBuildSpec().length, builders.size()); + assertThat(project1.getDescription().getBuildSpec()).hasSameSizeAs(builders); RebuildingBuilder b1 = builders.get(0); RebuildingBuilder b2 = builders.get(1); RebuildingBuilder b3 = builders.get(2); @@ -1194,7 +1195,7 @@ public void testMultipleProjectsNoPropagationAndOtherBuilders() throws Exception // do an initial build to create builders project1.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, createTestMonitor()); List builders = RebuildingBuilder.getInstances(); - assertEquals(project1.getDescription().getBuildSpec().length, builders.size()); + assertThat(project1.getDescription().getBuildSpec()).hasSameSizeAs(builders); RebuildingBuilder b1 = builders.get(0); RebuildingBuilder b2 = builders.get(1); RebuildingBuilder b3 = builders.get(2); @@ -1353,7 +1354,7 @@ public void testMultipleProjectsNoPropagationNoOtherBuildersEarlyExit() throws E // do an initial build to create builders project1.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, createTestMonitor()); List builders = RebuildingBuilder.getInstances(); - assertEquals(project1.getDescription().getBuildSpec().length, builders.size()); + assertThat(project1.getDescription().getBuildSpec()).hasSameSizeAs(builders); RebuildingBuilder b1 = builders.get(0); RebuildingBuilder b2 = builders.get(1); RebuildingBuilder b3 = builders.get(2); @@ -1508,7 +1509,7 @@ public void testMultipleProjectsPropagationAndNoOtherBuildersExplicitRebuild() t // do an initial build to create builders project1.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, createTestMonitor()); List builders = RebuildingBuilder.getInstances(); - assertEquals(project1.getDescription().getBuildSpec().length, builders.size()); + assertThat(project1.getDescription().getBuildSpec()).hasSameSizeAs(builders); RebuildingBuilder b1 = builders.get(0); // Create and set a build spec for the project @@ -1711,7 +1712,7 @@ public void testMultipleProjectsPropagationAndProcessOtherBuildersExplicitRebuil // do an initial build to create builders project1.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, createTestMonitor()); List builders = RebuildingBuilder.getInstances(); - assertEquals(project1.getDescription().getBuildSpec().length, builders.size()); + assertThat(project1.getDescription().getBuildSpec()).hasSameSizeAs(builders); RebuildingBuilder b1 = builders.get(0); // Create and set a build spec for the project diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/dtree/DeltaDataTreeTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/dtree/DeltaDataTreeTest.java index cdd2b0c3e1f..b5692d06edd 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/dtree/DeltaDataTreeTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/dtree/DeltaDataTreeTest.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.core.tests.internal.dtree; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -252,7 +253,7 @@ private void assertUnchanged(DeltaDataTree delta) { NodeComparison nodeComparison = (NodeComparison) rootData; assertEquals(nodeComparison.getNewData(), nodeComparison.getOldData()); // assertEquals(0, nodeComparison.getComparison()); XXX fails for tree!=other - assertEquals(0, delta.getChildren(AbstractDataTree.rootKey()).length); + assertThat(delta.getChildren(AbstractDataTree.rootKey())).isEmpty(); } @@ -386,7 +387,7 @@ public void testCreateChild() { tree.createChild(leftKey, "double"); tree.createChild(leftKey, "double"); /* Make sure size has only increased by one */ - assertEquals(size + 1, (tree.getNamesOfChildren(leftKey)).length); + assertThat(tree.getNamesOfChildren(leftKey)).hasSize(size + 1); } /** @@ -514,9 +515,9 @@ public void testDeltaOnCompletelyDifferentTrees() { @Test public void testEmpty() { - assertTrue("1", emptyTree.includes(rootKey)); - assertNotNull("2", TestHelper.getRootNode(emptyTree)); - assertEquals("3", 0, TestHelper.getRootNode(emptyTree).getChildren().length); + assertTrue(emptyTree.includes(rootKey)); + assertNotNull(TestHelper.getRootNode(emptyTree)); + assertThat(TestHelper.getRootNode(emptyTree).getChildren()).isEmpty(); } /** @@ -746,27 +747,22 @@ public void testGetChildren() { try { /* empty tree */ testChildren = emptyTree.getChildren(rootKey); - assertEquals("1", 0, testChildren.length); + assertThat(testChildren).isEmpty(); /* root node */ testChildren = tree.getChildren(rootKey); - assertEquals("2", 2, testChildren.length); - assertTrue("3", testChildren[0].equals(rootChildren[0])); - assertTrue("4", testChildren[1].equals(rootChildren[1])); + assertThat(testChildren).containsExactly(rootChildren[0], rootChildren[1]); /* interior nodes */ testChildren = tree.getChildren(leftKey); - assertEquals("5", 3, testChildren.length); - assertTrue("6", testChildren[0].equals(leftChildren[0])); - assertTrue("7", testChildren[2].equals(leftChildren[1])); - assertTrue("8", testChildren[1].equals(leftChildren[2])); + assertThat(testChildren).containsExactly(leftChildren[0], leftChildren[2], leftChildren[1]); /* leaf nodes */ testChildren = tree.getChildren(leftChildren[0]); - assertEquals("9", 0, testChildren.length); + assertThat(testChildren).isEmpty(); testChildren = tree.getChildren(rightChildren[0]); - assertEquals("10", 0, testChildren.length); + assertThat(testChildren).isEmpty(); } catch (ObjectNotFoundException e) { caught = true; } finally { @@ -809,31 +805,25 @@ public void testGetNamesOfChildren() { try { /* empty tree */ testChildren = emptyTree.getNamesOfChildren(rootKey); - assertEquals("1", 0, testChildren.length); + assertThat(testChildren).isEmpty(); /* root node */ testChildren = tree.getNamesOfChildren(rootKey); - assertEquals("2", 2, testChildren.length); - assertTrue("3", testChildren[0].equals(rootChildren[0])); - assertTrue("4", testChildren[1].equals(rootChildren[1])); + assertThat(testChildren).containsExactly(rootChildren[0], rootChildren[1]); /* interior nodes */ testChildren = tree.getNamesOfChildren(leftKey); - assertEquals("5", 3, testChildren.length); - assertTrue("6", testChildren[0].equals(leftChildren[0])); - assertTrue("7", testChildren[2].equals(leftChildren[1])); - assertTrue("8", testChildren[1].equals(leftChildren[2])); + assertThat(testChildren).containsExactly(leftChildren[0], leftChildren[2], leftChildren[1]); testChildren = tree.getNamesOfChildren(rightKey); - assertEquals("8.1", 1, testChildren.length); - assertTrue("8.2", testChildren[0].equals(rightChildren[0])); + assertThat(testChildren).containsExactly(rightChildren[0]); /* leaf nodes */ testChildren = tree.getNamesOfChildren(leftKey.append("one")); - assertEquals("9", 0, testChildren.length); + assertThat(testChildren).isEmpty(); testChildren = tree.getNamesOfChildren(rightKey.append("rightOfRight")); - assertEquals("10", 0, testChildren.length); + assertThat(testChildren).isEmpty(); } catch (ObjectNotFoundException e) { caught = true; } finally { diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/HistoryStoreTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/HistoryStoreTest.java index 6f3188b50d0..668aa541f42 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/HistoryStoreTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/HistoryStoreTest.java @@ -14,6 +14,7 @@ *******************************************************************************/ package org.eclipse.core.tests.internal.localstore; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.compareContent; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInFileSystem; @@ -32,7 +33,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.filesystem.provider.FileInfo; @@ -243,14 +243,14 @@ public void testAddStateAndPolicies() throws Exception { } IFileState[] states = file.getHistory(createTestMonitor()); // Make sure we have 8 states as we haven't trimmed yet. - assertEquals("1.02", 8, states.length); + assertThat(states).hasSize(8); IFileState[] oldStates = states; getWorkspace().save(true, null); states = file.getHistory(createTestMonitor()); // We added 8 states. Make sure we only have 5 (the max). - assertEquals("1.2", description.getMaxFileStates(), states.length); + assertThat(states).hasSize(description.getMaxFileStates()); // assert that states are in the correct order (newer ones first) long lastModified = states[0].getModificationTime(); @@ -295,7 +295,7 @@ public void testAddStateAndPolicies() throws Exception { getWorkspace().setDescription(description); states = file.getHistory(createTestMonitor()); // Make sure we have 5 states for file file.txt - assertEquals("3.1", description.getMaxFileStates(), states.length); + assertThat(states).hasSize(description.getMaxFileStates()); // change policies // 10 seconds description.setFileStateLongevity(1000 * 10); @@ -310,7 +310,7 @@ public void testAddStateAndPolicies() throws Exception { states = file.getHistory(createTestMonitor()); // The 5 states for file.txt should have exceeded their longevity // and been removed. Make sure we have 0 states left. - assertEquals("3.5", 0, states.length); + assertThat(states).isEmpty(); } @Test @@ -327,20 +327,20 @@ public void testBug28238() throws Exception { // location of the data on disk IFileStore fileStore = workspaceRule.getTempStore(); createInFileSystem(fileStore); - assertEquals("1.0" + " file already has state", 0, store.getStates(file.getFullPath(), createTestMonitor()).length); + assertThat(store.getStates(file.getFullPath(), createTestMonitor())).as("check file has no state").isEmpty(); // add the data to the history store FileInfo fileInfo = new FileInfo(file.getName()); fileInfo.setLastModified(System.currentTimeMillis()); store.addState(file.getFullPath(), fileStore, fileInfo, true); IFileState[] states = store.getStates(file.getFullPath(), createTestMonitor()); - assertEquals("2.0", 1, states.length); + assertThat(states).hasSize(1); // copy the data store.copyHistory(folder, destinationFolder, true); states = store.getStates(destinationFile.getFullPath(), createTestMonitor()); - assertEquals("3.0", 1, states.length); + assertThat(states).hasSize(1); } @Test @@ -363,20 +363,20 @@ public void testBug28603() throws CoreException { int maxStates = ResourcesPlugin.getWorkspace().getDescription().getMaxFileStates(); IFileState[] states = file1.getHistory(createTestMonitor()); - assertEquals("1.1", 3, states.length); + assertThat(states).hasSize(3); int currentStates = 3; - assertEquals("1.2" + " file2 already has history", 0, file2.getHistory(createTestMonitor()).length); + assertThat(file2.getHistory(createTestMonitor())).as("check file2 has no history").isEmpty(); for (int i = 0; i < maxStates + 10; i++) { states = file1.getHistory(createTestMonitor()); - assertEquals("2.1." + i + " file1 states", currentStates, states.length); + assertThat(states).as(i + " file1 states").hasSize(currentStates); file1.move(file2.getFullPath(), true, true, createTestMonitor()); states = file2.getHistory(createTestMonitor()); currentStates = currentStates < maxStates ? currentStates + 1 : maxStates; - assertEquals("2.4." + i + " file2 states", currentStates, states.length); + assertThat(states).as(i + " file2 states").hasSize(currentStates); file2.move(file1.getFullPath(), true, true, createTestMonitor()); states = file1.getHistory(createTestMonitor()); currentStates = currentStates < maxStates ? currentStates + 1 : maxStates; - assertEquals("2.7." + i + " file1 states", currentStates, states.length); + assertThat(states).as(i + " file1 states").hasSize(currentStates); } } @@ -424,7 +424,7 @@ public void testClean() throws Exception { // All 8 states should exist. long oldLastModTimes[] = new long[8]; IFileState[] states = file.getHistory(createTestMonitor()); - assertEquals("1.1", 8, states.length); + assertThat(states).hasSize(8); for (int i = 0; i < 8; i++) { oldLastModTimes[i] = states[i].getModificationTime(); } @@ -441,7 +441,7 @@ public void testClean() throws Exception { // Check to ensure only 3 states remain. Make sure these are the 3 // newer states. states = file.getHistory(createTestMonitor()); - assertEquals("2.3", 3, states.length); + assertThat(states).hasSize(3); // assert that states are in the correct order (newer ones first) long lastModified = states[0].getModificationTime(); for (int i = 1; i < states.length; i++) { @@ -461,7 +461,7 @@ public void testClean() throws Exception { // the description should be the same as the first test getWorkspace().setDescription(description); states = file.getHistory(createTestMonitor()); - assertEquals("3.1", 3, states.length); + assertThat(states).hasSize(3); // change policies // 10 seconds description.setFileStateLongevity(1000 * 10); @@ -484,7 +484,7 @@ public void testClean() throws Exception { // Ensure we have no state information left. It should have been // considered stale. states = file.getHistory(createTestMonitor()); - assertEquals("5.1", 0, states.length); + assertThat(states).isEmpty(); } /** @@ -523,9 +523,9 @@ public void testCopyFolder() throws Exception { file.setContents(createInputStream(contents[1]), true, true, createTestMonitor()); file.setContents(createInputStream(contents[2]), true, true, createTestMonitor()); IFileState[] states = file.getHistory(createTestMonitor()); - assertEquals("1.0", 2, states.length); - assertTrue("1.1", compareContent(createInputStream(contents[1]), states[0].getContents())); - assertTrue("1.2", compareContent(createInputStream(contents[0]), states[1].getContents())); + assertThat(states).hasSize(2).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[1]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[0]), second.getContents())).isTrue()); // Now do the move folder.copy(folder2.getFullPath(), true, createTestMonitor()); @@ -540,15 +540,15 @@ public void testCopyFolder() throws Exception { // Check the local history of both files states = file.getHistory(createTestMonitor()); - assertEquals("2.0", 2, states.length); - assertTrue("2.1", compareContent(createInputStream(contents[1]), states[0].getContents())); - assertTrue("2.2", compareContent(createInputStream(contents[0]), states[1].getContents())); + assertThat(states).hasSize(2).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[1]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[0]), second.getContents())).isTrue()); states = file2.getHistory(createTestMonitor()); - assertEquals("2.3", 4, states.length); - assertTrue("2.4", compareContent(createInputStream(contents[3]), states[0].getContents())); - assertTrue("2.5", compareContent(createInputStream(contents[2]), states[1].getContents())); - assertTrue("2.6", compareContent(createInputStream(contents[1]), states[2].getContents())); - assertTrue("2.7", compareContent(createInputStream(contents[0]), states[3].getContents())); + assertThat(states).hasSize(4).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[3]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[2]), second.getContents())).isTrue(), + third -> assertThat(compareContent(createInputStream(contents[1]), third.getContents())).isTrue(), + fourth -> assertThat(compareContent(createInputStream(contents[0]), fourth.getContents())).isTrue()); project.delete(true, createTestMonitor()); } @@ -595,9 +595,9 @@ public void testCopyHistoryFile() throws Exception { Thread.sleep(1000); IFileState[] states = file.getHistory(createTestMonitor()); - assertEquals("1.0", 2, states.length); - assertTrue("1.1", compareContent(createInputStream(contents[1]), states[0].getContents())); - assertTrue("1.2", compareContent(createInputStream(contents[0]), states[1].getContents())); + assertThat(states).hasSize(2).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[1]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[0]), second.getContents())).isTrue()); file2.create(createInputStream(contents[3]), true, createTestMonitor()); file2.setContents(createInputStream(contents[4]), true, true, createTestMonitor()); @@ -636,10 +636,10 @@ public void testCopyHistoryFile() throws Exception { // Test a valid copy of a file store.copyHistory(file, file2, false); states = file2.getHistory(createTestMonitor()); - assertEquals("2.4", 3, states.length); - assertTrue("2.5", compareContent(createInputStream(contents[3]), states[0].getContents())); - assertTrue("2.6", compareContent(createInputStream(contents[1]), states[1].getContents())); - assertTrue("2.7", compareContent(createInputStream(contents[0]), states[2].getContents())); + assertThat(states).hasSize(3).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[3]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[1]), second.getContents())).isTrue(), + third -> assertThat(compareContent(createInputStream(contents[0]), third.getContents())).isTrue()); } @Test @@ -665,9 +665,9 @@ public void testCopyHistoryFolder() throws Exception { Thread.sleep(1000); IFileState[] states = file.getHistory(createTestMonitor()); - assertEquals("1.0", 2, states.length); - assertTrue("1.1", compareContent(createInputStream(contents[1]), states[0].getContents())); - assertTrue("1.2", compareContent(createInputStream(contents[0]), states[1].getContents())); + assertThat(states).hasSize(2).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[1]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[0]), second.getContents())).isTrue()); folder2.create(true, true, createTestMonitor()); file2.create(createInputStream(contents[3]), true, createTestMonitor()); file2.setContents(createInputStream(contents[4]), true, true, createTestMonitor()); @@ -676,10 +676,10 @@ public void testCopyHistoryFolder() throws Exception { IHistoryStore store = ((Resource) file).getLocalManager().getHistoryStore(); store.copyHistory(folder, folder2, false); states = file2.getHistory(createTestMonitor()); - assertEquals("2.4", 3, states.length); - assertTrue("2.5", compareContent(createInputStream(contents[3]), states[0].getContents())); - assertTrue("2.6", compareContent(createInputStream(contents[1]), states[1].getContents())); - assertTrue("2.7", compareContent(createInputStream(contents[0]), states[2].getContents())); + assertThat(states).hasSize(3).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[3]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[1]), second.getContents())).isTrue(), + third -> assertThat(compareContent(createInputStream(contents[0]), third.getContents())).isTrue()); } @Test @@ -705,9 +705,9 @@ public void testCopyHistoryProject() throws Exception { Thread.sleep(1000); IFileState[] states = file.getHistory(createTestMonitor()); - assertEquals("1.0", 2, states.length); - assertTrue("1.1", compareContent(createInputStream(contents[1]), states[0].getContents())); - assertTrue("1.2", compareContent(createInputStream(contents[0]), states[1].getContents())); + assertThat(states).hasSize(2).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[1]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[0]), second.getContents())).isTrue()); folder2.create(true, true, createTestMonitor()); file2.create(createInputStream(contents[3]), true, createTestMonitor()); file2.setContents(createInputStream(contents[4]), true, true, createTestMonitor()); @@ -716,10 +716,10 @@ public void testCopyHistoryProject() throws Exception { IHistoryStore store = ((Resource) file).getLocalManager().getHistoryStore(); store.copyHistory(project, project2, false); states = file2.getHistory(createTestMonitor()); - assertEquals("2.4", 3, states.length); - assertTrue("2.5", compareContent(createInputStream(contents[3]), states[0].getContents())); - assertTrue("2.6", compareContent(createInputStream(contents[1]), states[1].getContents())); - assertTrue("2.7", compareContent(createInputStream(contents[0]), states[2].getContents())); + assertThat(states).hasSize(3).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[3]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[1]), second.getContents())).isTrue(), + third -> assertThat(compareContent(createInputStream(contents[0]), third.getContents())).isTrue()); } @Test @@ -737,17 +737,17 @@ public void testDelete() throws CoreException { // Check to see that there are only 2 states before the deletion IFileState[] states = file.getHistory(createTestMonitor()); - assertEquals("1.0", 2, states.length); + assertThat(states).hasSize(2); // Delete the file. This should add a state to the history store. file.delete(true, true, createTestMonitor()); states = file.getHistory(createTestMonitor()); - assertEquals("1.1", 3, states.length); + assertThat(states).hasSize(3); // Re-create the file. This should not affect the history store. file.create(createRandomContentsStream(), true, createTestMonitor()); states = file.getHistory(createTestMonitor()); - assertEquals("1.2", 3, states.length); + assertThat(states).hasSize(3); // test folder IFolder folder = project.getFolder("folder"); @@ -761,18 +761,18 @@ public void testDelete() throws CoreException { // There should only be 2 history store entries. states = file.getHistory(createTestMonitor()); - assertEquals("2.0", 2, states.length); + assertThat(states).hasSize(2); // Delete the folder. This should cause one more history store entry. folder.delete(true, true, createTestMonitor()); states = file.getHistory(createTestMonitor()); - assertEquals("2.1", 3, states.length); + assertThat(states).hasSize(3); // Re-create the folder. There should be no new history store entries. folder.create(true, true, createTestMonitor()); file.create(createRandomContentsStream(), true, createTestMonitor()); states = file.getHistory(createTestMonitor()); - assertEquals("2.2", 3, states.length); + assertThat(states).hasSize(3); project.delete(true, createTestMonitor()); } @@ -801,10 +801,10 @@ public void testExists() throws Throwable { /* Valid Case: Test retrieved values. */ IFileState[] states = file.getHistory(createTestMonitor()); // Make sure we have ITERATIONS number of states - assertEquals("5.1", ITERATIONS, states.length); + assertThat(states).hasSize(ITERATIONS); // Make sure that each of these states really exists in the filesystem. - for (int i = 0; i < states.length; i++) { - assertTrue("5.2." + i, states[i].exists()); + for (IFileState state : states) { + assertThat(state).matches(IFileState::exists, "exists"); } } @@ -816,8 +816,7 @@ public void testFindDeleted() throws CoreException { project.create(createTestMonitor()); project.open(createTestMonitor()); - IFile[] df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("0.1", 0, df.length); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); // test that a deleted file can be found IFile pfile = project.getFile("findDeletedFile.txt"); @@ -826,58 +825,37 @@ public void testFindDeleted() throws CoreException { pfile.delete(true, true, createTestMonitor()); // the deleted file should show up as a deleted member of project - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("0.1", 1, df.length); - assertEquals("0.2", pfile, df[0]); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("0.3", 1, df.length); - assertEquals("0.4", pfile, df[0]); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("0.5", 0, df.length); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())) + .containsExactly(pfile); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())) + .containsExactly(pfile); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); // the deleted file should show up as a deleted member of workspace root - df = root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("0.5.1", 0, df.length); - - df = root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("0.5.2", 1, df.length); - assertEquals("0.5.3", pfile, df[0]); - - df = root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("0.5.4", 0, df.length); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())) + .containsExactly(pfile); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); // recreate the file pfile.create(createRandomContentsStream(), true, createTestMonitor()); // the deleted file should no longer show up as a deleted member of project - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("0.6", 0, df.length); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("0.7", 0, df.length); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("0.8", 0, df.length); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())).isEmpty(); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); // the deleted file should no longer show up as a deleted member of ws root - df = root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("0.8.1", 0, df.length); - - df = root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("0.8.2", 0, df.length); - - df = root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("0.8.3", 0, df.length); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())).isEmpty(); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); // scrub the project project.delete(true, createTestMonitor()); project.create(createTestMonitor()); project.open(createTestMonitor()); - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("0.9", 0, df.length); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); // test folder IFolder folder = project.getFolder("folder"); @@ -890,42 +868,27 @@ public void testFindDeleted() throws CoreException { file.delete(true, true, createTestMonitor()); // the deleted file should show up as a deleted member - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("1.1", 0, df.length); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("1.2", 1, df.length); - assertEquals("1.3", file, df[0]); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("1.4", 0, df.length); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())) + .containsExactly(file); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); // recreate the file file.create(createRandomContentsStream(), true, createTestMonitor()); // the deleted file should no longer show up as a deleted member - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("1.5", 0, df.length); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("1.6", 0, df.length); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("1.7", 0, df.length); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())).isEmpty(); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); // deleting the folder should bring it back folder.delete(true, true, createTestMonitor()); // the deleted file should show up as a deleted member of project - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("1.8", 0, df.length); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("1.9", 1, df.length); - assertEquals("1.10", file, df[0]); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("1.11", 0, df.length); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())) + .containsExactly(file); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); // create and delete a file where the folder was folderAsFile.create(createRandomContentsStream(), true, createTestMonitor()); @@ -933,29 +896,19 @@ public void testFindDeleted() throws CoreException { folder.create(true, true, createTestMonitor()); // the deleted file should show up as a deleted member of folder - df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("1.12", 1, df.length); - assertEquals("1.13", folderAsFile, df[0]); - - df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("1.14", 2, df.length); - List dfList = Arrays.asList(df); - assertTrue("1.15", dfList.contains(file)); - assertTrue("1.16", dfList.contains(folderAsFile)); - - df = folder.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("1.17", 2, df.length); - dfList = Arrays.asList(df); - assertTrue("1.18", dfList.contains(file)); - assertTrue("1.19", dfList.contains(folderAsFile)); + assertThat(folder.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())) + .containsExactly(folderAsFile); + assertThat(folder.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())) + .containsExactlyInAnyOrder(file, folderAsFile); + assertThat(folder.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())) + .containsExactlyInAnyOrder(file, folderAsFile); // scrub the project project.delete(true, createTestMonitor()); project.create(createTestMonitor()); project.open(createTestMonitor()); - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("1.50", 0, df.length); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); // test a bunch of deletes folder = project.getFolder("folder"); @@ -973,95 +926,49 @@ public void testFindDeleted() throws CoreException { folder.delete(true, true, createTestMonitor()); // under root - df = root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("3.1", 0, df.length); - - df = root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("3.2", 0, df.length); - - df = root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("3.3", 3, df.length); - dfList = Arrays.asList(df); - assertTrue("3.3.1", dfList.contains(file1)); - assertTrue("3.3.2", dfList.contains(file2)); - assertTrue("3.3.3", dfList.contains(file3)); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())) + .containsExactlyInAnyOrder(file1, file2, file3); // under project - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("3.4", 0, df.length); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("3.5", 0, df.length); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("3.6", 3, df.length); - dfList = Arrays.asList(df); - assertTrue("3.6.1", dfList.contains(file1)); - assertTrue("3.6.2", dfList.contains(file2)); - assertTrue("3.6.3", dfList.contains(file3)); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())) + .containsExactlyInAnyOrder(file1, file2, file3); // under folder - df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("3.7", 0, df.length); - - df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("3.8", 2, df.length); - - df = folder.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("3.9", 3, df.length); + assertThat(folder.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); + assertThat(folder.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).hasSize(2); + assertThat(folder.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())).hasSize(3); // under folder2 - df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("3.10", 0, df.length); - - df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("3.11", 1, df.length); - - df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("3.12", 1, df.length); + assertThat(folder2.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); + assertThat(folder2.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).hasSize(1); + assertThat(folder2.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())).hasSize(1); project.delete(true, createTestMonitor()); // once the project is gone, so is all the history for that project // under root - df = root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("4.1", 0, df.length); - - df = root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("4.2", 0, df.length); - - df = root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("4.3", 0, df.length); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())).isEmpty(); // under project - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("4.4", 0, df.length); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("4.5", 0, df.length); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("4.6", 0, df.length); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())).isEmpty(); // under folder - df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("4.7", 0, df.length); - - df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("4.8", 0, df.length); - - df = folder.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("4.9", 0, df.length); + assertThat(folder.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); + assertThat(folder.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(folder.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())).isEmpty(); // under folder2 - df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("4.10", 0, df.length); - - df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("4.11", 0, df.length); - - df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("4.12", 0, df.length); + assertThat(folder2.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); + assertThat(folder2.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(folder2.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())).isEmpty(); } /** @@ -1160,15 +1067,15 @@ public void testModifiedStamp() throws CoreException { IFileState[] history = file.getHistory(createTestMonitor()); // no history yet - assertEquals("1.2", 0, history.length); + assertThat(history).isEmpty(); // save the file's current time stamp - it will be remembered in the file state long fileTimeStamp = file.getLocalTimeStamp(); file.setContents(createRandomContentsStream(), true, true, createTestMonitor()); history = file.getHistory(createTestMonitor()); // one state in the history - assertEquals("2.2", 1, history.length); + assertThat(history).hasSize(1); // the timestamp in the state should match the previous file's timestamp - assertEquals("3.0", fileTimeStamp, history[0].getModificationTime()); + assertThat(history[0].getModificationTime()).isEqualByComparingTo(fileTimeStamp); } /** @@ -1207,9 +1114,9 @@ public void testMoveFolder() throws Exception { file.setContents(createInputStream(contents[1]), true, true, createTestMonitor()); file.setContents(createInputStream(contents[2]), true, true, createTestMonitor()); IFileState[] states = file.getHistory(createTestMonitor()); - assertEquals("1.0", 2, states.length); - assertTrue("1.1", compareContent(createInputStream(contents[1]), states[0].getContents())); - assertTrue("1.2", compareContent(createInputStream(contents[0]), states[1].getContents())); + assertThat(states).hasSize(2).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[1]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[0]), second.getContents())).isTrue()); // Now do the move folder.move(folder2.getFullPath(), true, createTestMonitor()); @@ -1224,15 +1131,15 @@ public void testMoveFolder() throws Exception { // Check the local history of both files states = file.getHistory(createTestMonitor()); - assertEquals("2.0", 2, states.length); - assertTrue("2.1", compareContent(createInputStream(contents[1]), states[0].getContents())); - assertTrue("2.2", compareContent(createInputStream(contents[0]), states[1].getContents())); + assertThat(states).hasSize(2).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[1]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[0]), second.getContents())).isTrue()); states = file2.getHistory(createTestMonitor()); - assertEquals("2.3", 4, states.length); - assertTrue("2.4", compareContent(createInputStream(contents[3]), states[0].getContents())); - assertTrue("2.5", compareContent(createInputStream(contents[2]), states[1].getContents())); - assertTrue("2.6", compareContent(createInputStream(contents[1]), states[2].getContents())); - assertTrue("2.7", compareContent(createInputStream(contents[0]), states[3].getContents())); + assertThat(states).hasSize(4).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[3]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[2]), second.getContents())).isTrue(), + third -> assertThat(compareContent(createInputStream(contents[1]), third.getContents())).isTrue(), + fourth -> assertThat(compareContent(createInputStream(contents[0]), fourth.getContents())).isTrue()); project.delete(true, createTestMonitor()); } @@ -1273,9 +1180,9 @@ public void testMoveProject() throws Exception { file.setContents(createInputStream(contents[1]), true, true, createTestMonitor()); file.setContents(createInputStream(contents[2]), true, true, createTestMonitor()); IFileState[] states = file.getHistory(createTestMonitor()); - assertEquals("1.0", 2, states.length); - assertTrue("1.1", compareContent(createInputStream(contents[1]), states[0].getContents())); - assertTrue("1.2", compareContent(createInputStream(contents[0]), states[1].getContents())); + assertThat(states).hasSize(2).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[1]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[0]), second.getContents())).isTrue()); // Now do the move project.move(IPath.fromOSString("SecondMoveProjectProject"), true, createTestMonitor()); @@ -1292,13 +1199,13 @@ public void testMoveProject() throws Exception { states = file.getHistory(createTestMonitor()); // original file should not remember history when project is moved - assertEquals("2.0", 0, states.length); + assertThat(states).isEmpty(); states = file2.getHistory(createTestMonitor()); - assertEquals("2.3", 4, states.length); - assertTrue("2.4", compareContent(createInputStream(contents[3]), states[0].getContents())); - assertTrue("2.5", compareContent(createInputStream(contents[2]), states[1].getContents())); - assertTrue("2.6", compareContent(createInputStream(contents[1]), states[2].getContents())); - assertTrue("2.7", compareContent(createInputStream(contents[0]), states[3].getContents())); + assertThat(states).hasSize(4).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[3]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[2]), second.getContents())).isTrue(), + third -> assertThat(compareContent(createInputStream(contents[1]), third.getContents())).isTrue(), + fourth -> assertThat(compareContent(createInputStream(contents[0]), fourth.getContents())).isTrue()); project.delete(true, createTestMonitor()); } @@ -1321,12 +1228,12 @@ public void testRemoveAll() throws CoreException { /* Valid Case: Ensure correct number of states available. */ IFileState[] states = file.getHistory(createTestMonitor()); - assertEquals("4.1", ITERATIONS, states.length); + assertThat(states).hasSize(ITERATIONS); /* Remove all states, and verify that no states remain. */ file.clearHistory(createTestMonitor()); states = file.getHistory(createTestMonitor()); - assertEquals("5.0", 0, states.length); + assertThat(states).isEmpty(); /* test remove in a folder -- make sure it does not affect other resources' states*/ IFolder folder = project.getFolder("folder"); @@ -1339,16 +1246,16 @@ public void testRemoveAll() throws CoreException { } states = file.getHistory(createTestMonitor()); - assertEquals("6.2", ITERATIONS, states.length); + assertThat(states).hasSize(ITERATIONS); states = anotherOne.getHistory(createTestMonitor()); - assertEquals("6.3", ITERATIONS, states.length); + assertThat(states).hasSize(ITERATIONS); /* Remove all states, and verify that no states remain. */ project.clearHistory(createTestMonitor()); states = file.getHistory(createTestMonitor()); - assertEquals("7.0", 0, states.length); + assertThat(states).isEmpty(); states = anotherOne.getHistory(createTestMonitor()); - assertEquals("7.1", 0, states.length); + assertThat(states).isEmpty(); /* test remove in a folder -- make sure it does not affect other resources' states*/ IFile aaa = project.getFile("aaa"); @@ -1367,20 +1274,20 @@ public void testRemoveAll() throws CoreException { } states = anotherOne.getHistory(createTestMonitor()); - assertEquals("8.3", ITERATIONS, states.length); + assertThat(states).hasSize(ITERATIONS); states = aaa.getHistory(createTestMonitor()); - assertEquals("8.4", ITERATIONS, states.length); + assertThat(states).hasSize(ITERATIONS); states = ccc.getHistory(createTestMonitor()); - assertEquals("8.5", ITERATIONS, states.length); + assertThat(states).hasSize(ITERATIONS); /* Remove all states, and verify that no states remain. aaa and ccc should not be affected. */ bbb.clearHistory(createTestMonitor()); states = anotherOne.getHistory(createTestMonitor()); - assertEquals("9.1", 0, states.length); + assertThat(states).isEmpty(); states = aaa.getHistory(createTestMonitor()); - assertEquals("9.2", ITERATIONS, states.length); + assertThat(states).hasSize(ITERATIONS); states = ccc.getHistory(createTestMonitor()); - assertEquals("9.3", ITERATIONS, states.length); + assertThat(states).hasSize(ITERATIONS); } /** @@ -1422,9 +1329,9 @@ public void testSimpleCopy() throws Exception { /* Check history for both files. */ IFileState[] states = file.getHistory(null); - assertEquals("4.0", 2, states.length); + assertThat(states).hasSize(2); states = copyFile.getHistory(null); - assertEquals("4.1", 2, states.length); + assertThat(states).hasSize(2); /* Set new contents on second file. Should add two entries to the history store. */ copyFile.setContents(createInputStream(contents[3]), true, true, null); @@ -1433,17 +1340,17 @@ public void testSimpleCopy() throws Exception { /* Check history for both files. */ // Check log for original file. states = file.getHistory(null); - assertEquals("6.0", 2, states.length); - assertTrue("6.1", compareContent(createInputStream(contents[1]), states[0].getContents())); - assertTrue("6.2", compareContent(createInputStream(contents[0]), states[1].getContents())); + assertThat(states).hasSize(2).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[1]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[0]), second.getContents())).isTrue()); // Check log for copy. states = copyFile.getHistory(null); - assertEquals("6.3", 4, states.length); - assertTrue("6.4", compareContent(createInputStream(contents[3]), states[0].getContents())); - assertTrue("6.5", compareContent(createInputStream(contents[2]), states[1].getContents())); - assertTrue("6.6", compareContent(createInputStream(contents[1]), states[2].getContents())); - assertTrue("6.7", compareContent(createInputStream(contents[0]), states[3].getContents())); + assertThat(states).hasSize(4).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[3]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[2]), second.getContents())).isTrue(), + third -> assertThat(compareContent(createInputStream(contents[1]), third.getContents())).isTrue(), + fourth -> assertThat(compareContent(createInputStream(contents[0]), fourth.getContents())).isTrue()); } /** @@ -1487,9 +1394,9 @@ public void testSimpleMove() throws Exception { /* Check history for both files. */ IFileState[] states = file.getHistory(null); - assertEquals("4.0", 2, states.length); + assertThat(states).hasSize(2); states = moveFile.getHistory(null); - assertEquals("4.1", 2, states.length); + assertThat(states).hasSize(2); /* Set new contents on moved file. Should add two entries to the history store. */ moveFile.setContents(createInputStream(contents[3]), true, true, null); @@ -1498,17 +1405,17 @@ public void testSimpleMove() throws Exception { /* Check history for both files. */ // Check log for original file. states = file.getHistory(null); - assertEquals("6.0", 2, states.length); - assertTrue("6.1", compareContent(createInputStream(contents[1]), states[0].getContents())); - assertTrue("6.2", compareContent(createInputStream(contents[0]), states[1].getContents())); + assertThat(states).hasSize(2).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[1]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[0]), second.getContents())).isTrue()); // Check log for moved file. states = moveFile.getHistory(null); - assertEquals("6.3", 4, states.length); - assertTrue("6.4", compareContent(createInputStream(contents[3]), states[0].getContents())); - assertTrue("6.5", compareContent(createInputStream(contents[2]), states[1].getContents())); - assertTrue("6.6", compareContent(createInputStream(contents[1]), states[2].getContents())); - assertTrue("6.7", compareContent(createInputStream(contents[0]), states[3].getContents())); + assertThat(states).hasSize(4).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[3]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[2]), second.getContents())).isTrue(), + third -> assertThat(compareContent(createInputStream(contents[1]), third.getContents())).isTrue(), + fourth -> assertThat(compareContent(createInputStream(contents[0]), fourth.getContents())).isTrue()); } /** @@ -1543,20 +1450,19 @@ public void testSimpleUse() throws Exception { /* Ensure two entries are available for the file, and that content matches. */ IFileState[] states = file.getHistory(createTestMonitor()); - assertEquals("3.0", 2, states.length); - assertTrue("3.1.1", compareContent(createInputStream(contents[1]), states[0].getContents())); - assertTrue("3.1.2", compareContent(createInputStream(contents[0]), states[1].getContents())); + assertThat(states).hasSize(2).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[1]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[0]), second.getContents())).isTrue()); /* Delete the file. Should add an entry to the store. */ file.delete(true, true, createTestMonitor()); /* Ensure three entries are available for the file, and that content matches. */ states = file.getHistory(createTestMonitor()); - assertEquals("5.0", 3, states.length); - assertTrue("5.1.1", compareContent(createInputStream(contents[2]), states[0].getContents())); - assertTrue("5.1.2", compareContent(createInputStream(contents[1]), states[1].getContents())); - assertTrue("5.1.3", compareContent(createInputStream(contents[0]), states[2].getContents())); - + assertThat(states).hasSize(3).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[2]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[1]), second.getContents())).isTrue(), + third -> assertThat(compareContent(createInputStream(contents[0]), third.getContents())).isTrue()); /* Roll file back to first version, and ensure that content matches. */ states = file.getHistory(createTestMonitor()); // Create the file with the contents from one of the states. @@ -1565,24 +1471,24 @@ public void testSimpleUse() throws Exception { // Check history store. states = file.getHistory(createTestMonitor()); - assertEquals("6.0", 3, states.length); - assertTrue("6.1.1", compareContent(createInputStream(contents[2]), states[0].getContents())); - assertTrue("6.1.2", compareContent(createInputStream(contents[1]), states[1].getContents())); - assertTrue("6.1.3", compareContent(createInputStream(contents[0]), states[2].getContents())); + assertThat(states).hasSize(3).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[2]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[1]), second.getContents())).isTrue(), + third -> assertThat(compareContent(createInputStream(contents[0]), third.getContents())).isTrue()); // Check file contents. - assertTrue("6.2", compareContent(createInputStream(contents[2]), file.getContents(false))); + assertThat(compareContent(createInputStream(contents[2]), file.getContents(false))).isTrue(); /* Set new contents on the file. Should add an entry to the history store. */ file.setContents(createInputStream(contents[1]), true, true, null); /* Ensure four entries are available for the file, and that entries match. */ states = file.getHistory(createTestMonitor()); - assertEquals("8.0", 4, states.length); - assertTrue("8.1.1", compareContent(createInputStream(contents[2]), states[0].getContents())); - assertTrue("8.1.2", compareContent(createInputStream(contents[2]), states[1].getContents())); - assertTrue("8.1.3", compareContent(createInputStream(contents[1]), states[2].getContents())); - assertTrue("8.1.4", compareContent(createInputStream(contents[0]), states[3].getContents())); + assertThat(states).hasSize(4).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[2]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[2]), second.getContents())).isTrue(), + third -> assertThat(compareContent(createInputStream(contents[1]), third.getContents())).isTrue(), + fourth -> assertThat(compareContent(createInputStream(contents[0]), fourth.getContents())).isTrue()); /* Roll file back to third version, and ensure that content matches. */ states = file.getHistory(createTestMonitor()); @@ -1591,15 +1497,15 @@ public void testSimpleUse() throws Exception { // Check history log. states = file.getHistory(createTestMonitor()); - assertEquals("9.0", 5, states.length); - assertTrue("9.1.1", compareContent(createInputStream(contents[1]), states[0].getContents())); - assertTrue("9.1.2", compareContent(createInputStream(contents[2]), states[1].getContents())); - assertTrue("9.1.3", compareContent(createInputStream(contents[2]), states[2].getContents())); - assertTrue("9.1.4", compareContent(createInputStream(contents[1]), states[3].getContents())); - assertTrue("9.1.5", compareContent(createInputStream(contents[0]), states[4].getContents())); + assertThat(states).hasSize(5).satisfiesExactly( + first -> assertThat(compareContent(createInputStream(contents[1]), first.getContents())).isTrue(), + second -> assertThat(compareContent(createInputStream(contents[2]), second.getContents())).isTrue(), + third -> assertThat(compareContent(createInputStream(contents[2]), third.getContents())).isTrue(), + fourth -> assertThat(compareContent(createInputStream(contents[1]), fourth.getContents())).isTrue(), + fifth -> assertThat(compareContent(createInputStream(contents[0]), fifth.getContents())).isTrue()); // Check file contents. - assertTrue("9.2", compareContent(createInputStream(contents[1]), file.getContents(false))); + assertThat(compareContent(createInputStream(contents[1]), file.getContents(false))).isTrue(); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/RefreshLocalTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/RefreshLocalTest.java index b1ff1cd802e..816bb0989b8 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/RefreshLocalTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/RefreshLocalTest.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.core.tests.internal.localstore; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.internal.localstore.LocalStoreTestUtil.createTree; import static org.eclipse.core.tests.internal.localstore.LocalStoreTestUtil.getTree; @@ -300,7 +301,7 @@ public void testSimpleRefresh() throws Throwable { assertFalse(folder.exists()); folder.refreshLocal(IResource.DEPTH_INFINITE, null); assertTrue(folder.exists()); - assertEquals(((Resource) folder).countResources(IResource.DEPTH_INFINITE, false), getTree(target).length + 1); + assertThat(getTree(target)).hasSize(((Resource) folder).countResources(IResource.DEPTH_INFINITE, false) - 1); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/SafeChunkyInputOutputStreamTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/SafeChunkyInputOutputStreamTest.java index 756b294ad7f..f283060f58d 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/SafeChunkyInputOutputStreamTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/SafeChunkyInputOutputStreamTest.java @@ -17,7 +17,6 @@ import static org.eclipse.core.tests.harness.FileSystemHelper.getRandomLocation; import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomString; import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromFileSystem; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; @@ -92,7 +91,7 @@ public void testBufferLimit() throws Exception { // read chunks try (SafeChunkyInputStream input = new SafeChunkyInputStream(target)) { byte[] read = new byte[chunk.length]; - assertEquals(chunk.length, input.read(read)); + assertThat(chunk).hasSize(input.read(read)); assertThat(read).isEqualTo(chunk); } Workspace.clear(target); // make sure there was nothing here before @@ -163,19 +162,16 @@ public void testFailure() throws Exception { // read chunks try (SafeChunkyInputStream input = new SafeChunkyInputStream(target)) { byte[] read1 = new byte[chunk1.length]; - // byte[] read2 = new byte[chunk2.length]; byte[] read3 = new byte[chunk3.length]; byte[] read4 = new byte[chunk4.length]; byte[] read5 = new byte[chunk5.length]; byte[] read6 = new byte[fakeEnd.length + chunk6.length]; - assertEquals(chunk1.length, input.read(read1)); - // assert("3.1", input.read(read2) == chunk2.length); - assertEquals(chunk3.length, input.read(read3)); - assertEquals(chunk4.length, input.read(read4)); - assertEquals(chunk5.length, input.read(read5)); - assertEquals((fakeEnd.length + chunk6.length), input.read(read6)); + assertThat(chunk1).hasSize(input.read(read1)); + assertThat(chunk3).hasSize(input.read(read3)); + assertThat(chunk4).hasSize(input.read(read4)); + assertThat(chunk5).hasSize(input.read(read5)); + assertThat(chunk6).hasSize(input.read(read6) - fakeEnd.length); assertThat(read1).isEqualTo(chunk1); - // assert("3.7", compare(chunk2, read2)); assertThat(read3).isEqualTo(chunk3); assertThat(read4).isEqualTo(chunk4); assertThat(read5).isEqualTo(chunk5); @@ -239,11 +235,11 @@ public void testSimple() throws Exception { byte[] read3 = new byte[chunk3.length]; byte[] read4 = new byte[chunk4.length]; byte[] read5 = new byte[chunk5.length]; - assertEquals(chunk1.length, input.read(read1)); - assertEquals(chunk2.length, input.read(read2)); - assertEquals(chunk3.length, input.read(read3)); - assertEquals(chunk4.length, input.read(read4)); - assertEquals(chunk5.length, input.read(read5)); + assertThat(chunk1).hasSize(input.read(read1)); + assertThat(chunk2).hasSize(input.read(read2)); + assertThat(chunk3).hasSize(input.read(read3)); + assertThat(chunk4).hasSize(input.read(read4)); + assertThat(chunk5).hasSize(input.read(read5)); assertThat(read1).isEqualTo(chunk1); assertThat(read2).isEqualTo(chunk2); assertThat(read3).isEqualTo(chunk3); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectPreferencesTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectPreferencesTest.java index 1557bce3e9f..9fedf13762a 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectPreferencesTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectPreferencesTest.java @@ -1144,12 +1144,11 @@ public void testChildrenNamesAgainstInitialize() throws BackingStoreException, C Preferences node = new ProjectScope(project1).getNode(""); String[] childrenNames = node.childrenNames(); - assertEquals(2, childrenNames.length); - assertEquals(nodeA, childrenNames[1]); + assertThat(childrenNames).hasSize(2); + assertThat(childrenNames[1]).isEqualTo(nodeA); node = node.node(nodeA); childrenNames = node.childrenNames(); - assertEquals(1, childrenNames.length); - assertEquals(nodeB, childrenNames[0]); + assertThat(childrenNames).containsExactly(nodeB); project1.delete(true, createTestMonitor()); project2.delete(true, createTestMonitor()); @@ -1184,8 +1183,7 @@ public void testChildrenNamesAgainstLoad() throws BackingStoreException, CoreExc Preferences node = new ProjectScope(project1).getNode(nodeA); String[] childrenNames = node.childrenNames(); - assertEquals(1, childrenNames.length); - assertEquals(nodeB, childrenNames[0]); + assertThat(childrenNames).containsExactly(nodeB); project1.delete(true, createTestMonitor()); project2.delete(true, createTestMonitor()); @@ -1220,7 +1218,7 @@ public void testClear() throws BackingStoreException, CoreException { Preferences node = new ProjectScope(project1).getNode(nodeA).node(nodeB); node.clear(); - assertEquals(0, node.keys().length); + assertThat(node.keys()).isEmpty(); assertNull(node.get(key, null)); project1.delete(true, createTestMonitor()); @@ -1290,8 +1288,7 @@ public void testKeys() throws BackingStoreException, CoreException { Preferences node = new ProjectScope(project1).getNode(nodeA).node(nodeB); String[] keys = node.keys(); - assertEquals(1, keys.length); - assertEquals(key, keys[0]); + assertThat(keys).containsExactly(key); project1.delete(true, createTestMonitor()); project2.delete(true, createTestMonitor()); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WorkspacePreferencesTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WorkspacePreferencesTest.java index d771fd3f8ec..57dfcec124e 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WorkspacePreferencesTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WorkspacePreferencesTest.java @@ -96,7 +96,7 @@ public void testSetPreferences() throws CoreException { assertEquals("2.2", expectedList, actualList); preferences.setValue(ResourcesPlugin.PREF_BUILD_ORDER, ""); - assertTrue("2.3", workspace.getDescription().getBuildOrder().length == 0); + assertThat(workspace.getDescription().getBuildOrder()).isEmpty(); long snapshotInterval = 800000000L; preferences.setValue(ResourcesPlugin.PREF_SNAPSHOT_INTERVAL, snapshotInterval); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/utils/ObjectMapTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/utils/ObjectMapTest.java index fb710bcc1a6..7f3547bbf31 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/utils/ObjectMapTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/utils/ObjectMapTest.java @@ -14,6 +14,7 @@ *******************************************************************************/ package org.eclipse.core.tests.internal.utils; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -149,7 +150,7 @@ private ObjectMap populateMap(Object[] values) { values[i] = Long.valueOf(System.currentTimeMillis()); map.put(Integer.valueOf(i), values[i]); } - assertEquals("#populateMap", values.length, map.size()); + assertThat(values).hasSize(map.size()); return map; } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/TestUtil.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/TestUtil.java index 427422b70bb..44a8bee1479 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/TestUtil.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/TestUtil.java @@ -14,6 +14,7 @@ *******************************************************************************/ package org.eclipse.core.tests.internal.watson; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -72,7 +73,7 @@ static protected void assertEqualTrees(String msg, ElementTree expected, Element /* get the children */ IPath[] expectedChildren = expected.getChildren(path); IPath[] actualChildren = actual.getChildren(path); - assertEquals("Number of children", expectedChildren.length, actualChildren.length); + assertThat(actualChildren).describedAs("Number of children").hasSameSizeAs(expectedChildren); int newDepth = depth; if (depth != ElementTreeWriter.D_INFINITE) { @@ -110,29 +111,29 @@ static protected void assertTreeStructure(ElementTree tree) { assertHasPaths(tree, getTreePaths()); IPath[] children = tree.getChildren(IPath.ROOT); - assertEquals(1, children.length); + assertThat(children).hasSize(1); /* solution children */ children = tree.getChildren(children[0]); - assertEquals(2, children.length); - assertEquals(0, tree.getChildren(project1).length); + assertThat(children).hasSize(2); + assertThat(tree.getChildren(project1)).isEmpty(); /* project2 children */ children = tree.getChildren(children[1]); - assertEquals(3, children.length); - assertEquals(0, tree.getChildren(file1).length); - assertEquals(0, tree.getChildren(folder2).length); + assertThat(children).hasSize(3); + assertThat(tree.getChildren(file1)).isEmpty(); + assertThat(tree.getChildren(folder2)).isEmpty(); /* folder1 children */ children = tree.getChildren(children[1]); - assertEquals(3, children.length); - assertEquals(0, tree.getChildren(file2).length); - assertEquals(0, tree.getChildren(folder4).length); + assertThat(children).hasSize(3); + assertThat(tree.getChildren(file2)).isEmpty(); + assertThat(tree.getChildren(folder4)).isEmpty(); /* folder3 children */ children = tree.getChildren(children[1]); - assertEquals(1, children.length); - assertEquals(0, tree.getChildren(file3).length); + assertThat(children).hasSize(1); + assertThat(tree.getChildren(file3)).isEmpty(); } static ElementTree createTestElementTree() { @@ -320,7 +321,7 @@ static protected void scramble(Object[] first) { * arrays undergo the same permutation. */ static protected void scramble(Object[] first, Object[] second) { - assertTrue(first.length == second.length); + assertThat(first).hasSameSizeAs(second); Random random = new Random(System.currentTimeMillis()); final int len = first.length; diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/CharsetTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/CharsetTest.java index c063c75c556..92e4ed2a7da 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/CharsetTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/CharsetTest.java @@ -15,6 +15,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.PI_RESOURCES; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.assertDoesNotExistInWorkspace; @@ -141,13 +142,8 @@ private boolean isSet(int mask) { boolean ignoreEvent() { // to make testing easier, we allow events from the main or other thread to be ignored - if (isSet(IGNORE_BACKGROUND_THREAD) && Thread.currentThread() != creationThread) { - return true; - } - if (isSet(IGNORE_CREATION_THREAD) && Thread.currentThread() == creationThread) { - return true; - } - return false; + return (isSet(IGNORE_BACKGROUND_THREAD) && Thread.currentThread() != creationThread) + || (isSet(IGNORE_CREATION_THREAD) && Thread.currentThread() == creationThread); } @Override @@ -947,7 +943,7 @@ public void testDefaults() throws CoreException { assertEquals(ResourcesPlugin.getEncoding(), project.getDefaultCharset(false)); IMarker[] markers = project.findMarkers(ValidateProjectEncoding.MARKER_TYPE, false, IResource.DEPTH_ONE); - assertEquals("No missing encoding marker should be set", 0, markers.length); + assertThat(markers).as("check no missing encoding markers").isEmpty(); project.setDefaultCharset(null, createTestMonitor()); assertEquals(null, project.getDefaultCharset(false)); @@ -955,7 +951,7 @@ public void testDefaults() throws CoreException { waitForEncodingRelatedJobs(testName.getMethodName()); markers = project.findMarkers(ValidateProjectEncoding.MARKER_TYPE, false, IResource.DEPTH_ONE); - assertEquals("Missing encoding marker should be set", 1, markers.length); + assertThat(markers).as("check missing encoding markers").hasSize(1); createInWorkspace(new IResource[] {file1, file2, file3}); // project and children should be using the workspace's default now @@ -965,7 +961,7 @@ public void testDefaults() throws CoreException { // sets workspace default charset workspace.getRoot().setDefaultCharset("FOO", createTestMonitor()); markers = project.findMarkers(ValidateProjectEncoding.MARKER_TYPE, false, IResource.DEPTH_ONE); - assertEquals("Missing encoding marker should be still set", 1, markers.length); + assertThat(markers).as("check missing encoding markers").hasSize(1); assertCharsetIs("2.0", "FOO", new IResource[] {workspace.getRoot(), project, file1, folder1, file2, folder2, file3}, true); assertCharsetIs("2.1", null, new IResource[] {project, file1, folder1, file2, folder2, file3}, false); @@ -975,7 +971,7 @@ public void testDefaults() throws CoreException { waitForEncodingRelatedJobs(testName.getMethodName()); markers = project.findMarkers(ValidateProjectEncoding.MARKER_TYPE, false, IResource.DEPTH_ONE); - assertEquals("No missing encoding marker should be set", 0, markers.length); + assertThat(markers).as("check no missing encoding markers").isEmpty(); assertCharsetIs("3.0", "BAR", new IResource[] {project, file1, folder1, file2, folder2, file3}, true); assertCharsetIs("3.1", null, new IResource[] {file1, folder1, file2, folder2, file3}, false); @@ -1103,7 +1099,7 @@ public void testDeltaOnPreferenceChanges() throws IOException, CoreException { assertTrue("2.2 " + backgroundVerifier.getMessage(), backgroundVerifier.isDeltaValid()); IMarker[] markers = project.findMarkers(ValidateProjectEncoding.MARKER_TYPE, false, IResource.DEPTH_ONE); - assertEquals("No missing encoding marker should be set", 0, markers.length); + assertThat(markers).as("check no missing enconding markers").isEmpty(); backgroundVerifier.reset(); backgroundVerifier.addExpectedChange( @@ -1120,7 +1116,7 @@ public void testDeltaOnPreferenceChanges() throws IOException, CoreException { assertTrue("3.2 " + backgroundVerifier.getMessage(), backgroundVerifier.isDeltaValid()); markers = project.findMarkers(ValidateProjectEncoding.MARKER_TYPE, false, IResource.DEPTH_ONE); - assertEquals("Missing encoding marker should be set", 1, markers.length); + assertThat(markers).as("check missing encoding markers").hasSize(1); } finally { getWorkspace().removeResourceChangeListener(backgroundVerifier); clearAllEncodings(project); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/FilteredResourceTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/FilteredResourceTest.java index 12fb7c87a33..5bbec61b275 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/FilteredResourceTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/FilteredResourceTest.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.core.tests.resources; +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.harness.FileSystemHelper.getRandomLocation; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInFileSystem; @@ -20,10 +22,7 @@ import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import static org.eclipse.core.tests.resources.ResourceTestUtil.createUniqueString; import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromWorkspace; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -151,21 +150,23 @@ public void testCreateFilterOnFolder() throws CoreException { existingProject.open(createTestMonitor()); IResourceFilterDescription[] filters = existingFolderInExistingProject.getFilters(); - - assertEquals("1.4", filters.length, 1); - assertEquals("1.5", filters[0].getFileInfoMatcherDescription().getId(), REGEX_FILTER_PROVIDER); - assertEquals("1.6", filters[0].getFileInfoMatcherDescription().getArguments(), "foo"); - assertEquals("1.7", filters[0].getType(), IResourceFilterDescription.INCLUDE_ONLY | IResourceFilterDescription.FILES | IResourceFilterDescription.FOLDERS); - assertEquals("1.8", filters[0].getResource(), existingFolderInExistingProject); + assertThat(filters).hasSize(1).satisfiesExactly(filter -> { + assertThat(filter.getFileInfoMatcherDescription().getId()).as("provider").isEqualTo(REGEX_FILTER_PROVIDER); + assertThat(filter.getFileInfoMatcherDescription().getArguments()).as("arguments").isEqualTo("foo"); + assertThat(filter.getType()).as("type").isEqualTo(IResourceFilterDescription.INCLUDE_ONLY + | IResourceFilterDescription.FILES | IResourceFilterDescription.FOLDERS); + assertThat(filter.getResource()).as("resource").isEqualTo(existingFolderInExistingProject); + }); IResource members[] = existingFolderInExistingProject.members(); - assertEquals("2.0", members.length, 1); - assertEquals("2.1", members[0].getType(), IResource.FILE); - assertEquals("2.2", members[0].getName(), "foo"); + assertThat(members).hasSize(1).satisfiesExactly(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(member.getName()).as("name").isEqualTo("foo"); + }); IWorkspace workspace = existingProject.getWorkspace(); - assertTrue("2.3", !workspace.validateFiltered(bar).isOK()); - assertTrue("2.4", workspace.validateFiltered(foo).isOK()); + assertThat(bar).matches(it -> !workspace.validateFiltered(it).isOK(), "is filtered"); + assertThat(foo).matches(it -> workspace.validateFiltered(it).isOK(), "is not filtered"); } /** @@ -189,24 +190,23 @@ public void testCreateFilterOnProject() throws CoreException { existingProject.open(createTestMonitor()); IResourceFilterDescription[] filters = existingProject.getFilters(); - assertEquals("1.4", filters.length, 1); - assertEquals("1.5", filters[0].getFileInfoMatcherDescription().getId(), REGEX_FILTER_PROVIDER); - assertEquals("1.6", filters[0].getFileInfoMatcherDescription().getArguments(), "foo"); - assertEquals("1.7", filters[0].getType(), IResourceFilterDescription.INCLUDE_ONLY | IResourceFilterDescription.FOLDERS); - assertEquals("1.8", filters[0].getResource(), existingProject); + assertThat(filters).hasSize(1).satisfiesExactly(filter -> { + assertThat(filter.getFileInfoMatcherDescription().getId()).as("provider").isEqualTo(REGEX_FILTER_PROVIDER); + assertThat(filter.getFileInfoMatcherDescription().getArguments()).as("arguments").isEqualTo("foo"); + assertThat(filter.getType()).as("type") + .isEqualTo(IResourceFilterDescription.INCLUDE_ONLY | IResourceFilterDescription.FOLDERS); + assertThat(filter.getResource()).as("resource").isEqualTo(existingProject); + }); IResource members[] = existingProject.members(); - assertEquals("2.0", members.length, 3); - for (IResource member : members) { - if (member.getType() == IResource.FOLDER) { - assertEquals("2.1", member.getType(), IResource.FOLDER); - assertEquals("2.2", member.getName(), "foo"); - } - } + assertThat(members).hasSize(3).filteredOn(member -> member.getType() == IResource.FOLDER).allSatisfy(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FOLDER); + assertThat(member.getName()).as("name").isEqualTo("foo"); + }); IWorkspace workspace = existingProject.getWorkspace(); - assertTrue("2.1", !workspace.validateFiltered(bar).isOK()); - assertTrue("2.2", workspace.validateFiltered(foo).isOK()); + assertThat(bar).matches(it -> !workspace.validateFiltered(it).isOK(), "is filtered"); + assertThat(foo).matches(it -> workspace.validateFiltered(it).isOK(), "is not filtered"); } /** @@ -237,20 +237,23 @@ public void testCreateFilterOnLinkedFolder() throws CoreException { IResourceFilterDescription[] filters = folder.getFilters(); - assertEquals("1.4", filters.length, 1); - assertEquals("1.5", filters[0].getFileInfoMatcherDescription().getId(), REGEX_FILTER_PROVIDER); - assertEquals("1.6", filters[0].getFileInfoMatcherDescription().getArguments(), "foo"); - assertEquals("1.7", filters[0].getType(), IResourceFilterDescription.INCLUDE_ONLY | IResourceFilterDescription.FILES); - assertEquals("1.8", filters[0].getResource(), folder); + assertThat(filters).hasSize(1).satisfiesExactly(filter -> { + assertThat(filter.getFileInfoMatcherDescription().getId()).as("provider").isEqualTo(REGEX_FILTER_PROVIDER); + assertThat(filter.getFileInfoMatcherDescription().getArguments()).as("arguments").isEqualTo("foo"); + assertThat(filter.getType()).as("type") + .isEqualTo(IResourceFilterDescription.INCLUDE_ONLY | IResourceFilterDescription.FILES); + assertThat(filter.getResource()).as("resource").isEqualTo(folder); + }); IResource members[] = folder.members(); - assertEquals("2.0", members.length, 1); - assertEquals("2.1", members[0].getType(), IResource.FILE); - assertEquals("2.2", members[0].getName(), "foo"); + assertThat(members).hasSize(1).satisfiesExactly(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(member.getName()).as("name").isEqualTo("foo"); + }); IWorkspace workspace = existingProject.getWorkspace(); - assertTrue("2.1", !workspace.validateFiltered(bar).isOK()); - assertTrue("2.2", workspace.validateFiltered(foo).isOK()); + assertThat(bar).matches(it -> !workspace.validateFiltered(it).isOK(), "is filtered"); + assertThat(foo).matches(it -> workspace.validateFiltered(it).isOK(), "is not filtered"); } /** @@ -274,104 +277,122 @@ public void testCreateFilterOnLinkedFolderAndTarget() throws Exception { createTestMonitor()); IResource members[] = folder.members(); - assertEquals("1.2", members.length, 0); + assertThat(members).isEmpty(); members = existingFolderInExistingFolder.members(); - assertEquals("1.4", members.length, 0); + assertThat(members).isEmpty(); IFile newFile = existingFolderInExistingFolder.getFile("foo.cpp"); - assertTrue("1.5", newFile.getLocation().toFile().createNewFile()); + assertThat(newFile.getLocation().toFile().createNewFile()) + .withFailMessage("file creation not successful: %s", newFile).isTrue(); existingFolderInExistingFolder.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); members = existingFolderInExistingFolder.members(); - assertEquals("1.9", members.length, 1); - assertEquals("2.0", members[0].getType(), IResource.FILE); - assertEquals("2.1", members[0].getName(), "foo.cpp"); + assertThat(members).hasSize(1).satisfiesExactly(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(member.getName()).as("name").isEqualTo("foo.cpp"); + }); members = folder.members(); - assertEquals("2.3", members.length, 0); + assertThat(members).isEmpty(); newFile = existingFolderInExistingFolder.getFile("foo.h"); - assertTrue("2.5", newFile.getLocation().toFile().createNewFile()); + assertThat(newFile.getLocation().toFile().createNewFile()) + .withFailMessage("file creation not successful: %s", newFile).isTrue(); existingFolderInExistingFolder.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); members = existingFolderInExistingFolder.members(); - assertEquals("2.9", members.length, 1); - assertEquals("3.0", members[0].getType(), IResource.FILE); - assertEquals("3.1", members[0].getName(), "foo.cpp"); + assertThat(members).hasSize(1).satisfiesExactly(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(member.getName()).as("name").isEqualTo("foo.cpp"); + }); members = folder.members(); - assertEquals("3.3", members.length, 0); + assertThat(members).isEmpty(); folder.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); members = existingFolderInExistingFolder.members(); - assertEquals("3.9", members.length, 1); - assertEquals("4.0", members[0].getType(), IResource.FILE); - assertEquals("4.1", members[0].getName(), "foo.cpp"); + assertThat(members).hasSize(1).satisfiesExactly(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(member.getName()).as("name").isEqualTo("foo.cpp"); + }); members = folder.members(); - assertEquals("4.3", members.length, 1); - assertEquals("4.4", members[0].getType(), IResource.FILE); - assertEquals("4.5", members[0].getName(), "foo.h"); + assertThat(members).hasSize(1).satisfiesExactly(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(member.getName()).as("name").isEqualTo("foo.h"); + }); // create a file that shows under both newFile = existingFolderInExistingFolder.getFile("foo.text"); - assertTrue("5.5", newFile.getLocation().toFile().createNewFile()); + assertThat(newFile.getLocation().toFile().createNewFile()) + .withFailMessage("file creation not successful: %s", newFile).isTrue(); existingFolderInExistingFolder.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); members = existingFolderInExistingFolder.members(); - assertEquals("5.9", members.length, 2); - assertEquals("6.0", members[0].getType(), IResource.FILE); - assertEquals("6.1", members[0].getName(), "foo.cpp"); - assertEquals("6.2", members[1].getType(), IResource.FILE); - assertEquals("6.3", members[1].getName(), "foo.text"); + assertThat(members).hasSize(2).satisfiesExactly(firstMember -> { + assertThat(firstMember.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(firstMember.getName()).as("name").isEqualTo("foo.cpp"); + }, secondMember -> { + assertThat(secondMember.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(secondMember.getName()).as("name").isEqualTo("foo.text"); + }); members = folder.members(); - assertEquals("6.5", members.length, 2); - assertEquals("6.6", members[0].getType(), IResource.FILE); - assertEquals("6.7", members[0].getName(), "foo.h"); - assertEquals("6.8", members[1].getType(), IResource.FILE); - assertEquals("6.9", members[1].getName(), "foo.text"); + assertThat(members).hasSize(2).satisfiesExactly(firstMember -> { + assertThat(firstMember.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(firstMember.getName()).as("name").isEqualTo("foo.h"); + }, secondMember -> { + assertThat(secondMember.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(secondMember.getName()).as("name").isEqualTo("foo.text"); + }); // delete the common file newFile.delete(true, createTestMonitor()); members = existingFolderInExistingFolder.members(); - assertEquals("7.2", members.length, 1); - assertEquals("7.3", members[0].getType(), IResource.FILE); - assertEquals("7.4", members[0].getName(), "foo.cpp"); + assertThat(members).hasSize(1).satisfiesExactly(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(member.getName()).as("name").isEqualTo("foo.cpp"); + }); members = folder.members(); - assertEquals("7.6", members.length, 1); - assertEquals("7.7", members[0].getType(), IResource.FILE); - assertEquals("7.8", members[0].getName(), "foo.h"); + assertThat(members).hasSize(1).satisfiesExactly(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(member.getName()).as("name").isEqualTo("foo.h"); + }); // remove the first filter filterDescription2.delete(0, createTestMonitor()); members = existingFolderInExistingFolder.members(); - assertEquals("8.2", members.length, 2); - assertEquals("8.3", members[0].getType(), IResource.FILE); - assertEquals("8.4", members[0].getName(), "foo.cpp"); - assertEquals("8.4.1", members[1].getType(), IResource.FILE); - assertEquals("8.4.2", members[1].getName(), "foo.h"); + assertThat(members).hasSize(2).satisfiesExactly(firstMember -> { + assertThat(firstMember.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(firstMember.getName()).as("name").isEqualTo("foo.cpp"); + }, secondMember -> { + assertThat(secondMember.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(secondMember.getName()).as("name").isEqualTo("foo.h"); + }); members = folder.members(); - assertEquals("8.6", members.length, 1); - assertEquals("8.7", members[0].getType(), IResource.FILE); - assertEquals("8.8", members[0].getName(), "foo.h"); + assertThat(members).hasSize(1).satisfiesExactly(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(member.getName()).as("name").isEqualTo("foo.h"); + }); // add the filter again existingFolderInExistingFolder.createFilter( IResourceFilterDescription.EXCLUDE_ALL | IResourceFilterDescription.FILES, matcherDescription2, 0, createTestMonitor()); members = existingFolderInExistingFolder.members(); - assertEquals("9.2", members.length, 1); - assertEquals("9.3", members[0].getType(), IResource.FILE); - assertEquals("9.4", members[0].getName(), "foo.cpp"); + assertThat(members).hasSize(1).satisfiesExactly(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(member.getName()).as("name").isEqualTo("foo.cpp"); + }); members = folder.members(); - assertEquals("9.6", members.length, 1); - assertEquals("9.7", members[0].getType(), IResource.FILE); - assertEquals("9.8", members[0].getName(), "foo.h"); + assertThat(members).hasSize(1).satisfiesExactly(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(member.getName()).as("name").isEqualTo("foo.h"); + }); } @Test @@ -387,8 +408,8 @@ public void testIResource_isFiltered() throws CoreException { createTestMonitor()); IWorkspace workspace = existingProject.getWorkspace(); - assertTrue("1.0", workspace.validateFiltered(folder).isOK()); - assertTrue("1.1", workspace.validateFiltered(file).isOK()); + assertThat(folder).matches(it -> workspace.validateFiltered(it).isOK(), "is not filtered"); + assertThat(folder).matches(it -> workspace.validateFiltered(it).isOK(), "is not filtered"); } /** @@ -418,9 +439,10 @@ public void testCreateFilterOnLinkedFolderAndTarget2() throws Exception { IFile newFile = existingFolderInExistingFolder.getFile("foo.cpp"); createInWorkspace(newFile); IResource[] members = existingFolderInExistingFolder.members(); - assertEquals("1.9", 1, members.length); - assertEquals("2.0", IResource.FILE, members[0].getType()); - assertEquals("2.1", "foo.cpp", members[0].getName()); + assertThat(members).hasSize(1).satisfiesExactly(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(member.getName()).as("name").isEqualTo("foo.cpp"); + }); // Create a 'foo.h' under folder newFile = folder.getFile("foo.h"); @@ -429,31 +451,35 @@ public void testCreateFilterOnLinkedFolderAndTarget2() throws Exception { // // Refreshing restores sanity (hides the .cpp files)... // folder.refreshLocal(IResource.DEPTH_INFINITE, getMonitor()); members = folder.members(); - assertEquals("4.3", 1, members.length); - assertEquals("4.4", IResource.FILE, members[0].getType()); - assertEquals("4.5", "foo.h", members[0].getName()); + assertThat(members).hasSize(1).satisfiesExactly(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(member.getName()).as("name").isEqualTo("foo.h"); + }); // Check it hasn't appeared in existingFolder... // // Refresh restores sanity... // existingFolderInExistingFolder.refreshLocal(IResource.DEPTH_INFINITE, // getMonitor()); members = existingFolderInExistingFolder.members(); - assertEquals("2.9", 1, members.length); - assertEquals("3.0", IResource.FILE, members[0].getType()); - assertEquals("3.1", "foo.cpp", members[0].getName()); + assertThat(members).hasSize(1).allSatisfy(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(member.getName()).as("name").isEqualTo("foo.cpp"); + }); // And refreshing doesn't change things existingFolderInExistingFolder.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); members = existingFolderInExistingFolder.members(); - assertEquals("2.9", 1, members.length); - assertEquals("3.0", IResource.FILE, members[0].getType()); - assertEquals("3.1", "foo.cpp", members[0].getName()); + assertThat(members).hasSize(1).allSatisfy(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(member.getName()).as("name").isEqualTo("foo.cpp"); + }); // Check modifying foo.h doesn't make it appear modifyFileInWorkspace(folder.getFile("foo.h")); members = existingFolderInExistingFolder.members(); - assertEquals("2.9", 1, members.length); - assertEquals("3.0", IResource.FILE, members[0].getType()); - assertEquals("3.1", "foo.cpp", members[0].getName()); + assertThat(members).hasSize(1).allSatisfy(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(member.getName()).as("name").isEqualTo("foo.cpp"); + }); } private void modifyFileInWorkspace(final IFile file) throws IOException, CoreException { @@ -487,9 +513,10 @@ public void testCreateFilterOnLinkedFolderWithAlias() throws Exception { final IFolder folder1 = nonExistingFolderInOtherExistingProject; final IFolder folder2 = nonExistingFolder2InOtherExistingProject; - assertTrue("0.1", !folder1.exists()); - assertTrue("0.2", !folder2.exists()); - assertTrue("0.3", parentLoc.isPrefixOf(childLoc)); + assertThat(folder1).matches(not(IFolder::exists), "does not exist"); + assertThat(folder2).matches(not(IFolder::exists), "does not exist"); + assertThat(parentLoc).matches(parentLocation -> parentLocation.isPrefixOf(childLoc), + "is prefix of child location"); FileInfoMatcherDescription matcherDescription1 = new FileInfoMatcherDescription(REGEX_FILTER_PROVIDER, ".*"); @@ -502,14 +529,12 @@ public void testCreateFilterOnLinkedFolderWithAlias() throws Exception { folder2.createLink(childLoc, IResource.NONE, createTestMonitor()); existingProject.close(createTestMonitor()); - assertTrue("12.0", folder1.exists()); - assertTrue("12.2", folder2.exists()); - assertTrue("12.4", folder1.isLinked()); - assertTrue("12.6", folder2.isLinked()); - assertTrue("12.8", folder1.getLocation().equals(parentLoc)); - assertTrue("12.10", folder2.getLocation().equals(childLoc)); - assertTrue("12.12", folder1.members().length == 0); - assertTrue("12.14", folder2.members().length == 0); + assertThat(folder1).matches(IFolder::exists, "exists").matches(IFolder::isLinked, "is linked") + .extracting(IFolder::getLocation).isEqualTo(parentLoc); + assertThat(folder2).matches(IFolder::exists, "exists").matches(IFolder::isLinked, "is linked") + .extracting(IFolder::getLocation).isEqualTo(childLoc); + assertThat(folder1.members()).isEmpty(); + assertThat(folder2.members()).isEmpty(); // Need to unset M_USED on the project's resource info, or // reconcileLinks will never be called... @@ -525,20 +550,18 @@ public void testCreateFilterOnLinkedFolderWithAlias() throws Exception { } project.close(createTestMonitor()); - assertTrue("3.1", !project.isOpen()); + assertThat(project).matches(not(IProject::isOpen), "is not open"); // Create a file under existingFolderInExistingFolder createInFileSystem(childLoc.append("foo")); // Reopen the project project.open(IResource.NONE, createTestMonitor()); - assertTrue("22.0", folder1.exists()); - assertTrue("22.2", folder2.exists()); - assertTrue("22.4", folder1.isLinked()); - assertTrue("22.6", folder2.isLinked()); - assertTrue("22.8", folder1.getLocation().equals(parentLoc)); - assertTrue("22.10", folder2.getLocation().equals(childLoc)); - assertTrue("22.12", folder1.members().length == 0); - assertTrue("22.12", folder2.members().length == 1); + assertThat(folder1).matches(IFolder::exists, "exists").matches(IFolder::isLinked, "is linked") + .extracting(IFolder::getLocation).isEqualTo(parentLoc); + assertThat(folder2).matches(IFolder::exists, "exists").matches(IFolder::isLinked, "is linked") + .extracting(IFolder::getLocation).isEqualTo(childLoc); + assertThat(folder1.members()).isEmpty(); + assertThat(folder2.members()).hasSize(1); // Swap the links around, loading may be order independent... folder2.createLink(parentLoc, IResource.REPLACE, createTestMonitor()); @@ -548,7 +571,7 @@ public void testCreateFilterOnLinkedFolderWithAlias() throws Exception { folder2.createFilter(IResourceFilterDescription.EXCLUDE_ALL | IResourceFilterDescription.FOLDERS, matcherDescription1, 0, createTestMonitor()); filterDescription1.delete(0, createTestMonitor()); - assertTrue(folder1.getFilters().length == 0); + assertThat(folder1.getFilters()).isEmpty(); // Need to unset M_USED on the project's resource info, or // reconcileLinks will never be called... @@ -563,17 +586,15 @@ public void testCreateFilterOnLinkedFolderWithAlias() throws Exception { } project.close(createTestMonitor()); - assertTrue("3.1", !project.isOpen()); + assertThat(project).matches(not(IProject::isOpen), "is not open"); project.open(IResource.NONE, createTestMonitor()); - assertTrue("32.0", folder1.exists()); - assertTrue("32.2", folder2.exists()); - assertTrue("32.4", folder1.isLinked()); - assertTrue("32.6", folder2.isLinked()); - assertTrue("32.8", folder2.getLocation().equals(parentLoc)); - assertTrue("32.10", folder1.getLocation().equals(childLoc)); - assertTrue("32.12", folder1.members().length == 1); - assertTrue("32.12", folder2.members().length == 0); + assertThat(folder1).matches(IFolder::exists, "exists").matches(IFolder::isLinked, "is linked") + .extracting(IFolder::getLocation).isEqualTo(childLoc); + assertThat(folder2).matches(IFolder::exists, "exists").matches(IFolder::isLinked, "is linked") + .extracting(IFolder::getLocation).isEqualTo(parentLoc); + assertThat(folder1.members()).hasSize(1); + assertThat(folder2.members()).isEmpty(); } /** @@ -595,9 +616,10 @@ public void testCreateFilterOnLinkedFolderWithAlias2() throws CoreException { final IFolder folder1 = nonExistingFolderInOtherExistingProject; final IFolder folder2 = nonExistingFolder2InOtherExistingProject; - assertTrue("0.1", !folder1.exists()); - assertTrue("0.2", !folder2.exists()); - assertTrue("0.3", parentLoc.isPrefixOf(childLoc)); + assertThat(folder1).matches(not(IFolder::exists), "does not exist"); + assertThat(folder2).matches(not(IFolder::exists), "does not exist"); + assertThat(parentLoc).matches(parentLocation -> parentLocation.isPrefixOf(childLoc), + "is prefix of child location"); FileInfoMatcherDescription matcherDescription1 = new FileInfoMatcherDescription(REGEX_FILTER_PROVIDER, ".*"); @@ -610,14 +632,12 @@ public void testCreateFilterOnLinkedFolderWithAlias2() throws CoreException { folder2.createLink(childLoc, IResource.NONE, createTestMonitor()); existingProject.close(createTestMonitor()); - assertTrue("12.0", folder1.exists()); - assertTrue("12.2", folder2.exists()); - assertTrue("12.4", folder1.isLinked()); - assertTrue("12.6", folder2.isLinked()); - assertTrue("12.8", folder1.getLocation().equals(parentLoc)); - assertTrue("12.10", folder2.getLocation().equals(childLoc)); - assertTrue("12.12", folder1.members().length == 0); - assertTrue("12.14", folder2.members().length == 0); + assertThat(folder1).matches(IFolder::exists, "exists").matches(IFolder::isLinked, "is linked") + .extracting(IFolder::getLocation).isEqualTo(parentLoc); + assertThat(folder2).matches(IFolder::exists, "exists").matches(IFolder::isLinked, "is linked") + .extracting(IFolder::getLocation).isEqualTo(childLoc); + assertThat(folder1.members()).isEmpty(); + assertThat(folder2.members()).isEmpty(); // Need to unset M_USED on the project's resource info, or // reconcileLinks will never be called... @@ -635,14 +655,12 @@ public void testCreateFilterOnLinkedFolderWithAlias2() throws CoreException { // Create a file under existingFolderInExistingFolder createInWorkspace(folder2.getFile("foo")); - assertTrue("22.0", folder1.exists()); - assertTrue("22.2", folder2.exists()); - assertTrue("22.4", folder1.isLinked()); - assertTrue("22.6", folder2.isLinked()); - assertTrue("22.8", folder1.getLocation().equals(parentLoc)); - assertTrue("22.10", folder2.getLocation().equals(childLoc)); - assertTrue("22.12", folder1.members().length == 0); - assertTrue("22.12", folder2.members().length == 1); + assertThat(folder1).matches(IFolder::exists, "exists").matches(IFolder::isLinked, "is linked") + .extracting(IFolder::getLocation).isEqualTo(parentLoc); + assertThat(folder2).matches(IFolder::exists, "exists").matches(IFolder::isLinked, "is linked") + .extracting(IFolder::getLocation).isEqualTo(childLoc); + assertThat(folder1.members()).isEmpty(); + assertThat(folder2.members()).hasSize(1); // Swap the links around, loading may be order independent... folder2.createLink(parentLoc, IResource.REPLACE | IResource.NONE, createTestMonitor()); @@ -652,16 +670,14 @@ public void testCreateFilterOnLinkedFolderWithAlias2() throws CoreException { folder2.createFilter(IResourceFilterDescription.EXCLUDE_ALL | IResourceFilterDescription.FOLDERS, matcherDescription1, 0, createTestMonitor()); filterDescription1.delete(0, createTestMonitor()); - assertTrue(folder1.getFilters().length == 0); - - assertTrue("32.0", folder1.exists()); - assertTrue("32.2", folder2.exists()); - assertTrue("32.4", folder1.isLinked()); - assertTrue("32.6", folder2.isLinked()); - assertTrue("32.8", folder2.getLocation().equals(parentLoc)); - assertTrue("32.10", folder1.getLocation().equals(childLoc)); - assertTrue("32.12", folder1.members().length == 1); - assertTrue("32.12", folder2.members().length == 0); + assertThat(folder1.getFilters()).isEmpty(); + + assertThat(folder1).matches(IFolder::exists, "exists").matches(IFolder::isLinked, "is linked") + .extracting(IFolder::getLocation).isEqualTo(childLoc); + assertThat(folder2).matches(IFolder::exists, "exists").matches(IFolder::isLinked, "is linked") + .extracting(IFolder::getLocation).isEqualTo(parentLoc); + assertThat(folder1.members()).hasSize(1); + assertThat(folder2.members()).isEmpty(); } /** @@ -672,7 +688,7 @@ public void testCreateFilterOnLinkedFolderBeforeCreation() throws CoreException IPath location = existingFolderInExistingFolder.getLocation(); IFolder folder = nonExistingFolderInExistingProject; - assertTrue("0.1", !folder.exists()); + assertThat(folder).matches(not(IFolder::exists), "does not exist"); FileInfoMatcherDescription matcherDescription1 = new FileInfoMatcherDescription(REGEX_FILTER_PROVIDER, "foo"); @@ -693,16 +709,19 @@ public void testCreateFilterOnLinkedFolderBeforeCreation() throws CoreException IResourceFilterDescription[] filters = folder.getFilters(); - assertEquals("1.4", filters.length, 1); - assertEquals("1.5", filters[0].getFileInfoMatcherDescription().getId(), REGEX_FILTER_PROVIDER); - assertEquals("1.6", filters[0].getFileInfoMatcherDescription().getArguments(), "foo"); - assertEquals("1.7", filters[0].getType(), IResourceFilterDescription.INCLUDE_ONLY | IResourceFilterDescription.FILES); - assertEquals("1.8", filters[0].getResource(), folder); + assertThat(filters).hasSize(1).satisfiesExactly(filter -> { + assertThat(filter.getFileInfoMatcherDescription().getId()).as("provider").isEqualTo(REGEX_FILTER_PROVIDER); + assertThat(filter.getFileInfoMatcherDescription().getArguments()).as("arguments").isEqualTo("foo"); + assertThat(filter.getType()).as("type") + .isEqualTo(IResourceFilterDescription.INCLUDE_ONLY | IResourceFilterDescription.FILES); + assertThat(filter.getResource()).as("resource").isEqualTo(folder); + }); IResource members[] = folder.members(); - assertEquals("2.0", members.length, 1); - assertEquals("2.1", members[0].getType(), IResource.FILE); - assertEquals("2.2", members[0].getName(), "foo"); + assertThat(members).hasSize(1).satisfiesExactly(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(member.getName()).as("name").isEqualTo("foo"); + }); } /** @@ -734,14 +753,16 @@ public void testCreateAndRemoveFilterOnFolder() throws CoreException { IResourceFilterDescription[] filters = existingFolderInExistingFolder.getFilters(); - assertEquals("1.6", filters.length, 0); + assertThat(filters).isEmpty(); IResource members[] = existingFolderInExistingFolder.members(); - assertEquals("1.8", members.length, 2); - assertEquals("1.9", members[0].getType(), IResource.FILE); - assertEquals("2.0", members[0].getName(), "bar"); - assertEquals("2.1", members[1].getType(), IResource.FILE); - assertEquals("2.2", members[1].getName(), "foo"); + assertThat(members).hasSize(2).satisfiesExactly(firstMember -> { + assertThat(firstMember.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(firstMember.getName()).as("name").isEqualTo("bar"); + }, secondMember -> { + assertThat(secondMember.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(secondMember.getName()).as("name").isEqualTo("foo"); + }); } /** @@ -763,14 +784,16 @@ public void testCreateAndRemoveFilterOnFolderWithoutClosingProject() throws Core filterDescription.delete(0, createTestMonitor()); IResourceFilterDescription[] filters = existingFolderInExistingFolder.getFilters(); - assertEquals("1.6", filters.length, 0); + assertThat(filters).isEmpty(); IResource members[] = existingFolderInExistingFolder.members(); - assertEquals("1.8", members.length, 2); - assertEquals("1.9", members[0].getType(), IResource.FILE); - assertEquals("2.0", members[0].getName(), "bar"); - assertEquals("2.1", members[1].getType(), IResource.FILE); - assertEquals("2.2", members[1].getName(), "foo"); + assertThat(members).hasSize(2).satisfiesExactly(firstMember -> { + assertThat(firstMember.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(firstMember.getName()).as("name").isEqualTo("bar"); + }, secondMember -> { + assertThat(secondMember.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(secondMember.getName()).as("name").isEqualTo("foo"); + }); } /** @@ -792,11 +815,13 @@ public void testIncludeOnlyFilter() throws CoreException { existingProject.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); IResource members[] = existingFolderInExistingProject.members(); - assertEquals("2.0", members.length, 2); - assertEquals("2.1", members[0].getType(), IResource.FILE); - assertEquals("2.2", members[0].getName(), "file.c"); - assertEquals("2.3", members[1].getType(), IResource.FILE); - assertEquals("2.4", members[1].getName(), "foo.c"); + assertThat(members).hasSize(2).satisfiesExactly(firstMember -> { + assertThat(firstMember.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(firstMember.getName()).as("name").isEqualTo("file.c"); + }, secondMember -> { + assertThat(secondMember.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(secondMember.getName()).as("name").isEqualTo("foo.c"); + }); FileInfoMatcherDescription matcherDescription2 = new FileInfoMatcherDescription(REGEX_FILTER_PROVIDER, ".*\\.c"); existingFolderInExistingProject.createFilter(IResourceFilterDescription.INCLUDE_ONLY @@ -805,11 +830,13 @@ public void testIncludeOnlyFilter() throws CoreException { existingProject.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); members = existingFolderInExistingProject.members(); - assertEquals("3.3", members.length, 2); - assertEquals("3.4", members[0].getType(), IResource.FILE); - assertEquals("3.5", members[0].getName(), "file.c"); - assertEquals("3.6", members[1].getType(), IResource.FILE); - assertEquals("3.7", members[1].getName(), "foo.c"); + assertThat(members).hasSize(2).satisfiesExactly(firstMember -> { + assertThat(firstMember.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(firstMember.getName()).as("name").isEqualTo("file.c"); + }, secondMember -> { + assertThat(secondMember.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(secondMember.getName()).as("name").isEqualTo("foo.c"); + }); } /** @@ -832,11 +859,13 @@ public void testExcludeAllFilter() throws CoreException { existingProject.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); IResource members[] = existingFolderInExistingFolder.members(); - assertEquals("2.0", members.length, 2); - assertEquals("2.1", members[0].getType(), IResource.FILE); - assertEquals("2.2", members[0].getName(), "bar.h"); - assertEquals("2.3", members[1].getType(), IResource.FILE); - assertEquals("2.4", members[1].getName(), "foo.h"); + assertThat(members).hasSize(2).satisfiesExactly(firstMember -> { + assertThat(firstMember.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(firstMember.getName()).as("name").isEqualTo("bar.h"); + }, secondMember -> { + assertThat(secondMember.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(secondMember.getName()).as("name").isEqualTo("foo.h"); + }); FileInfoMatcherDescription matcherDescription2 = new FileInfoMatcherDescription(REGEX_FILTER_PROVIDER, "foo.*"); existingFolderInExistingFolder.createFilter(IResourceFilterDescription.EXCLUDE_ALL @@ -845,9 +874,10 @@ public void testExcludeAllFilter() throws CoreException { existingProject.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); members = existingFolderInExistingFolder.members(); - assertEquals("3.3", members.length, 1); - assertEquals("3.4", members[0].getType(), IResource.FILE); - assertEquals("3.5", members[0].getName(), "bar.h"); + assertThat(members).hasSize(1).satisfiesExactly(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(member.getName()).as("name").isEqualTo("bar.h"); + }); } /** @@ -874,9 +904,10 @@ public void testMixedFilter() throws CoreException { existingProject.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); IResource members[] = existingFolderInExistingProject.members(); - assertEquals("2.0", members.length, 1); - assertEquals("2.1", members[0].getType(), IResource.FILE); - assertEquals("2.2", members[0].getName(), "file.c"); + assertThat(members).hasSize(1).satisfiesExactly(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(member.getName()).as("name").isEqualTo("file.c"); + }); } /** @@ -902,9 +933,10 @@ public void testInheritedFilter() throws CoreException { existingProject.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); IResource members[] = existingFolderInExistingFolder.members(); - assertEquals("2.0", members.length, 1); - assertEquals("2.1", members[0].getType(), IResource.FILE); - assertEquals("2.2", members[0].getName(), "file.c"); + assertThat(members).hasSize(1).satisfiesExactly(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(member.getName()).as("name").isEqualTo("file.c"); + }); } /** @@ -924,9 +956,10 @@ public void testFolderOnlyFilters() throws CoreException { existingProject.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); IResource members[] = existingFolderInExistingFolder.members(); - assertEquals("2.0", members.length, 1); - assertEquals("2.1", members[0].getType(), IResource.FILE); - assertEquals("2.2", members[0].getName(), "foo.c"); + assertThat(members).hasSize(1).satisfiesExactly(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FILE); + assertThat(member.getName()).as("name").isEqualTo("foo.c"); + }); } /** @@ -946,9 +979,10 @@ public void testFileOnlyFilters() throws CoreException { existingProject.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); IResource members[] = existingFolderInExistingFolder.members(); - assertEquals("2.0", members.length, 1); - assertEquals("2.1", members[0].getType(), IResource.FOLDER); - assertEquals("2.2", members[0].getName(), "foo.d"); + assertThat(members).hasSize(1).satisfiesExactly(member -> { + assertThat(member.getType()).as("type").isEqualTo(IResource.FOLDER); + assertThat(member.getName()).as("name").isEqualTo("foo.d"); + }); } /** @@ -971,14 +1005,16 @@ public void testMoveFolderWithFilterToAnotherProject() throws CoreException { existingFolderInExistingProject.move(destination.getFullPath(), 0, createTestMonitor()); IResourceFilterDescription[] filters = existingFolderInExistingProject.getFilters(); - assertEquals("1.4", filters.length, 0); + assertThat(filters).isEmpty(); filters = destination.getFilters(); - assertEquals("1.6", filters.length, 1); - assertEquals("1.7", filters[0].getFileInfoMatcherDescription().getId(), REGEX_FILTER_PROVIDER); - assertEquals("1.8", filters[0].getFileInfoMatcherDescription().getArguments(), "foo.*"); - assertEquals("1.9", filters[0].getType(), IResourceFilterDescription.EXCLUDE_ALL | IResourceFilterDescription.FILES); - assertEquals("2.0", filters[0].getResource(), destination); + assertThat(filters).hasSize(1).satisfiesExactly(filter -> { + assertThat(filter.getFileInfoMatcherDescription().getId()).as("provider").isEqualTo(REGEX_FILTER_PROVIDER); + assertThat(filter.getFileInfoMatcherDescription().getArguments()).as("arguments").isEqualTo("foo.*"); + assertThat(filter.getType()).as("type") + .isEqualTo(IResourceFilterDescription.EXCLUDE_ALL | IResourceFilterDescription.FILES); + assertThat(filter.getResource()).as("resource").isEqualTo(destination); + }); } /** @@ -1001,18 +1037,22 @@ public void testCopyFolderWithFilterToAnotherProject() throws CoreException { existingFolderInExistingProject.copy(destination.getFullPath(), 0, createTestMonitor()); IResourceFilterDescription[] filters = existingFolderInExistingProject.getFilters(); - assertEquals("1.4", filters.length, 1); - assertEquals("1.5", filters[0].getFileInfoMatcherDescription().getId(), REGEX_FILTER_PROVIDER); - assertEquals("1.6", filters[0].getFileInfoMatcherDescription().getArguments(), "foo.*"); - assertEquals("1.7", filters[0].getType(), IResourceFilterDescription.EXCLUDE_ALL | IResourceFilterDescription.FILES); - assertEquals("1.8", filters[0].getResource(), existingFolderInExistingProject); + assertThat(filters).hasSize(1).satisfiesExactly(filter -> { + assertThat(filter.getFileInfoMatcherDescription().getId()).as("provider").isEqualTo(REGEX_FILTER_PROVIDER); + assertThat(filter.getFileInfoMatcherDescription().getArguments()).as("arguments").isEqualTo("foo.*"); + assertThat(filter.getType()).as("type") + .isEqualTo(IResourceFilterDescription.EXCLUDE_ALL | IResourceFilterDescription.FILES); + assertThat(filter.getResource()).as("resource").isEqualTo(existingFolderInExistingProject); + }); filters = destination.getFilters(); - assertEquals("2.1", filters.length, 1); - assertEquals("2.2", filters[0].getFileInfoMatcherDescription().getId(), REGEX_FILTER_PROVIDER); - assertEquals("2.3", filters[0].getFileInfoMatcherDescription().getArguments(), "foo.*"); - assertEquals("2.4", filters[0].getType(), IResourceFilterDescription.EXCLUDE_ALL | IResourceFilterDescription.FILES); - assertEquals("2.5", filters[0].getResource(), destination); + assertThat(filters).hasSize(1).satisfiesExactly(filter -> { + assertThat(filter.getFileInfoMatcherDescription().getId()).as("provider").isEqualTo(REGEX_FILTER_PROVIDER); + assertThat(filter.getFileInfoMatcherDescription().getArguments()).as("arguments").isEqualTo("foo.*"); + assertThat(filter.getType()).as("type") + .isEqualTo(IResourceFilterDescription.EXCLUDE_ALL | IResourceFilterDescription.FILES); + assertThat(filter.getResource()).as("resource").isEqualTo(destination); + }); } /** @@ -1036,18 +1076,22 @@ public void testCopyFolderWithFilterToAnotherFolder() throws CoreException { existingFolderInExistingProject.copy(destination.getFullPath(), 0, createTestMonitor()); IResourceFilterDescription[] filters = existingFolderInExistingProject.getFilters(); - assertEquals("1.4", filters.length, 1); - assertEquals("1.5", filters[0].getFileInfoMatcherDescription().getId(), REGEX_FILTER_PROVIDER); - assertEquals("1.6", filters[0].getFileInfoMatcherDescription().getArguments(), "foo.*"); - assertEquals("1.7", filters[0].getType(), IResourceFilterDescription.EXCLUDE_ALL | IResourceFilterDescription.FILES); - assertEquals("1.8", filters[0].getResource(), existingFolderInExistingProject); + assertThat(filters).hasSize(1).satisfiesExactly(filter -> { + assertThat(filter.getFileInfoMatcherDescription().getId()).as("provider").isEqualTo(REGEX_FILTER_PROVIDER); + assertThat(filter.getFileInfoMatcherDescription().getArguments()).as("arguments").isEqualTo("foo.*"); + assertThat(filter.getType()).as("type") + .isEqualTo(IResourceFilterDescription.EXCLUDE_ALL | IResourceFilterDescription.FILES); + assertThat(filter.getResource()).as("resource").isEqualTo(existingFolderInExistingProject); + }); filters = destination.getFilters(); - assertEquals("2.1", filters.length, 1); - assertEquals("2.2", filters[0].getFileInfoMatcherDescription().getId(), REGEX_FILTER_PROVIDER); - assertEquals("2.3", filters[0].getFileInfoMatcherDescription().getArguments(), "foo.*"); - assertEquals("2.4", filters[0].getType(), IResourceFilterDescription.EXCLUDE_ALL | IResourceFilterDescription.FILES); - assertEquals("2.5", filters[0].getResource(), destination); + assertThat(filters).hasSize(1).satisfiesExactly(filter -> { + assertThat(filter.getFileInfoMatcherDescription().getId()).as("provider").isEqualTo(REGEX_FILTER_PROVIDER); + assertThat(filter.getFileInfoMatcherDescription().getArguments()).as("arguments").isEqualTo("foo.*"); + assertThat(filter.getType()).as("type") + .isEqualTo(IResourceFilterDescription.EXCLUDE_ALL | IResourceFilterDescription.FILES); + assertThat(filter.getResource()).as("resource").isEqualTo(destination); + }); } /** @@ -1071,14 +1115,16 @@ public void testMoveFolderWithFilterToAnotherFolder() throws CoreException { existingFolderInExistingProject.move(destination.getFullPath(), 0, createTestMonitor()); IResourceFilterDescription[] filters = existingFolderInExistingProject.getFilters(); - assertEquals("1.4", filters.length, 0); + assertThat(filters).isEmpty(); filters = destination.getFilters(); - assertEquals("2.1", filters.length, 1); - assertEquals("2.2", filters[0].getFileInfoMatcherDescription().getId(), REGEX_FILTER_PROVIDER); - assertEquals("2.3", filters[0].getFileInfoMatcherDescription().getArguments(), "foo.*"); - assertEquals("2.4", filters[0].getType(), IResourceFilterDescription.EXCLUDE_ALL | IResourceFilterDescription.FILES); - assertEquals("2.5", filters[0].getResource(), destination); + assertThat(filters).hasSize(1).satisfiesExactly(filter -> { + assertThat(filter.getFileInfoMatcherDescription().getId()).as("provider").isEqualTo(REGEX_FILTER_PROVIDER); + assertThat(filter.getFileInfoMatcherDescription().getArguments()).as("arguments").isEqualTo("foo.*"); + assertThat(filter.getType()).as("type") + .isEqualTo(IResourceFilterDescription.EXCLUDE_ALL | IResourceFilterDescription.FILES); + assertThat(filter.getResource()).as("resource").isEqualTo(destination); + }); } /** @@ -1106,10 +1152,10 @@ public void testDeleteFolderWithFilterToAnotherFolder() throws CoreException { existingFolderInExistingProject.delete(0, createTestMonitor()); IResourceFilterDescription[] filters = existingFolderInExistingProject.getFilters(); - assertEquals("1.4", filters.length, 0); + assertThat(filters).isEmpty(); filters = existingFolderInExistingFolder.getFilters(); - assertEquals("2.1", filters.length, 0); + assertThat(filters).isEmpty(); } /* Regression test for Bug 304276 */ @@ -1136,11 +1182,13 @@ public void testBug302146() throws Exception { // check that filters are recreated when the project is reopened // it means that .project was updated with filter details - assertEquals("4.0", filters.length, 1); - assertEquals("4.1", filters[0].getFileInfoMatcherDescription().getId(), REGEX_FILTER_PROVIDER); - assertEquals("4.2", filters[0].getFileInfoMatcherDescription().getArguments(), "foo"); - assertEquals("4.3", filters[0].getType(), IResourceFilterDescription.INCLUDE_ONLY | IResourceFilterDescription.FILES | IResourceFilterDescription.FOLDERS); - assertEquals("4.4", filters[0].getResource(), existingFolderInExistingProject); + assertThat(filters).hasSize(1).satisfiesExactly(filter -> { + assertThat(filter.getFileInfoMatcherDescription().getId()).as("provider").isEqualTo(REGEX_FILTER_PROVIDER); + assertThat(filter.getFileInfoMatcherDescription().getArguments()).as("arguments").isEqualTo("foo"); + assertThat(filter.getType()).as("type").isEqualTo(IResourceFilterDescription.INCLUDE_ONLY + | IResourceFilterDescription.FILES | IResourceFilterDescription.FOLDERS); + assertThat(filter.getResource()).as("resource").isEqualTo(existingFolderInExistingProject); + }); new ProjectDescriptionReader(existingProject).read(existingProject.getFile(".project").getLocation()); } @@ -1167,18 +1215,16 @@ public void test317783() throws CoreException { existingProject.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); IResource members[] = existingProject.members(); - assertEquals("1.5", 2, members.length); - assertEquals("1.6", ".project", members[0].getName()); - assertEquals("1.7", existingFileInExistingProject.getName(), members[1].getName()); + assertThat(members).hasSize(2).satisfiesExactly(first -> assertThat(first.getName()).isEqualTo(".project"), + second -> assertThat(second.getName()).isEqualTo(existingFileInExistingProject.getName())); folder.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); members = existingProject.members(); - assertEquals("2.2", 2, members.length); - assertEquals("2.3", ".project", members[0].getName()); - assertEquals("2.4", existingFileInExistingProject.getName(), members[1].getName()); + assertThat(members).hasSize(2).satisfiesExactly(first -> assertThat(first.getName()).isEqualTo(".project"), + second -> assertThat(second.getName()).isEqualTo(existingFileInExistingProject.getName())); - assertEquals("2.5", false, folder.exists()); - assertEquals("2.6", false, file.exists()); + assertThat(folder).matches(not(IFolder::exists), "does not exist"); + assertThat(file).matches(not(IFile::exists), "does not exist"); } /** @@ -1197,7 +1243,7 @@ public void test317824() throws CoreException { FileInfoMatcherDescription matcherDescription = new FileInfoMatcherDescription(REGEX_FILTER_PROVIDER, ".*"); existingProject.createFilter(IResourceFilterDescription.EXCLUDE_ALL | IResourceFilterDescription.FOLDERS, matcherDescription, 0, createTestMonitor()); - assertEquals(1, existingProject.getFilters().length); + assertThat(existingProject.getFilters()).hasSize(1); existingProject.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); @@ -1205,15 +1251,15 @@ public void test317824() throws CoreException { existingProject.move(newPath, true, createTestMonitor()); IProject newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(existingProject.getName() + "_moved"); - assertTrue(newProject.exists()); - assertEquals(1, newProject.getFilters().length); + assertThat(newProject).matches(IProject::exists, "exists"); + assertThat(newProject.getFilters()).hasSize(1); newPath = newProject.getFullPath().removeLastSegments(1).append(newProject.getName() + "_copy"); newProject.copy(newPath, true, createTestMonitor()); newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(newProject.getName() + "_copy"); - assertTrue(newProject.exists()); - assertEquals(1, newProject.getFilters().length); + assertThat(newProject).matches(IProject::exists, "exists"); + assertThat(newProject.getFilters()).hasSize(1); } /** @@ -1231,24 +1277,25 @@ public void test328464() throws CoreException { "a\\.txt"); existingProject.createFilter(IResourceFilterDescription.EXCLUDE_ALL | IResourceFilterDescription.FILES | IResourceFilterDescription.INHERITABLE, matcherDescription, 0, createTestMonitor()); + IWorkspace workspace = getWorkspace(); - assertFalse("2.0", existingProject.getWorkspace().validateFiltered(file_a_txt).isOK()); + assertThat(file_a_txt).matches(it -> !workspace.validateFiltered(it).isOK(), "is filtered"); // rename a.txt to A.txt in the file system File ioFile = file_a_txt.getLocation().toFile(); - assertTrue("3.0", ioFile.exists()); + assertThat(ioFile).exists(); ioFile.renameTo(new File(file_a_txt.getLocation().removeLastSegments(1).append("A.txt").toString())); - assertFalse("4.0", existingProject.getWorkspace().validateFiltered(file_a_txt).isOK()); + assertThat(file_a_txt).matches(it -> !workspace.validateFiltered(it).isOK(), "is filtered"); folder.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); - assertFalse("6.0", file_a_txt.exists()); - assertFalse("7.0", existingProject.getWorkspace().validateFiltered(file_a_txt).isOK()); + assertThat(file_a_txt).matches(not(IFile::exists), "does not exists"); + assertThat(file_a_txt).matches(it -> !workspace.validateFiltered(it).isOK(), "is filtered"); IFile file_A_txt = folder.getFile("A.txt"); - assertTrue("9.0", file_A_txt.exists()); - assertTrue("10.0", existingProject.getWorkspace().validateFiltered(file_A_txt).isOK()); + assertThat(file_A_txt).matches(IFile::exists, "exists"); + assertThat(file_A_txt).matches(it -> workspace.validateFiltered(it).isOK(), "is not filtered"); } /** @@ -1271,20 +1318,20 @@ public void test343914() throws CoreException { IWorkspaceRoot root = getWorkspace().getRoot(); IFile result = root.getFileForLocation(fileLocation); - assertTrue("2.0", result == null); + assertThat(result).isNull(); IFile[] results = root.findFilesForLocation(fileLocation); - assertTrue("2.1", results.length == 0); + assertThat(results).isEmpty(); IPath containerLocation = subProjectLocation.append("folder"); IContainer resultContainer = root.getContainerForLocation(containerLocation); - assertTrue("2.2", resultContainer == null); + assertThat(resultContainer).isNull(); IContainer[] resultsContainer = root.findContainersForLocation(containerLocation); - assertTrue("2.3", resultsContainer.length == 0); + assertThat(resultsContainer).isEmpty(); IProject subProject = root.getProject(subProjectName); @@ -1294,22 +1341,19 @@ public void test343914() throws CoreException { subProject.create(newProjectDescription, createTestMonitor()); result = root.getFileForLocation(fileLocation); - assertTrue("3.0", result != null); - assertEquals("3.1", subProject, result.getProject()); + assertThat(result).isNotNull().extracting(IFile::getProject).isEqualTo(subProject); results = root.findFilesForLocation(fileLocation); - assertTrue("3.2", results.length == 1); - assertEquals("3.3", subProject, results[0].getProject()); + assertThat(results).hasSize(1).satisfiesExactly(it -> assertThat(it.getProject()).isEqualTo(subProject)); resultContainer = root.getContainerForLocation(containerLocation); - assertTrue("3.4", resultContainer != null); - assertEquals("3.5", subProject, resultContainer.getProject()); + assertThat(resultContainer).isNotNull().extracting(IContainer::getProject).isEqualTo(subProject); resultsContainer = root.findContainersForLocation(containerLocation); - assertTrue("3.6", resultsContainer.length == 1); - assertEquals("3.7", subProject, resultsContainer[0].getProject()); + assertThat(resultsContainer).hasSize(1) + .satisfiesExactly(it -> assertThat(it.getProject()).isEqualTo(subProject)); } } \ No newline at end of file diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/HiddenResourceTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/HiddenResourceTest.java index 36aac80f886..e5b00d4b841 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/HiddenResourceTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/HiddenResourceTest.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources; +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.assertExistsInWorkspace; @@ -131,9 +132,9 @@ public void testMembers() throws CoreException { members = project.members(); // +1 for the project description file - assertEquals("2.1", 4, members.length); + assertThat(members).hasSize(4); members = folder.members(); - assertEquals("2.3", 1, members.length); + assertThat(members).hasSize(1); // Set the values. setHidden(project, true, IResource.DEPTH_INFINITE); @@ -144,9 +145,9 @@ public void testMembers() throws CoreException { // Check the calls to #members members = project.members(); - assertEquals("5.1", 0, members.length); + assertThat(members).isEmpty(); members = folder.members(); - assertEquals("5.3", 0, members.length); + assertThat(members).isEmpty(); // FIXME: add the tests for #members(int) @@ -157,44 +158,44 @@ public void testMembers() throws CoreException { // Check the calls to members(IResource.NONE); members = project.members(IResource.NONE); // +1 for the project description file - assertEquals("7.1", 4, members.length); + assertThat(members).hasSize(4); members = project.members(IContainer.INCLUDE_HIDDEN); // +1 for the project description file - assertEquals("7.3", 4, members.length); + assertThat(members).hasSize(4); members = folder.members(); - assertEquals("7.5", 1, members.length); + assertThat(members).hasSize(1); // Set one of the children to be HIDDEN and try again setHidden(folder, true, IResource.DEPTH_ZERO); members = project.members(); // +1 for project description, -1 for hidden folder - assertEquals("8.2", 3, members.length); + assertThat(members).hasSize(3); members = folder.members(); - assertEquals("8.4", 1, members.length); + assertThat(members).hasSize(1); members = project.members(IResource.NONE); // +1 for project description, -1 for hidden folder - assertEquals("8.6", 3, members.length); + assertThat(members).hasSize(3); members = folder.members(); - assertEquals("8.8", 1, members.length); + assertThat(members).hasSize(1); members = project.members(IContainer.INCLUDE_HIDDEN); // +1 for project description - assertEquals("8.10", 4, members.length); + assertThat(members).hasSize(4); members = folder.members(); - assertEquals("8.12", 1, members.length); + assertThat(members).hasSize(1); // Set all the resources to be hidden setHidden(project, true, IResource.DEPTH_INFINITE); assertHidden(project, true, IResource.DEPTH_INFINITE); members = project.members(IResource.NONE); - assertEquals("9.3", 0, members.length); + assertThat(members).isEmpty(); members = folder.members(IResource.NONE); - assertEquals("9.5", 0, members.length); + assertThat(members).isEmpty(); members = project.members(IContainer.INCLUDE_HIDDEN); // +1 for project description - assertEquals("9.7", 4, members.length); + assertThat(members).hasSize(4); members = folder.members(IContainer.INCLUDE_HIDDEN); - assertEquals("9.9", 1, members.length); + assertThat(members).hasSize(1); } /** diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IProjectDescriptionTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IProjectDescriptionTest.java index 4e70aee2575..a08c7b13cfd 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IProjectDescriptionTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IProjectDescriptionTest.java @@ -14,6 +14,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources; +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; @@ -171,11 +172,9 @@ public void testDynamicProjectReferences() throws CoreException { description.setDynamicReferences(new IProject[] {target2}); project.setDescription(description, createTestMonitor()); IProject[] refs = project.getReferencedProjects(); - assertEquals("2.1", 2, refs.length); - assertEquals("2.2", target1, refs[0]); - assertEquals("2.3", target2, refs[1]); - assertEquals("2.4", 1, target1.getReferencingProjects().length); - assertEquals("2.5", 1, target2.getReferencingProjects().length); + assertThat(refs).containsExactly(target1, target2); + assertThat(target1.getReferencingProjects()).hasSize(1); + assertThat(target2.getReferencingProjects()).hasSize(1); //get references for a non-existent project assertThrows(CoreException.class, @@ -197,7 +196,7 @@ public void testProjectReferences() throws CoreException { IProjectDescription description = project.getDescription(); description.setReferencedProjects(new IProject[] {target}); project.setDescription(description, createTestMonitor()); - assertEquals("2.1", 1, target.getReferencingProjects().length); + assertThat(target.getReferencingProjects()).hasSize(1); //get references for a non-existent project assertThrows(CoreException.class, @@ -205,7 +204,7 @@ public void testProjectReferences() throws CoreException { //get referencing projects for a non-existent project IProject[] refs = getWorkspace().getRoot().getProject("DoesNotExist2").getReferencingProjects(); - assertEquals("4.0", 0, refs.length); + assertThat(refs).isEmpty(); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IProjectTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IProjectTest.java index 705769ebee4..08c3c7647d1 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IProjectTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IProjectTest.java @@ -14,6 +14,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources; +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.harness.FileSystemHelper.getTempDir; @@ -127,7 +128,7 @@ public void testCopy() throws CoreException { project.copy(destination.getFullPath(), IResource.NONE, monitor); monitor.assertUsedUp(); assertTrue("1.1", destination.exists()); - assertEquals("1.2", 0, destination.findMarkers(IMarker.TASK, true, IResource.DEPTH_INFINITE).length); + assertThat(destination.findMarkers(IMarker.TASK, true, IResource.DEPTH_INFINITE)).isEmpty(); } /** @@ -1997,29 +1998,23 @@ public void testProjectDescriptionDynamic() { IProject project2 = getWorkspace().getRoot().getProject("P2"); //dynamic project references - assertEquals("2.0", 0, desc.getDynamicReferences().length); + assertThat(desc.getDynamicReferences()).isEmpty(); IProject[] refs = new IProject[] {project1, project2}; desc.setDynamicReferences(refs); IProject[] result = desc.getDynamicReferences(); - assertEquals("2.1", 2, result.length); - assertEquals("2.2", project1, result[0]); - assertEquals("2.3", project2, result[1]); + assertThat(result).containsExactly(project1, project2); //destroying the result should not affect the description result[0] = null; result[1] = null; result = desc.getDynamicReferences(); - assertEquals("2.4", 2, result.length); - assertEquals("2.5", project1, result[0]); - assertEquals("2.6", project2, result[1]); + assertThat(result).containsExactly(project1, project2); //duplicates (should be automatically omitted) refs = new IProject[] {project1, project2, project2, project1, project1}; desc.setDynamicReferences(refs); result = desc.getDynamicReferences(); - assertEquals("3.1", 2, result.length); - assertEquals("3.2", project1, result[0]); - assertEquals("3.3", project2, result[1]); + assertThat(result).containsExactly(project1, project2); } /** @@ -2035,29 +2030,23 @@ public void testProjectDescriptionReferences() { assertEquals("1.0", "foo", desc.getName()); //project references - assertEquals("2.0", 0, desc.getReferencedProjects().length); + assertThat(desc.getReferencedProjects()).isEmpty(); IProject[] refs = new IProject[] {project1, project2}; desc.setReferencedProjects(refs); IProject[] result = desc.getReferencedProjects(); - assertEquals("2.1", 2, result.length); - assertEquals("2.2", project1, result[0]); - assertEquals("2.3", project2, result[1]); + assertThat(result).containsExactly(project1, project2); //destroying the result should not affect the description result[0] = null; result[1] = null; result = desc.getReferencedProjects(); - assertEquals("2.4", 2, result.length); - assertEquals("2.5", project1, result[0]); - assertEquals("2.6", project2, result[1]); + assertThat(result).containsExactly(project1, project2); //duplicates (should be automatically omitted) refs = new IProject[] {project1, project2, project2, project1, project1}; desc.setReferencedProjects(refs); result = desc.getReferencedProjects(); - assertEquals("3.1", 2, result.length); - assertEquals("3.2", project1, result[0]); - assertEquals("3.3", project2, result[1]); + assertThat(result).containsExactly(project1, project2); } @Test @@ -2216,7 +2205,7 @@ public void testProjectMoveVariations() throws CoreException { assertEquals("1.8", value, actual); // ensure the marker was moved markers = destChild.findMarkers(null, true, IResource.DEPTH_ZERO); - assertEquals("1.10", 1, markers.length); + assertThat(markers).hasSize(1); // cleanup monitor.prepare(); getWorkspace().getRoot().delete(false, monitor); @@ -2252,7 +2241,7 @@ public void testProjectMoveVariations() throws CoreException { assertEquals("2.11", value, actual); // ensure the marker was moved markers = destChild.findMarkers(null, true, IResource.DEPTH_ZERO); - assertEquals("2.13", 1, markers.length); + assertThat(markers).hasSize(1); // cleanup monitor.prepare(); getWorkspace().getRoot().delete(false, monitor); @@ -2384,7 +2373,7 @@ public void testRenameExternalProject() throws CoreException { assertEquals("2.11", propertyValue, actualPropertyValue); // ensure the marker was moved IMarker[] markers = destChild.findMarkers(null, true, IResource.DEPTH_ZERO); - assertEquals("2.13", 1, markers.length); + assertThat(markers).hasSize(1); // cleanup monitor.prepare(); getWorkspace().getRoot().delete(false, monitor); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeEventTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeEventTest.java index 2b2079fa602..bcfdf24ef6d 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeEventTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeEventTest.java @@ -13,13 +13,13 @@ *******************************************************************************/ package org.eclipse.core.tests.resources; +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; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import java.util.Map; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IMarker; @@ -105,8 +105,7 @@ public void testFindMarkerDeltas() throws CoreException { //marker type, no subtypes deltas = event.findMarkerDeltas(IMarker.MARKER, false); - assertNotNull("10.0", deltas); - assertTrue("10.1", deltas.length == 0); + assertThat(deltas).isEmpty(); //marker type, with subtypes deltas = event.findMarkerDeltas(IMarker.MARKER, true); @@ -114,8 +113,7 @@ public void testFindMarkerDeltas() throws CoreException { //problem type, with subtypes deltas = event.findMarkerDeltas(IMarker.PROBLEM, true); - assertNotNull("12.0", deltas); - assertTrue("12.1", deltas.length == 0); + assertThat(deltas).isEmpty(); //all types, include subtypes deltas = event.findMarkerDeltas(null, true); @@ -148,39 +146,25 @@ public void testFindMarkerDeltasInEmptyDelta() throws CoreException { */ IResourceChangeListener listener = event -> { //bookmark type, no subtypes - IMarkerDelta[] deltas = event.findMarkerDeltas(IMarker.BOOKMARK, false); - assertNotNull("1.0", deltas); - assertTrue("1.1", deltas.length == 0); + assertThat(event.findMarkerDeltas(IMarker.BOOKMARK, false)).isEmpty(); //bookmark type, with subtypes - deltas = event.findMarkerDeltas(IMarker.BOOKMARK, true); - assertNotNull("2.0", deltas); - assertTrue("2.1", deltas.length == 0); + assertThat(event.findMarkerDeltas(IMarker.BOOKMARK, true)).isEmpty(); //marker type, no subtypes - deltas = event.findMarkerDeltas(IMarker.MARKER, false); - assertNotNull("3.0", deltas); - assertTrue("3.1", deltas.length == 0); + assertThat(event.findMarkerDeltas(IMarker.MARKER, false)).isEmpty(); //marker type, with subtypes - deltas = event.findMarkerDeltas(IMarker.MARKER, true); - assertNotNull("4.0", deltas); - assertTrue("4.1", deltas.length == 0); + assertThat(event.findMarkerDeltas(IMarker.MARKER, true)).isEmpty(); //problem type, with subtypes - deltas = event.findMarkerDeltas(IMarker.PROBLEM, true); - assertNotNull("5.0", deltas); - assertTrue("5.1", deltas.length == 0); + assertThat(event.findMarkerDeltas(IMarker.PROBLEM, true)).isEmpty(); //all types, include subtypes - deltas = event.findMarkerDeltas(null, true); - assertNotNull("6.0", deltas); - assertTrue("6.1", deltas.length == 0); + assertThat(event.findMarkerDeltas(null, true)).isEmpty(); //all types, no subtypes - deltas = event.findMarkerDeltas(null, false); - assertNotNull("7.0", deltas); - assertTrue("7.1", deltas.length == 0); + assertThat(event.findMarkerDeltas(null, false)).isEmpty(); }; getWorkspace().addResourceChangeListener(listener); @@ -196,29 +180,15 @@ public void testFindMarkerDeltasInEmptyDelta() throws CoreException { * Verifies that the marker deltas have the right changes. */ protected void verifyDeltas(IMarkerDelta[] deltas) { - assertNotNull("1.0", deltas); - assertTrue("1.1", deltas.length == 3); - //delta order is not defined.. - boolean found1 = false, found2 = false, found3 = false; - for (int i = 0; i < deltas.length; i++) { - assertTrue("kind" + i, deltas[i].getType().equals(IMarker.BOOKMARK)); - long id = deltas[i].getId(); - if (id == marker1.getId()) { - found1 = true; - assertTrue("2.0", deltas[i].getKind() == IResourceDelta.ADDED); - } else if (id == marker2.getId()) { - found2 = true; - assertTrue("3.0", deltas[i].getKind() == IResourceDelta.REMOVED); - } else if (id == marker3.getId()) { - found3 = true; - assertTrue("4.0", deltas[i].getKind() == IResourceDelta.CHANGED); - } else { - assertTrue("4.99", false); - } - } - assertTrue("5.0", found1); - assertTrue("5.1", found2); - assertTrue("5.2", found3); + Map deltaIdToKind = Map.of(marker1.getId(), IResourceDelta.ADDED, // + marker2.getId(), IResourceDelta.REMOVED, // + marker3.getId(), IResourceDelta.CHANGED); + assertThat(deltas).hasSize(3).allSatisfy(delta -> { + assertThat(delta.getType()).as("type").isEqualTo(IMarker.BOOKMARK); + assertThat(delta.getKind()).as("kind").isNotNull().isEqualTo(deltaIdToKind.get(delta.getId())); + }).anySatisfy(delta -> assertThat(delta.getKind()).isEqualTo(IResourceDelta.ADDED)) + .anySatisfy(delta -> assertThat(delta.getKind()).isEqualTo(IResourceDelta.REMOVED)) + .anySatisfy(delta -> assertThat(delta.getKind()).isEqualTo(IResourceDelta.CHANGED)); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeListenerTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeListenerTest.java index f5f603156b8..ba65f3ac2db 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeListenerTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeListenerTest.java @@ -731,9 +731,10 @@ public void resourceChanged(IResourceChangeEvent event) { done = true; IMarkerDelta[] deltas = event.findMarkerDeltas(IMarker.TASK, false); listenerInMainThreadCallback.set(() -> { - assertEquals("1.0", 1, deltas.length); - assertEquals("1.1", marker.getId(), deltas[0].getId()); - assertEquals("1.2", IResourceDelta.REMOVED, deltas[0].getKind()); + assertThat(deltas).hasSize(1).allSatisfy(delta -> { + assertThat(delta.getId()).isEqualTo(marker.getId()); + assertThat(delta.getKind()).isEqualTo(IResourceDelta.REMOVED); + }); synchronized (this) { notifyAll(); } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceRootTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceRootTest.java index ff51d703d1e..dde80aef137 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceRootTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceRootTest.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.harness.FileSystemHelper.getTempDir; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInFileSystem; @@ -75,8 +76,7 @@ public void testFindFilesNonCanonicalPath() throws Exception { //try to find the file using the upper case device IFile[] files = getWorkspace().getRoot().findFilesForLocation(fileLocationUpper); - assertEquals("1.0", 1, files.length); - assertEquals("1.1", link, files[0]); + assertThat(files).containsExactly(link); } /** @@ -114,8 +114,7 @@ private void testFindContainersForLocation(IProject p1, IProject p2) throws Exce //should find the workspace root IWorkspaceRoot root = getWorkspace().getRoot(); IContainer[] result = root.findContainersForLocation(root.getLocation()); - assertEquals("1.0", 1, result.length); - assertEquals("1.1", root, result[0]); + assertThat(result).containsExactly(root); //deep linked resource IFolder parent = p2.getFolder("parent"); @@ -189,7 +188,7 @@ private void testFindFilesForLocation(IProject project) throws CoreException { //should not find the workspace root IWorkspaceRoot root = getWorkspace().getRoot(); IFile[] result = root.findFilesForLocation(root.getLocation()); - assertEquals("1.0", 0, result.length); + assertThat(result).isEmpty(); IFile existing = project.getFile("file1"); createInWorkspace(existing); @@ -239,22 +238,14 @@ private void testFindFilesForLocation(IProject project) throws CoreException { * Asserts that the given result array contains only the given resource. */ private void assertResources(String message, IResource expected, IResource[] actual) { - assertEquals(message, 1, actual.length); - assertEquals(message, expected, actual[0]); + assertThat(actual).describedAs(message).containsExactly(expected); } /** * Asserts that the given result array contains only the two given resources */ private void assertResources(String message, IResource expected0, IResource expected1, IResource[] actual) { - assertEquals(message, 2, actual.length); - if (actual[0].equals(expected0)) { - assertEquals(message, expected1, actual[1]); - } else if (actual[0].equals(expected1)) { - assertEquals(message, expected0, actual[1]); - } else { - assertEquals(message, expected0, actual[0]); - } + assertThat(actual).describedAs(message).containsExactlyInAnyOrder(expected0, expected1); } /** @@ -346,10 +337,10 @@ public void testBug234343_folderInHiddenProject() throws CoreException { folder.create(true, true, createTestMonitor()); IContainer[] containers = root.findContainersForLocationURI(folder.getLocationURI()); - assertEquals("2.0", 0, containers.length); + assertThat(containers).isEmpty(); containers = root.findContainersForLocationURI(folder.getLocationURI(), IContainer.INCLUDE_HIDDEN); - assertEquals("3.0", 1, containers.length); + assertThat(containers).hasSize(1); } @Test @@ -364,16 +355,16 @@ public void testBug234343_fileInHiddenProject() throws CoreException { file.create(new ByteArrayInputStream("foo".getBytes()), true, createTestMonitor()); IFile[] files = root.findFilesForLocationURI(file.getLocationURI()); - assertEquals("3.0", 0, files.length); + assertThat(files).isEmpty(); files = root.findFilesForLocationURI(file.getLocationURI(), IContainer.INCLUDE_HIDDEN); - assertEquals("4.0", 1, files.length); + assertThat(files).hasSize(1); IContainer[] containers = root.findContainersForLocationURI(file.getLocationURI()); - assertEquals("5.0", 0, containers.length); + assertThat(containers).isEmpty(); containers = root.findContainersForLocationURI(file.getLocationURI(), IContainer.INCLUDE_HIDDEN); - assertEquals("6.0", 1, containers.length); + assertThat(containers).hasSize(1); } /** @@ -483,12 +474,12 @@ public void checkFindMethods(int updateFlags, int[][] results) throws Exception private void checkFindFiles(URI location, int memberFlags, int foundResources) { IFile[] files = getWorkspace().getRoot().findFilesForLocationURI(location, memberFlags); - assertEquals(foundResources, files.length); + assertThat(files).hasSize(foundResources); } private void checkFindContainers(URI location, int memberFlags, int foundResources) { IContainer[] containers = getWorkspace().getRoot().findContainersForLocationURI(location, memberFlags); - assertEquals(foundResources, containers.length); + assertThat(containers).hasSize(foundResources); } private IFile createFile(IContainer parent, int updateFlags, boolean linked) throws Exception { diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceTest.java index bac74e7a305..f733a0d6a04 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceTest.java @@ -14,6 +14,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources; +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.harness.FileSystemHelper.getTempDir; @@ -227,7 +228,7 @@ public void testCopy() throws Exception { //copy a folder getWorkspace().copy(new IResource[] { folder }, folder2.getFullPath(), false, createTestMonitor()); assertTrue("3.7", folderCopy.exists()); - assertTrue("3.8", folderCopy.members().length > 0); + assertThat(folderCopy.members()).hasSizeGreaterThan(0); removeFromWorkspace(folderCopy); removeFromFileSystem(folderCopy); } @@ -309,95 +310,81 @@ public void testGetNatureDescriptors() { assertNotNull("2.0", current); assertEquals("2.1", NATURE_SIMPLE, current.getNatureId()); assertEquals("2.2", "Simple", current.getLabel()); - assertEquals("2.3", 0, current.getRequiredNatureIds().length); - assertEquals("2.4", 0, current.getNatureSetIds().length); + assertThat(current.getRequiredNatureIds()).isEmpty(); + assertThat(current.getNatureSetIds()).isEmpty(); current = findNature(descriptors, NATURE_SNOW); assertNotNull("3.0", current); assertEquals("3.1", NATURE_SNOW, current.getNatureId()); assertEquals("3.2", "Snow", current.getLabel()); String[] required = current.getRequiredNatureIds(); - assertEquals("3.3", 1, required.length); - assertEquals("3.4", NATURE_WATER, required[0]); + assertThat(required).containsExactly(NATURE_WATER); String[] sets = current.getNatureSetIds(); - assertEquals("3.5", 1, sets.length); - assertEquals("3.6", SET_OTHER, sets[0]); + assertThat(sets).containsExactly(SET_OTHER); current = findNature(descriptors, NATURE_WATER); assertNotNull("4.0", current); assertEquals("4.1", NATURE_WATER, current.getNatureId()); assertEquals("4.2", "Water", current.getLabel()); required = current.getRequiredNatureIds(); - assertEquals("4.3", 0, required.length); + assertThat(required).isEmpty(); sets = current.getNatureSetIds(); - assertEquals("4.4", 1, sets.length); - assertEquals("4.5", SET_STATE, sets[0]); + assertThat(sets).containsExactly(SET_STATE); current = findNature(descriptors, NATURE_EARTH); assertNotNull("5.0", current); assertEquals("5.1", NATURE_EARTH, current.getNatureId()); assertEquals("5.2", "Earth", current.getLabel()); required = current.getRequiredNatureIds(); - assertEquals("5.3", 0, required.length); + assertThat(required).isEmpty(); sets = current.getNatureSetIds(); - assertEquals("5.4", 1, sets.length); - assertEquals("5.5", SET_STATE, sets[0]); + assertThat(sets).containsExactly(SET_STATE); current = findNature(descriptors, NATURE_MUD); assertNotNull("6.0", current); assertEquals("6.1", NATURE_MUD, current.getNatureId()); assertEquals("6.2", "Mud", current.getLabel()); required = current.getRequiredNatureIds(); - assertEquals("6.3", 2, required.length); //water and earth are required for mud - if (required[0].equals(NATURE_WATER)) { - assertEquals("6.4", NATURE_EARTH, required[1]); - } else { - assertEquals("6.5", NATURE_EARTH, required[0]); - assertEquals("6.6", NATURE_WATER, required[0]); - } + assertThat(required).containsExactlyInAnyOrder(NATURE_WATER, NATURE_EARTH); sets = current.getNatureSetIds(); - assertEquals("6.7", 1, sets.length); - assertEquals("6.8", SET_OTHER, sets[0]); + assertThat(sets).containsExactly(SET_OTHER); current = findNature(descriptors, NATURE_INVALID); assertNotNull("7.0", current); assertEquals("7.1", NATURE_INVALID, current.getNatureId()); assertEquals("7.2", "", current.getLabel()); required = current.getRequiredNatureIds(); - assertEquals("7.3", 0, required.length); + assertThat(required).isEmpty(); sets = current.getNatureSetIds(); - assertEquals("7.4", 0, sets.length); + assertThat(sets).isEmpty(); current = findNature(descriptors, NATURE_CYCLE1); assertNotNull("8.0", current); assertEquals("8.1", NATURE_CYCLE1, current.getNatureId()); assertEquals("8.2", "Cycle1", current.getLabel()); required = current.getRequiredNatureIds(); - assertEquals("8.3", 1, required.length); - assertEquals("8.4", NATURE_CYCLE2, required[0]); + assertThat(required).containsExactly(NATURE_CYCLE2); sets = current.getNatureSetIds(); - assertEquals("8.5", 0, sets.length); + assertThat(sets).isEmpty(); current = findNature(descriptors, NATURE_CYCLE2); assertNotNull("5.0", current); assertEquals("9.1", NATURE_CYCLE2, current.getNatureId()); assertEquals("9.2", "Cycle2", current.getLabel()); required = current.getRequiredNatureIds(); - assertEquals("9.3", 1, required.length); - assertEquals("9.4", NATURE_CYCLE3, required[0]); + assertThat(required).containsExactly(NATURE_CYCLE3); sets = current.getNatureSetIds(); - assertEquals("9.5", 0, sets.length); + assertThat(sets).isEmpty(); current = findNature(descriptors, NATURE_CYCLE3); assertNotNull("10.0", current); assertEquals("10.1", NATURE_CYCLE3, current.getNatureId()); assertEquals("10.2", "Cycle3", current.getLabel()); required = current.getRequiredNatureIds(); - assertEquals("10.3", 1, required.length); - assertEquals("10.4", NATURE_CYCLE1, required[0]); + assertThat(required).containsExactly(NATURE_CYCLE1); sets = current.getNatureSetIds(); - assertEquals("10.5", 0, sets.length); + assertThat(sets).isEmpty(); } /** @@ -413,95 +400,80 @@ public void testGetNatureDescriptor() { assertNotNull("2.0", current); assertEquals("2.1", NATURE_SIMPLE, current.getNatureId()); assertEquals("2.2", "Simple", current.getLabel()); - assertEquals("2.3", 0, current.getRequiredNatureIds().length); - assertEquals("2.4", 0, current.getNatureSetIds().length); + assertThat(current.getRequiredNatureIds()).isEmpty(); + assertThat(current.getNatureSetIds()).isEmpty(); current = ws.getNatureDescriptor(NATURE_SNOW); assertNotNull("3.0", current); assertEquals("3.1", NATURE_SNOW, current.getNatureId()); assertEquals("3.2", "Snow", current.getLabel()); String[] required = current.getRequiredNatureIds(); - assertEquals("3.3", 1, required.length); - assertEquals("3.4", NATURE_WATER, required[0]); + assertThat(required).containsExactly(NATURE_WATER); String[] sets = current.getNatureSetIds(); - assertEquals("3.5", 1, sets.length); - assertEquals("3.6", SET_OTHER, sets[0]); + assertThat(sets).containsExactly(SET_OTHER); current = ws.getNatureDescriptor(NATURE_WATER); assertNotNull("4.0", current); assertEquals("4.1", NATURE_WATER, current.getNatureId()); assertEquals("4.2", "Water", current.getLabel()); required = current.getRequiredNatureIds(); - assertEquals("4.3", 0, required.length); + assertThat(required).isEmpty(); sets = current.getNatureSetIds(); - assertEquals("4.4", 1, sets.length); - assertEquals("4.5", SET_STATE, sets[0]); + assertThat(sets).containsExactly(SET_STATE); current = ws.getNatureDescriptor(NATURE_EARTH); assertNotNull("5.0", current); assertEquals("5.1", NATURE_EARTH, current.getNatureId()); assertEquals("5.2", "Earth", current.getLabel()); required = current.getRequiredNatureIds(); - assertEquals("5.3", 0, required.length); + assertThat(required).isEmpty(); sets = current.getNatureSetIds(); - assertEquals("5.4", 1, sets.length); - assertEquals("5.5", SET_STATE, sets[0]); + assertThat(sets).containsExactly(SET_STATE); current = ws.getNatureDescriptor(NATURE_MUD); assertNotNull("6.0", current); assertEquals("6.1", NATURE_MUD, current.getNatureId()); assertEquals("6.2", "Mud", current.getLabel()); required = current.getRequiredNatureIds(); - assertEquals("6.3", 2, required.length); - //water and earth are required for mud - if (required[0].equals(NATURE_WATER)) { - assertEquals("6.4", NATURE_EARTH, required[1]); - } else { - assertEquals("6.5", NATURE_EARTH, required[0]); - assertEquals("6.6", NATURE_WATER, required[0]); - } + assertThat(required).containsExactlyInAnyOrder(NATURE_WATER, NATURE_EARTH); sets = current.getNatureSetIds(); - assertEquals("6.7", 1, sets.length); - assertEquals("6.8", SET_OTHER, sets[0]); + assertThat(sets).containsExactly(SET_OTHER); current = ws.getNatureDescriptor(NATURE_INVALID); assertNotNull("7.0", current); assertEquals("7.1", NATURE_INVALID, current.getNatureId()); assertEquals("7.2", "", current.getLabel()); required = current.getRequiredNatureIds(); - assertEquals("7.3", 0, required.length); + assertThat(required).isEmpty(); sets = current.getNatureSetIds(); - assertEquals("7.4", 0, sets.length); + assertThat(sets).isEmpty(); current = ws.getNatureDescriptor(NATURE_CYCLE1); assertNotNull("8.0", current); assertEquals("8.1", NATURE_CYCLE1, current.getNatureId()); assertEquals("8.2", "Cycle1", current.getLabel()); required = current.getRequiredNatureIds(); - assertEquals("8.3", 1, required.length); - assertEquals("8.4", NATURE_CYCLE2, required[0]); + assertThat(required).containsExactly(NATURE_CYCLE2); sets = current.getNatureSetIds(); - assertEquals("8.5", 0, sets.length); + assertThat(sets).isEmpty(); current = ws.getNatureDescriptor(NATURE_CYCLE2); assertNotNull("5.0", current); assertEquals("9.1", NATURE_CYCLE2, current.getNatureId()); assertEquals("9.2", "Cycle2", current.getLabel()); required = current.getRequiredNatureIds(); - assertEquals("9.3", 1, required.length); - assertEquals("9.4", NATURE_CYCLE3, required[0]); + assertThat(required).containsExactly(NATURE_CYCLE3); sets = current.getNatureSetIds(); - assertEquals("9.5", 0, sets.length); + assertThat(sets).isEmpty(); current = ws.getNatureDescriptor(NATURE_CYCLE3); assertNotNull("10.0", current); assertEquals("10.1", NATURE_CYCLE3, current.getNatureId()); assertEquals("10.2", "Cycle3", current.getLabel()); required = current.getRequiredNatureIds(); - assertEquals("10.3", 1, required.length); - assertEquals("10.4", NATURE_CYCLE1, required[0]); + assertThat(required).containsExactly(NATURE_CYCLE1); sets = current.getNatureSetIds(); - assertEquals("10.5", 0, sets.length); + assertThat(sets).isEmpty(); } /** @@ -544,7 +516,7 @@ public void testMove() throws CoreException { CoreException ex = assertThrows(CoreException.class, () -> getWorkspace().move(resources2, folder.getFullPath(), true, createTestMonitor())); assertFalse("3.1", ex.getStatus().isOK()); - assertEquals("3.2", 1, ex.getStatus().getChildren().length); + assertThat(ex.getStatus().getChildren()).hasSize(1); assertFalse("3.3", file.exists()); assertFalse("3.4", anotherFile.exists()); assertFalse("3.5", oneMoreFile.exists()); @@ -628,7 +600,7 @@ public void testMultiCopy() throws Exception { () -> getWorkspace().copy(resources2, folder.getFullPath(), true, createTestMonitor())); IStatus status = e.getStatus(); assertFalse("3.1", status.isOK()); - assertEquals("3.2", 1, status.getChildren().length); + assertThat(status.getChildren()).hasSize(1); assertTrue("3.3", file1.exists()); assertTrue("3.4", anotherFile.exists()); assertTrue("3.5", oneMoreFile.exists()); @@ -661,7 +633,7 @@ public void testMultiCopy() throws Exception { () -> getWorkspace().copy(new IResource[] { project }, destination.getFullPath(), true, createTestMonitor())); status = ex2.getStatus(); assertFalse("5.1", status.isOK()); - assertEquals("5.2", 1, status.getChildren().length); + assertThat(status.getChildren()).hasSize(1); } @Test @@ -773,29 +745,22 @@ public void testSortNatureSet() { String[][] invalid = getInvalidNatureSets(); for (String[] element : invalid) { String[] sorted = ws.sortNatureSet(element); - assertNotNull("0.0", sorted); //set may grow if it contained duplicates - assertTrue("0.1", sorted.length <= element.length); + assertThat(sorted).hasSizeLessThanOrEqualTo(element.length); } String[] sorted = ws.sortNatureSet(new String[] {}); - assertEquals("1.0", 0, sorted.length); + assertThat(sorted).isEmpty(); sorted = ws.sortNatureSet(new String[] {NATURE_SIMPLE}); - assertEquals("2.0", 1, sorted.length); - assertEquals("2.1", NATURE_SIMPLE, sorted[0]); + assertThat(sorted).containsExactly(NATURE_SIMPLE); sorted = ws.sortNatureSet(new String[] {NATURE_SNOW, NATURE_WATER}); - assertEquals("3.0", 2, sorted.length); - assertEquals("3.1", NATURE_WATER, sorted[0]); - assertEquals("3.2", NATURE_SNOW, sorted[1]); + assertThat(sorted).containsExactly(NATURE_WATER, NATURE_SNOW); sorted = ws.sortNatureSet(new String[] {NATURE_WATER, NATURE_SIMPLE, NATURE_SNOW}); - assertEquals("4.0", 3, sorted.length); - //three valid sorts: water, snow, simple; water, simple, snow; simple, water, snow - boolean first = sorted[0].equals(NATURE_WATER) && sorted[1].equals(NATURE_SNOW) && sorted[2].equals(NATURE_SIMPLE); - boolean second = sorted[0].equals(NATURE_WATER) && sorted[1].equals(NATURE_SIMPLE) && sorted[2].equals(NATURE_SNOW); - boolean third = sorted[0].equals(NATURE_SIMPLE) && sorted[1].equals(NATURE_WATER) && sorted[2].equals(NATURE_SNOW); - assertTrue("4.1", first || second || third); + assertThat(sorted).satisfiesAnyOf(order -> assertThat(order).containsExactly(NATURE_WATER, NATURE_SNOW, NATURE_SIMPLE), + order -> assertThat(order).containsExactly(NATURE_WATER, NATURE_SIMPLE, NATURE_SNOW), + order -> assertThat(order).containsExactly(NATURE_SIMPLE, NATURE_WATER, NATURE_SNOW)); } @Test diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceTest.java index 3e0fe3f3a4d..cc15aacbdaa 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceTest.java @@ -14,6 +14,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.harness.FileSystemHelper.canCreateSymLinks; import static org.eclipse.core.tests.harness.FileSystemHelper.createSymLink; @@ -213,7 +214,7 @@ public void testAllowMissingLocal() throws CoreException { assertEquals("1.2", resolve(location), folder.getLocation()); assertTrue("1.3", !resolve(location).toFile().exists()); //getting children should succeed (and be empty) - assertEquals("1.4", 0, folder.members().length); + assertThat(folder.members()).isEmpty(); //delete should succeed folder.delete(IResource.NONE, createTestMonitor()); @@ -898,7 +899,7 @@ public void testFindFilesForLocationCaseVariant() throws CoreException { link.createLink(upperCase, IResource.NONE, createTestMonitor()); IPath lowerCaseFilePath = lowerCase.append("file.txt"); IFile[] files = getWorkspace().getRoot().findFilesForLocation(lowerCaseFilePath); - assertEquals("1.0", 1, files.length); + assertThat(files).hasSize(1); } /** @@ -968,28 +969,24 @@ public void testSetLinkLocationSwapLinkedResource() throws CoreException { nonExistingFolderInOtherExistingProject.createLink(childLoc, IResource.NONE, createTestMonitor()); createInWorkspace(nonExistingFolderInOtherExistingProject.getFile("foo")); - assertTrue("2.0", existingFolderInExistingFolder.members().length == 1); - assertTrue("3.0", existingFolderInExistingFolder.members()[0].getName().equals("foo")); - assertTrue("2.0", nonExistingFolderInOtherExistingProject.members().length == 1); - assertTrue("3.0", nonExistingFolderInOtherExistingProject.members()[0].getName().equals("foo")); - - assertTrue("4.0", nonExistingFolderInExistingProject.members().length == 1); - assertTrue("5.0", nonExistingFolderInExistingProject.members()[0].getName() - .equals(existingFolderInExistingFolder.getName())); + assertThat(existingFolderInExistingFolder.members()).hasSize(1) + .satisfiesExactly(member -> assertThat(member.getName()).as("name").isEqualTo("foo")); + assertThat(nonExistingFolderInOtherExistingProject.members()).hasSize(1) + .satisfiesExactly(member -> assertThat(member.getName()).as("name").isEqualTo("foo")); + assertThat(nonExistingFolderInExistingProject.members()).hasSize(1).satisfiesExactly( + member -> assertThat(member.getName()).as("name").isEqualTo(existingFolderInExistingFolder.getName())); // Swap links around nonExistingFolderInExistingProject.createLink(childLoc, IResource.REPLACE, createTestMonitor()); nonExistingFolderInOtherExistingProject.createLink(parentLoc, IResource.REPLACE, createTestMonitor()); - assertTrue("2.0", existingFolderInExistingFolder.members().length == 1); - assertTrue("3.0", existingFolderInExistingFolder.members()[0].getName().equals("foo")); - assertTrue(nonExistingFolderInExistingProject.getLocation().equals(childLoc)); - assertTrue("2.0", nonExistingFolderInExistingProject.members().length == 1); - assertTrue("3.0", nonExistingFolderInExistingProject.members()[0].getName().equals("foo")); - - assertTrue("4.0", nonExistingFolderInOtherExistingProject.members().length == 1); - assertTrue("5.0", nonExistingFolderInOtherExistingProject.members()[0].getName() - .equals(existingFolderInExistingFolder.getName())); + assertThat(existingFolderInExistingFolder.members()).hasSize(1) + .satisfiesExactly(member -> assertThat(member.getName()).as("name").isEqualTo("foo")); + assertThat(nonExistingFolderInOtherExistingProject.members()).hasSize(1).satisfiesExactly( + member -> assertThat(member.getName()).as("name").isEqualTo(existingFolderInExistingFolder.getName())); + assertThat(nonExistingFolderInExistingProject.members()).hasSize(1) + .satisfiesExactly(member -> assertThat(member.getName()).as("name").isEqualTo("foo")); + assertThat(nonExistingFolderInExistingProject.getLocation()).isEqualTo(childLoc); } @Test diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerSetTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerSetTest.java index 4af350e0103..cca98580ae3 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerSetTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerSetTest.java @@ -14,6 +14,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -37,10 +38,10 @@ public class MarkerSetTest { @Rule public WorkspaceTestRule workspaceRule = new WorkspaceTestRule(); - private void assertMarkerElementsEqual(String message, IMarkerSetElement[] array1, IMarkerSetElement[] array2) { - assertNotNull(message, array1); - assertNotNull(message, array2); - assertEquals(message, array1.length, array2.length); + private void assertMarkerElementsEqual(IMarkerSetElement[] array1, IMarkerSetElement[] array2) { + assertNotNull(array1); + assertNotNull(array2); + assertThat(array1).hasSameSizeAs(array2); IMarkerSetElement[] m1 = new IMarkerSetElement[array1.length]; System.arraycopy(array1, 0, m1, 0, array1.length); IMarkerSetElement[] m2 = new IMarkerSetElement[array2.length]; @@ -56,7 +57,7 @@ private void assertMarkerElementsEqual(String message, IMarkerSetElement[] array Arrays.sort(m1, compare); Arrays.sort(m2, compare); for (int i = 0; i < m1.length; i++) { - assertEquals(message, m1[i].getId(), m2[i].getId()); + assertEquals(m1[i].getId(), m2[i].getId()); } } @@ -106,7 +107,7 @@ public void testElements() { assertEquals("1.0", max, set.size()); // remove each element - assertMarkerElementsEqual("2.0", set.elements(), infos); + assertMarkerElementsEqual(set.elements(), infos); } @Test diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectEncodingTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectEncodingTest.java index 2515f669491..7941db58701 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectEncodingTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectEncodingTest.java @@ -13,12 +13,12 @@ *******************************************************************************/ package org.eclipse.core.tests.resources; +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.eclipse.core.tests.resources.ResourceTestUtil.createUniqueString; import static org.eclipse.core.tests.resources.ResourceTestUtil.waitForBuild; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; import org.eclipse.core.internal.resources.PreferenceInitializer; import org.eclipse.core.internal.resources.ValidateProjectEncoding; @@ -182,7 +182,7 @@ private void whenProjectSpecificEncodingWasSet() throws Exception { private void thenProjectHasNoEncodingMarker() throws Exception { IMarker[] markers = project.findMarkers(ValidateProjectEncoding.MARKER_TYPE, false, IResource.DEPTH_ONE); - assertEquals("Expected to find no marker for project specific file encoding", 0, markers.length); + assertThat(markers).describedAs("Expected to find no marker for project specific file encoding").isEmpty(); } private void thenProjectHasEncodingMarkerOfSeverity(int expectedSeverity) throws Exception { diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectOrderTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectOrderTest.java index 4b3a302dab1..7f01b57c9b4 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectOrderTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectOrderTest.java @@ -14,8 +14,8 @@ *******************************************************************************/ package org.eclipse.core.tests.resources; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; -import static org.junit.Assert.assertTrue; import java.util.Arrays; import java.util.HashSet; @@ -94,26 +94,27 @@ public void test0() throws CoreException { IProject[] projects = new IProject[] { p4, p3, p2, p5, p1, p0 }; IProject[][] oldOrder = ws.computePrerequisiteOrder(projects); - assertTrue("0.1", oldOrder[1].length == 0); + assertThat(oldOrder[1]).isEmpty(); List x = Arrays.asList(oldOrder[0]); - assertTrue("0.2", x.size() == 6); - assertTrue("0.3", x.indexOf(p0) >= 0); - assertTrue("0.4", x.indexOf(p1) >= 0); - assertTrue("0.5", x.indexOf(p5) >= 0); - assertTrue("0.6", x.indexOf(p2) > x.indexOf(p1)); - assertTrue("0.7", x.indexOf(p3) > x.indexOf(p2)); - assertTrue("0.8", x.indexOf(p4) > x.indexOf(p3)); + assertThat(x).hasSize(6); + assertThat(x.indexOf(p0)).as("index p0").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(p1)).as("index p1").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(p2)).as("index p2").isGreaterThan(x.indexOf(p1)); + assertThat(x.indexOf(p3)).as("index p3").isGreaterThan(x.indexOf(p2)); + assertThat(x.indexOf(p4)).as("index p4").isGreaterThan(x.indexOf(p3)); + assertThat(x.indexOf(p5)).as("index p5").isGreaterThanOrEqualTo(0); IWorkspace.ProjectOrder order = ws.computeProjectOrder(projects); x = Arrays.asList(order.projects); - assertTrue("0.9", !order.hasCycles); - assertTrue("0.10", order.knots.length == 0); - assertTrue("0.11", x.size() == 6); - assertTrue("0.12", x.indexOf(p0) < x.indexOf(p1)); // alpha - assertTrue("0.13", x.indexOf(p2) > x.indexOf(p1)); // ref - assertTrue("0.14", x.indexOf(p3) > x.indexOf(p2)); // ref - assertTrue("0.15", x.indexOf(p4) > x.indexOf(p3)); // ref - assertTrue("0.16", x.indexOf(p5) > x.indexOf(p4)); // alpha + assertThat(order).matches(it -> !it.hasCycles, "has no cycles"); + assertThat(order.knots).isEmpty(); + assertThat(x).hasSize(6); + assertThat(x.indexOf(p0)).as("index p0").isLessThan(x.indexOf(p1)); // alpha + assertThat(x.indexOf(p2)).as("index p2").isGreaterThan(x.indexOf(p1)); // ref + assertThat(x.indexOf(p3)).as("index p3").isGreaterThan(x.indexOf(p2)); // ref + assertThat(x.indexOf(p4)).as("index p4").isGreaterThan(x.indexOf(p3)); // ref + assertThat(x.indexOf(p5)).as("index p5").isGreaterThan(x.indexOf(p4)); // alpha + assertThat(x.indexOf(p5)).as("index p5").isGreaterThanOrEqualTo(0); } @Test @@ -126,15 +127,15 @@ public void test1() throws CoreException { IProject[] projects = new IProject[] {}; IProject[][] oldOrder = ws.computePrerequisiteOrder(projects); List x = Arrays.asList(oldOrder[0]); - assertTrue("1.1", oldOrder[1].length == 0); - assertTrue("1.2", x.isEmpty()); + assertThat(oldOrder[1]).isEmpty(); + assertThat(x).isEmpty(); // no projects IWorkspace.ProjectOrder order = ws.computeProjectOrder(projects); x = Arrays.asList(order.projects); - assertTrue("1.3", !order.hasCycles); - assertTrue("1.4", order.knots.length == 0); - assertTrue("1.5", x.isEmpty()); + assertThat(order).matches(it -> !it.hasCycles, "has no cycles"); + assertThat(order.knots).isEmpty(); + assertThat(x).isEmpty(); // 1 project // open projects show up @@ -143,43 +144,43 @@ public void test1() throws CoreException { projects = new IProject[] { p0 }; oldOrder = ws.computePrerequisiteOrder(projects); x = Arrays.asList(oldOrder[0]); - assertTrue("1.6.1", oldOrder[1].length == 0); - assertTrue("1.6.2", x.size() == 1); - assertTrue("1.6.3", x.indexOf(p0) >= 0); + assertThat(oldOrder[1]).isEmpty(); + assertThat(x).hasSize(1); + assertThat(x.indexOf(p0)).as("index p0").isGreaterThanOrEqualTo(0); order = ws.computeProjectOrder(projects); x = Arrays.asList(order.projects); - assertTrue("1.6.4", !order.hasCycles); - assertTrue("1.6.5", order.knots.length == 0); - assertTrue("1.6.6", x.size() == 1); - assertTrue("1.6.7", x.indexOf(p0) >= 0); + assertThat(order).matches(it -> !it.hasCycles, "has no cycles"); + assertThat(order.knots).isEmpty(); + assertThat(x).hasSize(1); + assertThat(x.indexOf(p0)).as("index p0").isGreaterThanOrEqualTo(0); // closed projects do not show up p0.close(null); projects = new IProject[] { p0 }; oldOrder = ws.computePrerequisiteOrder(projects); x = Arrays.asList(oldOrder[0]); - assertTrue("1.6,8", oldOrder[1].length == 0); - assertTrue("1.6.9", x.isEmpty()); + assertThat(oldOrder[1]).isEmpty(); + assertThat(x).isEmpty(); order = ws.computeProjectOrder(projects); x = Arrays.asList(order.projects); - assertTrue("1.6.10", !order.hasCycles); - assertTrue("1.6.11", order.knots.length == 0); - assertTrue("1.6.12", x.isEmpty()); + assertThat(order).matches(it -> !it.hasCycles, "has no cycles"); + assertThat(order.knots).isEmpty(); + assertThat(x).isEmpty(); // non-existent projects do not show up either projects = new IProject[] { p0, p1 }; oldOrder = ws.computePrerequisiteOrder(projects); x = Arrays.asList(oldOrder[0]); - assertTrue("1.6.13", oldOrder[1].length == 0); - assertTrue("1.6.14", x.isEmpty()); + assertThat(oldOrder[1]).isEmpty(); + assertThat(x).isEmpty(); order = ws.computeProjectOrder(projects); x = Arrays.asList(order.projects); - assertTrue("1.6.15", !order.hasCycles); - assertTrue("1.6.16", order.knots.length == 0); - assertTrue("1.6.17", x.isEmpty()); + assertThat(order).matches(it -> !it.hasCycles, "has no cycles"); + assertThat(order.knots).isEmpty(); + assertThat(x).isEmpty(); p0.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, null); @@ -193,54 +194,54 @@ public void test1() throws CoreException { projects = new IProject[] { p1, p0 }; oldOrder = ws.computePrerequisiteOrder(projects); x = Arrays.asList(oldOrder[0]); - assertTrue("1.7.1", oldOrder[1].length == 0); - assertTrue("1.7.2", x.size() == 2); - assertTrue("1.7.3", x.indexOf(p0) >= 0); - assertTrue("1.7.4", x.indexOf(p1) >= 0); + assertThat(oldOrder[1]).isEmpty(); + assertThat(x).hasSize(2); + assertThat(x.indexOf(p0)).as("index p0").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(p1)).as("index p1").isGreaterThanOrEqualTo(0); order = ws.computeProjectOrder(projects); x = Arrays.asList(order.projects); - assertTrue("1.7.5", x.size() == 2); - assertTrue("1.7.6", x.indexOf(p0) >= 0); - assertTrue("1.7.7", x.indexOf(p1) >= 0); + assertThat(x).hasSize(2); + assertThat(x.indexOf(p0)).as("index p0").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(p1)).as("index p1").isGreaterThanOrEqualTo(0); // alpha order - assertTrue("1.7.8", x.indexOf(p0) < x.indexOf(p1)); - assertTrue("1.7.9", !order.hasCycles); - assertTrue("1.7.10", order.knots.length == 0); + assertThat(x.indexOf(p0)).as("index p0").isLessThan(x.indexOf(p1)); + assertThat(order).matches(it -> !it.hasCycles, "has no cycles"); + assertThat(order.knots).isEmpty(); // closed projects do not show up p0.close(null); oldOrder = ws.computePrerequisiteOrder(projects); x = Arrays.asList(oldOrder[0]); - assertTrue("1.7.11", oldOrder[1].length == 0); - assertTrue("1.7.12", x.size() == 1); - assertTrue("1.7.13", x.indexOf(p0) < 0); - assertTrue("1.7.14", x.indexOf(p1) >= 0); + assertThat(oldOrder[1]).isEmpty(); + assertThat(x).hasSize(1); + assertThat(x.indexOf(p0)).as("index p0").isLessThan(0); + assertThat(x.indexOf(p1)).as("index p1").isGreaterThanOrEqualTo(0); order = ws.computeProjectOrder(projects); x = Arrays.asList(order.projects); - assertTrue("1.7.15", !order.hasCycles); - assertTrue("1.7.16", order.knots.length == 0); - assertTrue("1.7.17", x.size() == 1); - assertTrue("1.7.18", x.indexOf(p0) < 0); - assertTrue("1.7.19", x.indexOf(p1) >= 0); + assertThat(order).matches(it -> !it.hasCycles, "has no cycles"); + assertThat(order.knots).isEmpty(); + assertThat(x).hasSize(1); + assertThat(x.indexOf(p0)).as("index p0").isLessThan(0); + assertThat(x.indexOf(p1)).as("index p1").isGreaterThanOrEqualTo(0); p0.open(null); p1.close(null); oldOrder = ws.computePrerequisiteOrder(projects); x = Arrays.asList(oldOrder[0]); - assertTrue("1.7.20", oldOrder[1].length == 0); - assertTrue("1.7.21", x.size() == 1); - assertTrue("1.7.22", x.indexOf(p0) >= 0); - assertTrue("1.7.23", x.indexOf(p1) < 0); + assertThat(oldOrder[1]).isEmpty(); + assertThat(x).hasSize(1); + assertThat(x.indexOf(p0)).as("index p0").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(p1)).as("index p1").isLessThan(0); order = ws.computeProjectOrder(projects); x = Arrays.asList(order.projects); - assertTrue("1.7.24", !order.hasCycles); - assertTrue("1.7.25", order.knots.length == 0); - assertTrue("1.7.26", x.size() == 1); - assertTrue("1.7.27", x.indexOf(p0) >= 0); - assertTrue("1.7.28", x.indexOf(p1) < 0); + assertThat(order).matches(it -> !it.hasCycles, "has no cycles"); + assertThat(order.knots).isEmpty(); + assertThat(x).hasSize(1); + assertThat(x.indexOf(p0)).as("index p0").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(p1)).as("index p1").isLessThan(0); p0.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, null); p1.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, null); @@ -255,20 +256,20 @@ public void test1() throws CoreException { projects = new IProject[] { p1, p0 }; oldOrder = ws.computePrerequisiteOrder(projects); x = Arrays.asList(oldOrder[0]); - assertTrue("1.8.1", oldOrder[1].length == 0); - assertTrue("1.8.2", x.size() == 2); - assertTrue("1.8.3", x.indexOf(p0) >= 0); - assertTrue("1.8.4", x.indexOf(p1) >= 0); - assertTrue("1.8.5", x.indexOf(p0) > x.indexOf(p1)); + assertThat(oldOrder[1]).isEmpty(); + assertThat(x).hasSize(2); + assertThat(x.indexOf(p0)).as("index p0").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(p1)).as("index p1").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(p0)).as("index p0").isGreaterThan(x.indexOf(p1)); order = ws.computeProjectOrder(projects); x = Arrays.asList(order.projects); - assertTrue("1.8.6", x.size() == 2); - assertTrue("1.8.7", x.indexOf(p0) >= 0); - assertTrue("1.8.8", x.indexOf(p1) >= 0); - assertTrue("1.8.9", x.indexOf(p0) > x.indexOf(p1)); - assertTrue("1.8.10", !order.hasCycles); - assertTrue("1.8.11", order.knots.length == 0); + assertThat(x).hasSize(2); + assertThat(x.indexOf(p0)).as("index p0").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(p1)).as("index p1").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(p0)).as("index p0").isGreaterThan(x.indexOf(p1)); + assertThat(order).matches(it -> !it.hasCycles, "has no cycles"); + assertThat(order.knots).isEmpty(); p0.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, null); p1.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, null); @@ -283,20 +284,20 @@ public void test1() throws CoreException { projects = new IProject[] { p1, p0 }; oldOrder = ws.computePrerequisiteOrder(projects); x = Arrays.asList(oldOrder[0]); - assertTrue("1.9.1", oldOrder[1].length == 0); - assertTrue("1.9.2", x.size() == 2); - assertTrue("1.9.3", x.indexOf(p0) >= 0); - assertTrue("1.9.4", x.indexOf(p1) >= 0); - assertTrue("1.9.5", x.indexOf(p1) > x.indexOf(p0)); + assertThat(oldOrder[1]).isEmpty(); + assertThat(x).hasSize(2); + assertThat(x.indexOf(p0)).as("index p0").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(p1)).as("index p1").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(p1)).as("index p1").isGreaterThan(x.indexOf(p0)); order = ws.computeProjectOrder(projects); x = Arrays.asList(order.projects); - assertTrue("1.9.6", !order.hasCycles); - assertTrue("1.9.7", order.knots.length == 0); - assertTrue("1.9.8", x.size() == 2); - assertTrue("1.9.9", x.indexOf(p0) >= 0); - assertTrue("1.9.10", x.indexOf(p1) >= 0); - assertTrue("1.9.11", x.indexOf(p1) > x.indexOf(p0)); + assertThat(order).matches(it -> !it.hasCycles, "has no cycles"); + assertThat(order.knots).isEmpty(); + assertThat(x).hasSize(2); + assertThat(x.indexOf(p0)).as("index p0").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(p1)).as("index p1").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(p1)).as("index p1").isGreaterThan(x.indexOf(p0)); p0.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, null); p1.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, null); @@ -314,77 +315,77 @@ public void test1() throws CoreException { oldOrder = ws.computePrerequisiteOrder(projects); x = Arrays.asList(oldOrder[0]); List unordered = Arrays.asList(oldOrder[1]); - assertTrue("1.10.1", oldOrder[1].length == 2); - assertTrue("1.10.2", x.isEmpty()); - assertTrue("1.10.3", unordered.size() == 2); - assertTrue("1.10.4", unordered.indexOf(p0) >= 0); - assertTrue("1.10.5", unordered.indexOf(p1) >= 0); + assertThat(oldOrder[1]).hasSize(2); + assertThat(x).isEmpty(); + assertThat(unordered).hasSize(2); + assertThat(unordered.indexOf(p0)).as("index p0").isGreaterThanOrEqualTo(0); + assertThat(unordered.indexOf(p1)).as("index p1").isGreaterThanOrEqualTo(0); order = ws.computeProjectOrder(projects); x = Arrays.asList(order.projects); - assertTrue("1.10.6", order.hasCycles); - assertTrue("1.10.7", order.knots.length == 1); - assertTrue("1.10.8", x.size() == 2); - assertTrue("1.10.9", x.indexOf(p0) >= 0); - assertTrue("1.10.10", x.indexOf(p1) >= 0); + assertThat(order).matches(it -> it.hasCycles, "has cycles"); + assertThat(order.knots).hasNumberOfRows(1); + assertThat(x).hasSize(2); + assertThat(x.indexOf(p0)).as("index p0").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(p1)).as("index p1").isGreaterThanOrEqualTo(0); List knot = Arrays.asList(order.knots[0]); - assertTrue("1.10.11", knot.size() == 2); - assertTrue("1.10.12", knot.indexOf(p0) >= 0); - assertTrue("1.10.13", knot.indexOf(p1) >= 0); + assertThat(knot).hasSize(2); + assertThat(knot.indexOf(p0)).as("index p0").isGreaterThanOrEqualTo(0); + assertThat(knot.indexOf(p1)).as("index p1").isGreaterThanOrEqualTo(0); // closing one breaks the cycle p0.close(null); oldOrder = ws.computePrerequisiteOrder(projects); x = Arrays.asList(oldOrder[0]); - assertTrue("1.10.14", oldOrder[1].length == 0); - assertTrue("1.10.15", x.size() == 1); - assertTrue("1.10.16", x.indexOf(p1) >= 0); + assertThat(oldOrder[1]).isEmpty(); + assertThat(x).hasSize(1); + assertThat(x.indexOf(p1)).as("index p1").isGreaterThanOrEqualTo(0); order = ws.computeProjectOrder(projects); x = Arrays.asList(order.projects); - assertTrue("1.10.17", !order.hasCycles); - assertTrue("1.10.18", order.knots.length == 0); - assertTrue("1.10.19", x.size() == 1); - assertTrue("1.10.20", x.indexOf(p1) >= 0); + assertThat(order).matches(it -> !it.hasCycles, "has no cycles"); + assertThat(order.knots).isEmpty(); + assertThat(x).hasSize(1); + assertThat(x.indexOf(p1)).as("index p1").isGreaterThanOrEqualTo(0); // closing other instead breaks the cycle p0.open(null); p1.close(null); oldOrder = ws.computePrerequisiteOrder(projects); x = Arrays.asList(oldOrder[0]); - assertTrue("1.10.21", oldOrder[1].length == 0); - assertTrue("1.10.22", x.size() == 1); - assertTrue("1.10.23", x.indexOf(p0) >= 0); + assertThat(oldOrder[1]).isEmpty(); + assertThat(x).hasSize(1); + assertThat(x.indexOf(p0)).as("index p0").isGreaterThanOrEqualTo(0); order = ws.computeProjectOrder(projects); x = Arrays.asList(order.projects); - assertTrue("1.10.24", !order.hasCycles); - assertTrue("1.10.25", order.knots.length == 0); - assertTrue("1.10.26", x.size() == 1); - assertTrue("1.10.27", x.indexOf(p0) >= 0); + assertThat(order).matches(it -> !it.hasCycles, "has no cycles"); + assertThat(order.knots).isEmpty(); + assertThat(x).hasSize(1); + assertThat(x.indexOf(p0)).as("index p0").isGreaterThanOrEqualTo(0); // reopening both brings back the cycle p1.open(null); oldOrder = ws.computePrerequisiteOrder(projects); x = Arrays.asList(oldOrder[0]); unordered = Arrays.asList(oldOrder[1]); - assertTrue("1.10.28", oldOrder[1].length == 2); - assertTrue("1.10.29", x.isEmpty()); - assertTrue("1.10.30", unordered.size() == 2); - assertTrue("1.10.31", unordered.indexOf(p0) >= 0); - assertTrue("1.10.32", unordered.indexOf(p1) >= 0); + assertThat(oldOrder[1]).hasSize(2); + assertThat(x).isEmpty(); + assertThat(unordered).hasSize(2); + assertThat(unordered.indexOf(p0)).as("index p0").isGreaterThanOrEqualTo(0); + assertThat(unordered.indexOf(p1)).as("index p1").isGreaterThanOrEqualTo(0); order = ws.computeProjectOrder(projects); x = Arrays.asList(order.projects); - assertTrue("1.10.33", order.hasCycles); - assertTrue("1.10.34", order.knots.length == 1); - assertTrue("1.10.35", x.size() == 2); - assertTrue("1.10.36", x.indexOf(p0) >= 0); - assertTrue("1.10.37", x.indexOf(p1) >= 0); + assertThat(order).matches(it -> it.hasCycles, "has cycles"); + assertThat(order.knots).hasNumberOfRows(1); + assertThat(x).hasSize(2); + assertThat(x.indexOf(p0)).as("index p0").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(p1)).as("index p1").isGreaterThanOrEqualTo(0); knot = Arrays.asList(order.knots[0]); - assertTrue("1.10.38", knot.size() == 2); - assertTrue("1.10.39", knot.indexOf(p0) >= 0); - assertTrue("1.10.40", knot.indexOf(p1) >= 0); + assertThat(x).hasSize(2); + assertThat(knot.indexOf(p0)).as("index p0").isGreaterThanOrEqualTo(0); + assertThat(knot.indexOf(p1)).as("index p1").isGreaterThanOrEqualTo(0); p0.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, null); p1.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, null); @@ -452,43 +453,43 @@ public void test2() throws CoreException { IProject[][] oldOrder = ws.computePrerequisiteOrder(projects); List x = Arrays.asList(oldOrder[0]); List unordered = Arrays.asList(oldOrder[1]); - assertTrue("2.1", x.size() == 1); - assertTrue("2.2", x.indexOf(h) >= 0); - assertTrue("2.3", unordered.size() == 7); - assertTrue("2.4", unordered.indexOf(a) >= 0); - assertTrue("2.5", unordered.indexOf(b) >= 0); - assertTrue("2.6", unordered.indexOf(c) >= 0); - assertTrue("2.7", unordered.indexOf(d) >= 0); - assertTrue("2.8", unordered.indexOf(e) >= 0); - assertTrue("2.9", unordered.indexOf(f) >= 0); - assertTrue("2.10", unordered.indexOf(g) >= 0); + assertThat(x).hasSize(1); + assertThat(x.indexOf(h)).as("index h").isGreaterThanOrEqualTo(0); + assertThat(unordered).hasSize(7); + assertThat(unordered.indexOf(a)).as("index a").isGreaterThanOrEqualTo(0); + assertThat(unordered.indexOf(b)).as("index b").isGreaterThanOrEqualTo(0); + assertThat(unordered.indexOf(c)).as("index c").isGreaterThanOrEqualTo(0); + assertThat(unordered.indexOf(d)).as("index d").isGreaterThanOrEqualTo(0); + assertThat(unordered.indexOf(e)).as("index e").isGreaterThanOrEqualTo(0); + assertThat(unordered.indexOf(f)).as("index f").isGreaterThanOrEqualTo(0); + assertThat(unordered.indexOf(g)).as("index g").isGreaterThanOrEqualTo(0); IWorkspace.ProjectOrder order = ws.computeProjectOrder(projects); x = Arrays.asList(order.projects); - assertTrue("2.11", x.size() == 8); - assertTrue("2.12", x.indexOf(a) >= 0); - assertTrue("2.13", x.indexOf(b) >= 0); - assertTrue("2.14", x.indexOf(c) >= 0); - assertTrue("2.15", x.indexOf(d) >= 0); - assertTrue("2.16", x.indexOf(e) >= 0); - assertTrue("2.17", x.indexOf(f) >= 0); - assertTrue("2.18", x.indexOf(g) >= 0); - assertTrue("2.19", x.indexOf(h) >= 0); + assertThat(x).hasSize(8); + assertThat(x.indexOf(a)).as("index a").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(b)).as("index b").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(c)).as("index c").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(d)).as("index d").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(e)).as("index e").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(f)).as("index f").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(g)).as("index g").isGreaterThanOrEqualTo(0); + assertThat(x.indexOf(h)).as("index h").isGreaterThanOrEqualTo(0); // {a, b, e} < {c,d} < {f, g} < {h} - assertTrue("2.20", x.indexOf(b) < x.indexOf(c)); - assertTrue("2.21", x.indexOf(b) < x.indexOf(d)); - assertTrue("2.22", x.indexOf(a) < x.indexOf(c)); - assertTrue("2.23", x.indexOf(a) < x.indexOf(d)); - assertTrue("2.24", x.indexOf(e) < x.indexOf(c)); - assertTrue("2.25", x.indexOf(e) < x.indexOf(d)); - assertTrue("2.26", x.indexOf(c) < x.indexOf(f)); - assertTrue("2.27", x.indexOf(c) < x.indexOf(g)); - assertTrue("2.28", x.indexOf(d) < x.indexOf(f)); - assertTrue("2.29", x.indexOf(d) < x.indexOf(g)); - assertTrue("2.30", x.indexOf(f) < x.indexOf(h)); - assertTrue("2.31", x.indexOf(g) < x.indexOf(h)); - assertTrue("2.32", order.hasCycles); - assertTrue("2.33", order.knots.length == 3); + assertThat(x.indexOf(b)).as("index b").isLessThan(x.indexOf(c)); + assertThat(x.indexOf(b)).as("index b").isLessThan(x.indexOf(d)); + assertThat(x.indexOf(a)).as("index a").isLessThan(x.indexOf(c)); + assertThat(x.indexOf(a)).as("index a").isLessThan(x.indexOf(d)); + assertThat(x.indexOf(e)).as("index e").isLessThan(x.indexOf(c)); + assertThat(x.indexOf(e)).as("index e").isLessThan(x.indexOf(d)); + assertThat(x.indexOf(c)).as("index c").isLessThan(x.indexOf(f)); + assertThat(x.indexOf(c)).as("index c").isLessThan(x.indexOf(g)); + assertThat(x.indexOf(d)).as("index d").isLessThan(x.indexOf(f)); + assertThat(x.indexOf(d)).as("index d").isLessThan(x.indexOf(g)); + assertThat(x.indexOf(f)).as("index f").isLessThan(x.indexOf(h)); + assertThat(x.indexOf(g)).as("index g").isLessThan(x.indexOf(h)); + assertThat(order).matches(it -> it.hasCycles, "has cycles"); + assertThat(order.knots).hasNumberOfRows(3); List k1 = Arrays.asList(order.knots[0]); List k2 = Arrays.asList(order.knots[1]); List k3 = Arrays.asList(order.knots[2]); @@ -508,18 +509,18 @@ public void test2() throws CoreException { k3 = temp; } // knot 1 - assertTrue("2.34", k1.size() == 3); - assertTrue("2.35", k1.indexOf(a) >= 0); - assertTrue("2.36", k1.indexOf(b) >= 0); - assertTrue("2.37", k1.indexOf(e) >= 0); + assertThat(k1).hasSize(3); + assertThat(k1.indexOf(a)).as("index a").isGreaterThanOrEqualTo(0); + assertThat(k1.indexOf(b)).as("index b").isGreaterThanOrEqualTo(0); + assertThat(k1.indexOf(e)).as("index e").isGreaterThanOrEqualTo(0); // knot 2 - assertTrue("2.38", k2.size() == 2); - assertTrue("2.39", k2.indexOf(c) >= 0); - assertTrue("2.40", k2.indexOf(d) >= 0); + assertThat(k2).hasSize(2); + assertThat(k2.indexOf(c)).as("index c").isGreaterThanOrEqualTo(0); + assertThat(k2.indexOf(d)).as("index d").isGreaterThanOrEqualTo(0); // knot 3 - assertTrue("2.41", k3.size() == 2); - assertTrue("2.42", k3.indexOf(f) >= 0); - assertTrue("2.43", k3.indexOf(g) >= 0); + assertThat(k3).hasSize(2); + assertThat(k3.indexOf(f)).as("index f").isGreaterThanOrEqualTo(0); + assertThat(k3.indexOf(g)).as("index g").isGreaterThanOrEqualTo(0); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/VirtualFolderTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/VirtualFolderTest.java index 6cad6923c62..5f541fdd669 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/VirtualFolderTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/VirtualFolderTest.java @@ -16,6 +16,7 @@ package org.eclipse.core.tests.resources; import static java.io.InputStream.nullInputStream; +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; @@ -130,7 +131,7 @@ public void testCreateLinkedFolderUnderVirtualFolder() throws CoreException { assertTrue("4.0", !location.toFile().exists()); // getting children should succeed (and be empty) - assertEquals("5.0", 0, linkedFolder.members().length); + assertThat(linkedFolder.members()).isEmpty(); // delete should succeed linkedFolder.delete(IResource.NONE, createTestMonitor()); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceTest.java index 3ee2e29dd8f..9c0d84c191f 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceTest.java @@ -15,6 +15,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.harness.FileSystemHelper.canCreateSymLinks; import static org.eclipse.core.tests.harness.FileSystemHelper.createSymLink; @@ -372,7 +373,7 @@ public void testProjectReferences() throws Throwable { monitor.prepare(); project.setDescription(description, monitor); monitor.assertUsedUp(); - assertTrue(target.getReferencingProjects().length == 1); + assertThat(target.getReferencingProjects()).hasSize(1); monitor.prepare(); target.delete(true, true, monitor); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/IContentTypeManagerTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/IContentTypeManagerTest.java index 2eacb69f52e..c7a196b0ba9 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/IContentTypeManagerTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/IContentTypeManagerTest.java @@ -14,6 +14,8 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.content; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.atIndex; import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -24,19 +26,38 @@ import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.CharArrayReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.HashSet; import java.util.Set; -import org.eclipse.core.internal.content.*; -import org.eclipse.core.runtime.*; -import org.eclipse.core.runtime.content.*; +import org.eclipse.core.internal.content.ContentType; +import org.eclipse.core.internal.content.ContentTypeBuilder; +import org.eclipse.core.internal.content.ContentTypeHandler; +import org.eclipse.core.internal.content.ContentTypeManager; +import org.eclipse.core.internal.content.IContentConstants; +import org.eclipse.core.internal.content.Util; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.core.runtime.content.IContentDescriber; +import org.eclipse.core.runtime.content.IContentDescription; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.core.runtime.content.IContentTypeManager; import org.eclipse.core.runtime.content.IContentTypeManager.ContentTypeChangeEvent; +import org.eclipse.core.runtime.content.IContentTypeMatcher; import org.eclipse.core.runtime.content.XMLContentDescriber; import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.core.runtime.preferences.*; -import org.eclipse.core.tests.harness.*; +import org.eclipse.core.runtime.preferences.IExportedPreferences; +import org.eclipse.core.runtime.preferences.IPreferencesService; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.core.tests.harness.BundleTestingHelper; +import org.eclipse.core.tests.harness.FussyProgressMonitor; +import org.eclipse.core.tests.harness.TestRegistryChangeListener; import org.junit.After; import org.junit.Test; import org.osgi.service.prefs.BackingStoreException; @@ -109,15 +130,6 @@ private String changeCase(String original) { return result.toString(); } - boolean contains(Object[] array, Object element) { - for (Object element2 : array) { - if (element2.equals(element)) { - return true; - } - } - return false; - } - private IContentDescription getDescriptionFor(IContentTypeMatcher finder, String contents, Charset encoding, String fileName, QualifiedName[] options, boolean text) throws IOException { return text ? finder.getDescriptionFor(getReader(contents), fileName, options) @@ -181,13 +193,9 @@ public void testAlias() throws IOException { assertNull("0.9", target); IContentType[] selected; selected = contentTypeManager.findContentTypesFor("foo.missing-target"); - assertEquals("1.1", 2, selected.length); - assertEquals("1.2", alias, selected[0]); - assertEquals("1.3", derived, selected[1]); + assertThat(selected).containsExactly(alias, derived); selected = contentTypeManager.findContentTypesFor(getRandomContents(), "foo.missing-target"); - assertEquals("1.4", 2, selected.length); - assertEquals("1.5", alias, selected[0]); - assertEquals("1.6", derived, selected[1]); + assertThat(selected).containsExactly(alias, derived); // test late addition of content type TestRegistryChangeListener listener = new TestRegistryChangeListener(Platform.PI_RUNTIME, @@ -201,18 +209,14 @@ public void testAlias() throws IOException { assertNotNull("2.1.3", target1); // checks associations IContentType[] selected1 = contentTypeManager.findContentTypesFor("foo.missing-target"); - assertEquals("2.2.1", 2, selected1.length); - assertEquals("2.2.2", target1, selected1[0]); - assertEquals("2.2.3", derived1, selected1[1]); + assertThat(selected1).containsExactly(target1, derived1); IContentType[] selected2; try { selected2 = contentTypeManager.findContentTypesFor(getRandomContents(), "foo.missing-target"); } catch (IOException e) { throw new AssertionError(e); } - assertEquals("2.2.5", 2, selected2.length); - assertEquals("2.2.6", target1, selected2[0]); - assertEquals("2.2.7", derived1, selected2[1]); + assertThat(selected2).containsExactly(target1, derived1); }, getContext(), new String[] { ContentTypeTest.TEST_FILES_ROOT + "content/bundle02" }, listener); } @@ -246,41 +250,30 @@ public void testAssociationInheritance() throws CoreException { IContentType[] selected; // text built-in associations selected = finder.findContentTypesFor(changeCase("text.txt")); - assertEquals("3.0", 2, selected.length); - assertEquals("3.1", assoc1, selected[1]); - assertEquals("3.2", text, selected[0]); + assertThat(selected).containsExactly(text, assoc1); // text user-added associations selected = finder.findContentTypesFor(changeCase("text.txt_useradded")); - assertEquals("4.0", 2, selected.length); - assertEquals("4.1", assoc1, selected[1]); - assertEquals("4.2", text, selected[0]); + assertThat(selected).containsExactly(text, assoc1); // text provider-added associations selected = finder.findContentTypesFor(changeCase("text.txt_pluginadded")); - assertEquals("5.0", 2, selected.length); - assertEquals("5.1", assoc1, selected[1]); - assertEquals("5.2", text, selected[0]); + assertThat(selected).containsExactly(text, assoc1); selected = finder.findContentTypesFor(changeCase("text.txt_assoc1pluginadded")); - assertEquals("6.0", 1, selected.length); - assertEquals("6.1", assoc1, selected[0]); + assertThat(selected).containsExactly(assoc1); selected = finder.findContentTypesFor(changeCase("text.txt_assoc1useradded")); - assertEquals("7.0", 1, selected.length); - assertEquals("7.1", assoc1, selected[0]); + assertThat(selected).containsExactly(assoc1); selected = finder.findContentTypesFor(changeCase("text.txt_assoc2pluginadded")); - assertEquals("8.0", 1, selected.length); - assertEquals("8.1", assoc2, selected[0]); + assertThat(selected).containsExactly(assoc2); selected = finder.findContentTypesFor(changeCase("text.txt_assoc2useradded")); - assertEquals("9.0", 1, selected.length); - assertEquals("9.1", assoc2, selected[0]); + assertThat(selected).containsExactly(assoc2); selected = finder.findContentTypesFor(changeCase("text.txt_assoc2builtin")); - assertEquals("10.0", 1, selected.length); - assertEquals("10.1", assoc2, selected[0]); + assertThat(selected).containsExactly(assoc2); } @Test @@ -298,29 +291,29 @@ public void testAssociations() throws CoreException { // check provider defined settings String[] providerDefinedExtensions = text .getFileSpecs(IContentType.FILE_EXTENSION_SPEC | IContentType.IGNORE_USER_DEFINED); - assertTrue("1.0", contains(providerDefinedExtensions, "txt")); - assertFalse("1.1", contains(providerDefinedExtensions, "txt_useradded")); - assertTrue("1.2", contains(providerDefinedExtensions, "txt_pluginadded")); + assertThat(providerDefinedExtensions).contains("txt"); + assertThat(providerDefinedExtensions).doesNotContain("txt_useradded"); + assertThat(providerDefinedExtensions).contains("txt_pluginadded"); // check user defined settings String[] textUserDefinedExtensions = text .getFileSpecs(IContentType.FILE_EXTENSION_SPEC | IContentType.IGNORE_PRE_DEFINED); - assertFalse("2.0", contains(textUserDefinedExtensions, "txt")); - assertTrue("2.1", contains(textUserDefinedExtensions, "txt_useradded")); - assertFalse("2.2", contains(textUserDefinedExtensions, "txt_pluginadded")); + assertThat(textUserDefinedExtensions).doesNotContain("txt"); + assertThat(textUserDefinedExtensions).contains("txt_useradded"); + assertThat(textUserDefinedExtensions).doesNotContain("txt_pluginadded"); // removing pre-defined file specs should not do anything text.removeFileSpec("txt", IContentType.FILE_EXTENSION_SPEC); - assertTrue("3.0", contains( - text.getFileSpecs(IContentType.FILE_EXTENSION_SPEC | IContentType.IGNORE_USER_DEFINED), "txt")); + assertThat(text.getFileSpecs(IContentType.FILE_EXTENSION_SPEC | IContentType.IGNORE_USER_DEFINED)) + .contains("txt"); assertTrue("3.1", text.isAssociatedWith(changeCase("text.txt"))); assertTrue("3.2", text.isAssociatedWith(changeCase("text.txt_useradded"))); assertTrue("3.3", text.isAssociatedWith(changeCase("text.txt_pluginadded"))); // removing user file specs is the normal case and has to work as expected text.removeFileSpec("txt_useradded", IContentType.FILE_EXTENSION_SPEC); - assertFalse("4.0", - contains(text.getFileSpecs(IContentType.FILE_EXTENSION_SPEC | IContentType.IGNORE_PRE_DEFINED), "ini")); + assertThat(text.getFileSpecs(IContentType.FILE_EXTENSION_SPEC | IContentType.IGNORE_PRE_DEFINED)) + .doesNotContain("ini"); assertTrue("4.1", text.isAssociatedWith(changeCase("text.txt"))); assertFalse("4.2", text.isAssociatedWith(changeCase("text.txt_useradded"))); assertTrue("4.3", text.isAssociatedWith(changeCase("text.txt_pluginadded"))); @@ -349,8 +342,8 @@ public void testBinaryTypes() throws IOException { // (see bug 100032) // first check if our test environment is sane IContentType[] selected = contentTypeManager.findContentTypesFor("test.samplebin2"); - assertEquals("8.1", 1, selected.length); - assertEquals("8.2", sampleBinary2.getId(), selected[0].getId()); + assertThat(selected).hasSize(1) + .allSatisfy(element -> assertThat(element.getId()).isEqualTo(sampleBinary2.getId())); // (we used to blow up here) description = contentTypeManager.getDescriptionFor(getReader(getRandomString()), "test.samplebin2", IContentDescription.ALL); @@ -459,40 +452,40 @@ public void testContentAndNameMatching() throws IOException /* not really */ { IContentType[] selected; selected = manager.findContentTypesFor(getInputStream(contents0), "anything.mybinary"); - assertEquals("1.0", 3, selected.length); + assertThat(selected).hasSize(3); // all we know is the first one is the base type (only one with a VALID match) assertEquals("1.1", base, selected[0]); selected = manager.findContentTypesFor(getInputStream(contents0), "foo.mybinary"); // we know also that the second one will be derived1, because it has a full name // matching - assertEquals("2.0", 3, selected.length); + assertThat(selected).hasSize(3); assertEquals("2.1", base, selected[0]); assertEquals("2.2", derived1, selected[1]); selected = manager.findContentTypesFor(getInputStream(contents1), "foo.mybinary"); // derived1 will be first because both base and derived1 have a strong content // matching, so more specific wins - assertEquals("3.0", 3, selected.length); + assertThat(selected).hasSize(3); assertEquals("3.1", derived1, selected[0]); assertEquals("3.2", base, selected[1]); selected = manager.findContentTypesFor(getInputStream(contents2), "foo.mybinary"); // same as 3.* - derived1 is last because content matching is weak, althoug name // matching is strong - assertEquals("4.0", 3, selected.length); + assertThat(selected).hasSize(3); assertEquals("4.1", derived2, selected[0]); assertEquals("4.2", base, selected[1]); selected = manager.findContentTypesFor(getInputStream(invalidContents), "foo.mybinary"); // all types have weak content matching only - derived1 has strong name matching - assertEquals("5.0", 3, selected.length); + assertThat(selected).hasSize(3); assertEquals("5.1", derived1, selected[0]); assertEquals("5.2", base, selected[1]); selected = manager.findContentTypesFor(getInputStream(invalidContents), "anything.mybinary"); // all types have weak content/name matching only - most general wins - assertEquals("6.0", 3, selected.length); + assertThat(selected).hasSize(3); assertEquals("6.1", base, selected[0]); } @@ -654,10 +647,11 @@ public void testContentDetection() throws IOException { new IContentType[] { inappropriate, appropriate, appropriateSpecific1, appropriateSpecific2 }), null); IContentType[] selected = finder.findContentTypesFor(getInputStream(MINIMAL_XML), null); - assertEquals("4.0", 3, selected.length); - assertTrue("4.1", appropriateSpecific1.equals(selected[0]) || appropriateSpecific1.equals(selected[1])); - assertTrue("4.2", appropriateSpecific2.equals(selected[0]) || appropriateSpecific2.equals(selected[1])); - assertTrue("4.3", appropriate.equals(selected[2])); + assertThat(selected).satisfiesAnyOf( + elements -> assertThat(elements).containsExactly(appropriateSpecific1, appropriateSpecific2, + appropriate), + elements -> assertThat(elements).containsExactly(appropriateSpecific2, appropriateSpecific1, + appropriate)); // if appropriate and a more specific appropriate type (but with low priority) // are provided, the specific type will be selected @@ -742,9 +736,7 @@ public void testDoubleAssociation() { // ensure we don't get fooBar twice IContentTypeMatcher finder = contentTypeManager.getMatcher(new LocalSelectionPolicy(), null); IContentType[] fooBarAssociated = finder.findContentTypesFor(changeCase("foo.bar")); - assertEquals("2.1", 2, fooBarAssociated.length); - assertTrue("2.2", contains(fooBarAssociated, fooBarType)); - assertTrue("2.3", contains(fooBarAssociated, subFooBarType)); + assertThat(fooBarAssociated).containsExactlyInAnyOrder(fooBarType, subFooBarType); } /** @@ -899,9 +891,7 @@ public void testFileSpecConflicts() throws IOException { // when submitting contents, for related types with indeterminate match, general // comes first IContentType[] selectedConflict2 = manager.findContentTypesFor(getRandomContents(), "test.conflict2"); - assertEquals("2.2", 2, selectedConflict2.length); - assertEquals("2.3", selectedConflict2[0], conflict2base); - assertEquals("2.4", selectedConflict2[1], conflict2sub); + assertThat(selectedConflict2).containsExactly(conflict2base, conflict2sub); IContentType conflict2abase = manager.getContentType(PI_RESOURCES_TESTS + ".base_conflict2a"); IContentType conflict2asub = manager.getContentType(PI_RESOURCES_TESTS + ".sub_conflict2a"); @@ -912,15 +902,11 @@ public void testFileSpecConflicts() throws IOException { // comes first IContentType[] selectedConflict2a = manager .findContentTypesFor(getInputStream("conflict2a", StandardCharsets.UTF_8), "test.conflict2a"); - assertEquals("2.7", 2, selectedConflict2a.length); - assertEquals("2.8", selectedConflict2a[0], conflict2asub); - assertEquals("2.9", selectedConflict2a[1], conflict2abase); + assertThat(selectedConflict2a).containsExactly(conflict2asub, conflict2abase); // when not submitting contents, for related types, most general type prevails selectedConflict2a = manager.findContentTypesFor("test.conflict2a"); - assertEquals("2.10", 2, selectedConflict2a.length); - assertEquals("2.11", selectedConflict2a[0], conflict2abase); - assertEquals("2.12", selectedConflict2a[1], conflict2asub); + assertThat(selectedConflict2a).containsExactly(conflict2abase, conflict2asub); IContentType conflict3base = manager.getContentType(PI_RESOURCES_TESTS + ".base_conflict3"); IContentType conflict3sub = manager.getContentType(PI_RESOURCES_TESTS + ".sub_conflict3"); @@ -933,9 +919,7 @@ public void testFileSpecConflicts() throws IOException { // Order will be arbitrary (lexicographically). IContentType[] selectedConflict3 = manager.findContentTypesFor(getRandomContents(), "test.conflict3"); - assertEquals("4.0", 2, selectedConflict3.length); - assertEquals("4.1", selectedConflict3[0], conflict3sub); - assertEquals("4.2", selectedConflict3[1], conflict3unrelated); + assertThat(selectedConflict3).containsExactly(conflict3sub, conflict3unrelated); IContentType conflict4base = manager.getContentType(PI_RESOURCES_TESTS + ".base_conflict4"); IContentType conflict4sub = manager.getContentType(PI_RESOURCES_TESTS + ".sub_conflict4"); @@ -949,9 +933,7 @@ public void testFileSpecConflicts() throws IOException { // Order will be based on priority IContentType[] selectedConflict4 = manager.findContentTypesFor(getRandomContents(), "test.conflict4"); - assertEquals("6.0", 2, selectedConflict4.length); - assertEquals("6.1", selectedConflict4[0], conflict4sub); - assertEquals("6.2", selectedConflict4[1], conflict4unrelated_lowPriority); + assertThat(selectedConflict4).containsExactly(conflict4sub, conflict4unrelated_lowPriority); IContentType conflict5base = manager.getContentType(PI_RESOURCES_TESTS + ".base_conflict5"); IContentType conflict5sub_lowPriority = manager.getContentType(PI_RESOURCES_TESTS + ".sub_conflict5"); @@ -965,9 +947,7 @@ public void testFileSpecConflicts() throws IOException { // Order will be based on priority IContentType[] selectedConflict5 = manager.findContentTypesFor(getRandomContents(), "test.conflict5"); - assertEquals("7.0", 2, selectedConflict5.length); - assertEquals("7.1", selectedConflict5[0], conflict5unrelated); - assertEquals("7.2", selectedConflict5[1], conflict5sub_lowPriority); + assertThat(selectedConflict5).containsExactly(conflict5unrelated, conflict5sub_lowPriority); } @Test @@ -989,7 +969,7 @@ public void testFindContentType() throws IOException { assertEquals("2.1", xmlContentType, single); IContentType[] multiple = finder.findContentTypesFor(getInputStream(XML_UTF_8, StandardCharsets.UTF_8), null); - assertTrue("3.0", contains(multiple, xmlContentType)); + assertThat(multiple).contains(xmlContentType); } @Test @@ -1046,15 +1026,15 @@ public void testImportFileAssociation() throws CoreException { public void testInvalidMarkup() { final IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); IContentTypeMatcher finder = contentTypeManager.getMatcher(new LocalSelectionPolicy(), null); - assertEquals("1.0", 0, finder.findContentTypesFor("invalid.missing.identifier").length); - assertEquals("2.0", 0, finder.findContentTypesFor("invalid.missing.name").length); + assertThat(finder.findContentTypesFor("invalid.missing.identifier")).isEmpty(); + assertThat(finder.findContentTypesFor("invalid.missing.name")).isEmpty(); assertNull("3.0", contentTypeManager.getContentType(PI_RESOURCES_TESTS + '.' + "invalid-missing-name")); TestRegistryChangeListener listener = new TestRegistryChangeListener(Platform.PI_RUNTIME, ContentTypeBuilder.PT_CONTENTTYPES, null, null); BundleTestingHelper.runWithBundles("1", () -> { // ensure the invalid content types are not available - assertEquals("1.2", 0, contentTypeManager.findContentTypesFor("invalid.missing.identifier").length); - assertEquals("1.3", 0, contentTypeManager.findContentTypesFor("invalid.missing.name").length); + assertThat(contentTypeManager.findContentTypesFor("invalid.missing.identifier")).isEmpty(); + assertThat(contentTypeManager.findContentTypesFor("invalid.missing.name")).isEmpty(); assertNull("1.4", contentTypeManager.getContentType("org.eclipse.bundle03.invalid-missing-name")); // this content type has good markup, but invalid describer class IContentType invalidDescriber = contentTypeManager.getContentType("org.eclipse.bundle03.invalid-describer"); @@ -1084,8 +1064,7 @@ public void testIOException() throws IOException { // XMLRootElementDescriber in these cases IContentType[] selected = manager .findContentTypesFor(getInputStream(XML_US_ASCII_INVALID, StandardCharsets.ISO_8859_1), "test.xml"); - assertTrue("1.1", contains(selected, xml)); - assertTrue("1.2", contains(selected, rootElement)); + assertThat(selected).contains(xml, rootElement); // induce regular IOExceptions... these should be thrown to clients class FakeIOException extends IOException { @@ -1143,56 +1122,27 @@ public void testIsKindOf() { public void testListParsing() { String[] list; list = Util.parseItems(null); - assertEquals("0.0", 0, list.length); + assertThat(list).isEmpty(); list = Util.parseItems(""); - assertEquals("1.0", 1, list.length); - assertEquals("1.1", "", list[0]); + assertThat(list).containsExactly(""); list = Util.parseItems("foo"); - assertEquals("2.0", 1, list.length); - assertEquals("2.1", "foo", list[0]); + assertThat(list).containsExactly("foo"); list = Util.parseItems(","); - assertEquals("3.0", 2, list.length); - assertEquals("3.1", "", list[0]); - assertEquals("3.2", "", list[1]); + assertThat(list).containsExactly("", ""); list = Util.parseItems(",foo,bar"); - assertEquals("4.0", 3, list.length); - assertEquals("4.1", "", list[0]); - assertEquals("4.2", "foo", list[1]); - assertEquals("4.3", "bar", list[2]); + assertThat(list).containsExactly("", "foo", "bar"); list = Util.parseItems("foo,bar,"); - assertEquals("5.0", 3, list.length); - assertEquals("5.1", "foo", list[0]); - assertEquals("5.2", "bar", list[1]); - assertEquals("5.3", "", list[2]); + assertThat(list).containsExactly("foo", "bar", ""); list = Util.parseItems("foo,,bar"); - assertEquals("6.0", 3, list.length); - assertEquals("6.1", "foo", list[0]); - assertEquals("6.2", "", list[1]); - assertEquals("6.3", "bar", list[2]); + assertThat(list).containsExactly("foo", "", "bar"); list = Util.parseItems("foo,,,bar"); - assertEquals("7.0", 4, list.length); - assertEquals("7.1", "foo", list[0]); - assertEquals("7.2", "", list[1]); - assertEquals("7.3", "", list[2]); - assertEquals("7.4", "bar", list[3]); + assertThat(list).containsExactly("foo", "", "", "bar"); list = Util.parseItems(",,foo,bar"); - assertEquals("8.0", 4, list.length); - assertEquals("8.1", "", list[0]); - assertEquals("8.2", "", list[1]); - assertEquals("8.3", "foo", list[2]); - assertEquals("8.4", "bar", list[3]); + assertThat(list).containsExactly("", "", "foo", "bar"); list = Util.parseItems("foo,bar,,"); - assertEquals("9.0", 4, list.length); - assertEquals("9.1", "foo", list[0]); - assertEquals("9.2", "bar", list[1]); - assertEquals("9.3", "", list[2]); - assertEquals("9.4", "", list[3]); + assertThat(list).containsExactly("foo", "bar", "", ""); list = Util.parseItems(",,,"); - assertEquals("10.0", 4, list.length); - assertEquals("10.1", "", list[0]); - assertEquals("10.2", "", list[1]); - assertEquals("10.3", "", list[2]); - assertEquals("10.4", "", list[3]); + assertThat(list).containsExactly("", "", "", ""); } @Test @@ -1222,7 +1172,7 @@ public void testNoExtensionAssociation() { final IContentTypeManager manager = Platform.getContentTypeManager(); IContentType[] selected = manager.findContentTypesFor("file_with_no_extension"); - assertEquals("0.1", 0, selected.length); + assertThat(selected).isEmpty(); TestRegistryChangeListener listener = new TestRegistryChangeListener(Platform.PI_RUNTIME, ContentTypeBuilder.PT_CONTENTTYPES, null, null); @@ -1242,15 +1192,10 @@ public void testNoExtensionAssociation() { assertNotNull("1.1.5", nonEmpty); IContentType[] selected1 = manager.findContentTypesFor("file_with_no_extension"); - assertEquals("1.2.0", 4, selected1.length); - assertTrue("1.2.1", contains(selected1, empty1)); - assertTrue("1.2.2", contains(selected1, empty2)); - assertTrue("1.2.3", contains(selected1, empty3)); - assertTrue("1.2.4", contains(selected1, empty4)); + assertThat(selected1).containsExactlyInAnyOrder(empty1, empty2, empty3, empty4); selected1 = manager.findContentTypesFor("file_with_extension.non-empty"); - assertEquals("1.2.5", 1, selected1.length); - assertTrue("1.2.6", contains(selected1, nonEmpty)); + assertThat(selected1).containsExactly(nonEmpty); try { nonEmpty.addFileSpec("", IContentType.FILE_EXTENSION_SPEC); @@ -1259,8 +1204,7 @@ public void testNoExtensionAssociation() { } try { selected1 = manager.findContentTypesFor("file_with_no_extension"); - assertEquals("1.3.1", 5, selected1.length); - assertTrue("1.3.2", contains(selected1, nonEmpty)); + assertThat(selected1).hasSize(5).containsOnlyOnce(nonEmpty); } finally { try { nonEmpty.removeFileSpec("", IContentType.FILE_EXTENSION_SPEC); @@ -1269,8 +1213,7 @@ public void testNoExtensionAssociation() { } } selected1 = manager.findContentTypesFor("file_with_no_extension"); - assertEquals("1.4.0", 4, selected1.length); - assertFalse("1.4.1", contains(selected1, nonEmpty)); + assertThat(selected1).hasSize(4).doesNotContain(nonEmpty); }, getContext(), new String[] { ContentTypeTest.TEST_FILES_ROOT + "content/bundle04" }, listener); } @@ -1300,9 +1243,9 @@ public void testOrphanContentType() { assertNull("0.8", orphan); IContentType missing = contentTypeManager.getContentType("org.eclipse.bundle01.missing"); assertNull("0.9", missing); - assertEquals("1.1", 0, contentTypeManager.findContentTypesFor("foo.orphan").length); - assertEquals("1.2", 0, contentTypeManager.findContentTypesFor("orphan.orphan").length); - assertEquals("1.3", 0, contentTypeManager.findContentTypesFor("foo.orphan2").length); + assertThat(contentTypeManager.findContentTypesFor("foo.orphan")).isEmpty(); + assertThat(contentTypeManager.findContentTypesFor("orphan.orphan")).isEmpty(); + assertThat(contentTypeManager.findContentTypesFor("foo.orphan2")).isEmpty(); // test late addition of content type - orphan2 should become visible TestRegistryChangeListener listener = new TestRegistryChangeListener(Platform.PI_RUNTIME, @@ -1314,13 +1257,10 @@ public void testOrphanContentType() { IContentType missing1 = contentTypeManager.getContentType("org.eclipse.bundle01.missing"); assertNotNull("2.2", missing1); // checks orphan's associations - assertEquals("2.3", 1, contentTypeManager.findContentTypesFor("foo.orphan").length); - assertEquals("2.4", orphan1, contentTypeManager.findContentTypesFor("foo.orphan")[0]); - assertEquals("2.5", 1, contentTypeManager.findContentTypesFor("orphan.orphan").length); - assertEquals("2.6", orphan1, contentTypeManager.findContentTypesFor("foo.orphan")[0]); + assertThat(contentTypeManager.findContentTypesFor("foo.orphan")).containsExactly(orphan1); + assertThat(contentTypeManager.findContentTypesFor("orphan.orphan")).containsExactly(orphan1); // check whether an orphan association was added to the dynamically added bundle - assertEquals("2.7", 1, contentTypeManager.findContentTypesFor("foo.orphan2").length); - assertEquals("2.8", missing1, contentTypeManager.findContentTypesFor("foo.orphan2")[0]); + assertThat(contentTypeManager.findContentTypesFor("foo.orphan2")).containsExactly(missing1); }, getContext(), new String[] { ContentTypeTest.TEST_FILES_ROOT + "content/bundle01" }, listener); } @@ -1421,7 +1361,7 @@ public void testRegistry() { assertEquals("4.2", xmlContentType, xmlBasedSpecificNameContentType.getBaseType()); IContentType[] xmlTypes = finder.findContentTypesFor(changeCase("foo.xml")); - assertTrue("5.1", contains(xmlTypes, xmlContentType)); + assertThat(xmlTypes).contains(xmlContentType); IContentType binaryContentType = contentTypeManager.getContentType(PI_RESOURCES_TESTS + '.' + "sample-binary1"); assertNotNull("6.0", binaryContentType); @@ -1429,22 +1369,20 @@ public void testRegistry() { assertNull("6.2", binaryContentType.getBaseType()); IContentType[] binaryTypes = finder.findContentTypesFor(changeCase("foo.samplebin1")); - assertEquals("7.0", 1, binaryTypes.length); - assertEquals("7.1", binaryContentType, binaryTypes[0]); + assertThat(binaryTypes).containsExactly(binaryContentType); IContentType myText = contentTypeManager.getContentType(PI_RESOURCES_TESTS + ".mytext"); assertNotNull("8.0", myText); assertEquals("8.1", "BAR", myText.getDefaultCharset()); IContentType[] fooBarTypes = finder.findContentTypesFor(changeCase("foo.bar")); - assertEquals("9.0", 2, fooBarTypes.length); + assertThat(fooBarTypes).hasSize(2); IContentType fooBar = contentTypeManager.getContentType(PI_RESOURCES_TESTS + ".fooBar"); assertNotNull("9.1", fooBar); IContentType subFooBar = contentTypeManager.getContentType(PI_RESOURCES_TESTS + ".subFooBar"); assertNotNull("9.2", subFooBar); - assertTrue("9.3", contains(fooBarTypes, fooBar)); - assertTrue("9.4", contains(fooBarTypes, subFooBar)); + assertThat(fooBarTypes).contains(fooBar, subFooBar); } @Test @@ -1460,63 +1398,50 @@ public void testRootElementAndDTDDescriber() throws IOException { IContentType[] contentTypes = contentTypeManager.findContentTypesFor( getInputStream(XML_ROOT_ELEMENT_ISO_8859_1, StandardCharsets.ISO_8859_1), "fake.xml"); - assertTrue("1.0", contentTypes.length > 0); - assertEquals("1.1", rootElement, contentTypes[0]); + assertThat(contentTypes).hasSizeGreaterThan(0).contains(rootElement, atIndex(0)); // bugs 64053 and 63298 contentTypes = contentTypeManager.findContentTypesFor( getInputStream(XML_ROOT_ELEMENT_EXTERNAL_ENTITY, StandardCharsets.UTF_8), "fake.xml"); - assertTrue("2.0", contentTypes.length > 0); - assertEquals("2.1", rootElement, contentTypes[0]); + assertThat(contentTypes).hasSizeGreaterThan(0).contains(rootElement, atIndex(0)); // bug 63625 contentTypes = contentTypeManager.findContentTypesFor( getInputStream(XML_ROOT_ELEMENT_EXTERNAL_ENTITY2, StandardCharsets.UTF_8), "fake.xml"); - assertTrue("3.0", contentTypes.length > 0); - assertEquals("3.1", rootElement, contentTypes[0]); + assertThat(contentTypes).hasSizeGreaterThan(0).contains(rootElement, atIndex(0)); // bug 135575 contentTypes = contentTypeManager .findContentTypesFor(getInputStream(XML_ROOT_ELEMENT_NS_MATCH1, StandardCharsets.UTF_8), "fake.xml"); - assertTrue("4.0", contentTypes.length > 0); - assertEquals("4.1", nsRootElement, contentTypes[0]); + assertThat(contentTypes).hasSizeGreaterThan(0).contains(nsRootElement, atIndex(0)); contentTypes = contentTypeManager .findContentTypesFor(getInputStream(XML_ROOT_ELEMENT_NS_MATCH2, StandardCharsets.UTF_8), "fake.xml"); - assertTrue("4.2", contentTypes.length > 0); - assertEquals("4.3", nsRootElement, contentTypes[0]); + assertThat(contentTypes).hasSizeGreaterThan(0).contains(nsRootElement, atIndex(0)); contentTypes = contentTypeManager.findContentTypesFor( getInputStream(XML_ROOT_ELEMENT_NS_WRONG_ELEM, StandardCharsets.UTF_8), "fake.xml"); - assertTrue("4.4", contentTypes.length > 0); - assertEquals("4.5", xmlType, contentTypes[0]); + assertThat(contentTypes).hasSizeGreaterThan(0).contains(xmlType, atIndex(0)); contentTypes = contentTypeManager .findContentTypesFor(getInputStream(XML_ROOT_ELEMENT_NS_WRONG_NS, StandardCharsets.UTF_8), "fake.xml"); - assertTrue("4.6", contentTypes.length > 0); - assertEquals("4.7", xmlType, contentTypes[0]); + assertThat(contentTypes).hasSizeGreaterThan(0).contains(xmlType, atIndex(0)); contentTypes = contentTypeManager .findContentTypesFor(getInputStream(XML_ROOT_ELEMENT_NS_MIXUP, StandardCharsets.UTF_8), "fake.xml"); - assertTrue("4.8", contentTypes.length > 0); - assertEquals("4.9", xmlType, contentTypes[0]); + assertThat(contentTypes).hasSizeGreaterThan(0).contains(xmlType, atIndex(0)); contentTypes = contentTypeManager .findContentTypesFor(getInputStream(XML_ROOT_ELEMENT_NS_WILDCARD, StandardCharsets.UTF_8), "fake.xml"); - assertTrue("4.10", contentTypes.length > 0); - assertEquals("4.11", nsWildcard, contentTypes[0]); + assertThat(contentTypes).hasSizeGreaterThan(0).contains(nsWildcard, atIndex(0)); contentTypes = contentTypeManager .findContentTypesFor(getInputStream(XML_ROOT_ELEMENT_NS_WILDCARD2, StandardCharsets.UTF_8), "fake.xml"); - assertTrue("4.12", contentTypes.length > 0); - assertEquals("4.13", nsWildcard, contentTypes[0]); + assertThat(contentTypes).hasSizeGreaterThan(0).contains(nsWildcard, atIndex(0)); contentTypes = contentTypeManager .findContentTypesFor(getInputStream(XML_ROOT_ELEMENT_EMPTY_NS, StandardCharsets.UTF_8), "fake.xml"); - assertTrue("4.14", contentTypes.length > 0); - assertEquals("4.15", emptyNsRootElement, contentTypes[0]); + assertThat(contentTypes).hasSizeGreaterThan(0).contains(emptyNsRootElement, atIndex(0)); contentTypes = contentTypeManager .findContentTypesFor(getInputStream(XML_DTD_US_ASCII, StandardCharsets.US_ASCII), "fake.xml"); - assertTrue("5.0", contentTypes.length > 0); - assertEquals("5.1", dtdElement, contentTypes[0]); + assertThat(contentTypes).hasSizeGreaterThan(0).contains(dtdElement, atIndex(0)); contentTypes = contentTypeManager .findContentTypesFor(getInputStream(XML_DTD_EXTERNAL_ENTITY, StandardCharsets.UTF_8), "fake.xml"); - assertTrue("5.4", contentTypes.length > 0); - assertEquals("5.5", dtdElement, contentTypes[0]); + assertThat(contentTypes).hasSizeGreaterThan(0).contains(dtdElement, atIndex(0)); // bug 67975 IContentDescription description = contentTypeManager.getDescriptionFor(getInputStream( @@ -1549,8 +1474,8 @@ public void testRootElementAndDTDDescriber() throws IOException { // bug 84354 contentTypes = contentTypeManager .findContentTypesFor(getInputStream(XML_ROOT_ELEMENT_NO_DECL, StandardCharsets.UTF_8), "test.txt"); - assertTrue("8.0", contentTypes.length > 0); - assertEquals("8.1", contentTypeManager.getContentType(IContentTypeManager.CT_TEXT), contentTypes[0]); + assertThat(contentTypes).hasSizeGreaterThan(0) + .contains(contentTypeManager.getContentType(IContentTypeManager.CT_TEXT), atIndex(0)); } /** @@ -1608,9 +1533,7 @@ public void testDescriberInvalidation() throws IOException { IContentType[] contentTypes = contentTypeManager.findContentTypesFor( getInputStream(XML_ROOT_ELEMENT_NS_MATCH2, StandardCharsets.UTF_8), "Bug182337.Bug182337"); - assertEquals("1.0", 2, contentTypes.length); - assertEquals("1.1", type_bug182337_A, contentTypes[0]); - assertEquals("1.1", type_bug182337_B, contentTypes[1]); + assertThat(contentTypes).containsExactly(type_bug182337_A, type_bug182337_B); InputStream is = new InputStream() { @Override @@ -1620,12 +1543,12 @@ public int read() { } }; contentTypes = contentTypeManager.findContentTypesFor(is, "Bug182337.Bug182337"); - assertEquals("1.2", 0, contentTypes.length); + assertThat(contentTypes).isEmpty(); // Describer should be invalidated by now contentTypes = contentTypeManager.findContentTypesFor( getInputStream(XML_ROOT_ELEMENT_NS_MATCH2, StandardCharsets.UTF_8), "Bug182337.Bug182337"); - assertEquals("1.3", 0, contentTypes.length); + assertThat(contentTypes).isEmpty(); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyInputStreamTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyInputStreamTest.java index 18ad74bf4fa..ca53e61a60e 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyInputStreamTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyInputStreamTest.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.content; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; @@ -91,7 +92,7 @@ public void testReadBlock() throws IOException { stream.skip(4); byte[] buffer = new byte[7]; int read = stream.read(buffer); - assertEquals("1.0", buffer.length, read); + assertThat(buffer).hasSize(read); assertEquals("1.1", DATA.substring(4, 4 + buffer.length), new String(buffer)); assertEquals("1.2", 11, stream.getOffset()); read = stream.read(buffer, 3, 4); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyReaderTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyReaderTest.java index 953081778cc..a005f494cb2 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyReaderTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/LazyReaderTest.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.content; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -90,7 +91,7 @@ public void testReadBlock() throws IOException { stream.skip(4); char[] buffer = new char[7]; int read = stream.read(buffer); - assertEquals("1.0", buffer.length, read); + assertThat(buffer).hasSize(read); assertEquals("1.1", DATA.substring(4, 4 + buffer.length), new String(buffer)); assertEquals("1.2", 11, stream.getOffset()); read = stream.read(buffer, 3, 4); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/SpecificContextTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/SpecificContextTest.java index a619501b153..1ea29c7f613 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/SpecificContextTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/SpecificContextTest.java @@ -13,14 +13,20 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.content; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.eclipse.core.internal.content.ContentTypeManager; import org.eclipse.core.internal.preferences.EclipsePreferences; -import org.eclipse.core.runtime.*; -import org.eclipse.core.runtime.content.*; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.core.runtime.content.IContentTypeManager; +import org.eclipse.core.runtime.content.IContentTypeMatcher; +import org.eclipse.core.runtime.content.IContentTypeSettings; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IScopeContext; import org.junit.Rule; @@ -104,8 +110,7 @@ public void testIsAssociatedWith() throws CoreException { localSettings = textContentType.getSettings(scope); // scope-specific settings should contain the filespec we just added String[] fileSpecs = localSettings.getFileSpecs(IContentType.FILE_EXTENSION_SPEC); - assertEquals("2.2", 1, fileSpecs.length); - assertEquals("2.3", "foo", fileSpecs[0]); + assertThat(fileSpecs).containsExactly("foo"); // now it is associated at the scope level... assertTrue("2.5", textContentType.isAssociatedWith("hello.foo", scope)); // ...but not at the global level diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/TestBug94498.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/TestBug94498.java index bfb06ba8ece..8069b396b9b 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/TestBug94498.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/TestBug94498.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.content; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS; import junit.framework.Test; @@ -33,18 +34,16 @@ public static Test suite() { public void test1() throws CoreException { IContentType text = Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT); - assertNotNull("1.0", text); + assertThat(text).isNotNull(); text.addFileSpec(FILE_NAME, IContentType.FILE_NAME_SPEC); String[] fileSpecs = text.getFileSpecs(IContentType.FILE_NAME_SPEC | IContentType.IGNORE_PRE_DEFINED); - assertEquals("2.0", 1, fileSpecs.length); - assertEquals("2.1", FILE_NAME, fileSpecs[0]); + assertThat(fileSpecs).containsExactly(FILE_NAME); } public void test2() { IContentType text = Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT); - assertNotNull("1.0", text); + assertThat(text).isNotNull(); String[] fileSpecs = text.getFileSpecs(IContentType.FILE_NAME_SPEC | IContentType.IGNORE_PRE_DEFINED); - assertEquals("2.0", 1, fileSpecs.length); - assertEquals("2.1", FILE_NAME, fileSpecs[0]); + assertThat(fileSpecs).containsExactly(FILE_NAME); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/refresh/RefreshProviderTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/refresh/RefreshProviderTest.java index 22540291df5..9ea5c23b8e6 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/refresh/RefreshProviderTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/refresh/RefreshProviderTest.java @@ -19,7 +19,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.removeFromWorkspace; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -89,16 +88,16 @@ public void testLinkedFile() throws Exception { IFile link = project.getFile("Link"); // ensure we currently have just the project being monitored TestRefreshProvider provider = TestRefreshProvider.getInstance(); - assertEquals("1.0", 1, provider.getMonitoredResources().length); + assertThat(provider.getMonitoredResources()).hasSize(1); link.createLink(location, IResource.ALLOW_MISSING_LOCAL, createTestMonitor()); joinAutoRefreshJobs(); - assertEquals("1.1", 2, provider.getMonitoredResources().length); + assertThat(provider.getMonitoredResources()).hasSize(2); link.delete(IResource.FORCE, createTestMonitor()); joinAutoRefreshJobs(); - assertEquals("1.2", 1, provider.getMonitoredResources().length); + assertThat(provider.getMonitoredResources()).hasSize(1); removeFromWorkspace(project); joinAutoRefreshJobs(); - assertEquals("1.3", 0, provider.getMonitoredResources().length); + assertThat(provider.getMonitoredResources()).isEmpty(); // check provider for other errors AssertionFailedError[] failures = provider.getFailures(); assertThat(failures).isEmpty(); @@ -116,16 +115,16 @@ public void testProjectCloseOpen() throws Exception { joinAutoRefreshJobs(); // ensure we currently have just the project being monitored TestRefreshProvider provider = TestRefreshProvider.getInstance(); - assertEquals("1.0", 1, provider.getMonitoredResources().length); + assertThat(provider.getMonitoredResources()).hasSize(1); project.close(createTestMonitor()); joinAutoRefreshJobs(); - assertEquals("1.1", 0, provider.getMonitoredResources().length); + assertThat(provider.getMonitoredResources()).isEmpty(); project.open(createTestMonitor()); joinAutoRefreshJobs(); - assertEquals("1.2", 1, provider.getMonitoredResources().length); + assertThat(provider.getMonitoredResources()).hasSize(1); removeFromWorkspace(project); joinAutoRefreshJobs(); - assertEquals("1.3", 0, provider.getMonitoredResources().length); + assertThat(provider.getMonitoredResources()).isEmpty(); // check provider for other errors AssertionFailedError[] failures = provider.getFailures(); assertThat(failures).isEmpty(); 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 49533ee1397..a306838d280 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 @@ -13,8 +13,8 @@ *******************************************************************************/ 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.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; @@ -69,23 +69,20 @@ public void testBug() { IPathVariableManager pvm = getWorkspace().getPathVariableManager(); Preferences prefs = ResourcesPlugin.getPlugin().getPluginPreferences(); - assertEquals("1.0", 0, pvm.getPathVariableNames().length); + assertThat(pvm.getPathVariableNames()).isEmpty(); prefs.setValue(VARIABLE_PREFIX + "VALID_VAR", IPath.fromOSString("c:/temp").toPortableString()); - assertEquals("1.1", 1, pvm.getPathVariableNames().length); - assertEquals("1.2", "VALID_VAR", pvm.getPathVariableNames()[0]); + assertThat(pvm.getPathVariableNames()).containsExactly("VALID_VAR"); //sets invalid value (relative path) IPath relativePath = IPath.fromOSString("temp"); prefs.setValue(VARIABLE_PREFIX + "INVALID_VAR", relativePath.toPortableString()); - assertEquals("2.0", 1, pvm.getPathVariableNames().length); - assertEquals("2.1", "VALID_VAR", pvm.getPathVariableNames()[0]); + assertThat(pvm.getPathVariableNames()).containsExactly("VALID_VAR"); //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())); - assertEquals("3.1", 1, pvm.getPathVariableNames().length); - assertEquals("3.2", "VALID_VAR", pvm.getPathVariableNames()[0]); + assertThat(pvm.getPathVariableNames()).containsExactly("VALID_VAR"); } } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_079398.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_079398.java index d32ed8bb151..1adba848a90 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_079398.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_079398.java @@ -13,14 +13,13 @@ *******************************************************************************/ 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.assertExistsInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomContentsStream; import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomString; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import org.eclipse.core.internal.localstore.IHistoryStore; import org.eclipse.core.internal.resources.Workspace; @@ -62,7 +61,7 @@ public void testBug79398() throws Exception { IFileState[] sourceStates = file1.getHistory(createTestMonitor()); // just make sure our assumptions are valid - assertEquals("0.4", 10, sourceStates.length); + assertThat(sourceStates).hasSize(10); // copy the file - the history should be shared, but the destination // will conform to the policy @@ -71,10 +70,10 @@ public void testBug79398() throws Exception { assertExistsInWorkspace(file2); sourceStates = file1.getHistory(createTestMonitor()); // the source is unaffected so far - assertEquals("1.2", 10, sourceStates.length); + assertThat(sourceStates).hasSize(10); IFileState[] destinationStates = file2.getHistory(createTestMonitor()); // but the destination conforms to the policy - assertEquals("1.4", description.getMaxFileStates(), destinationStates.length); + assertThat(destinationStates).hasSize(description.getMaxFileStates()); // now cause the destination to have many more states for (int i = 0; i <= description.getMaxFileStates(); i++) { @@ -87,15 +86,12 @@ public void testBug79398() throws Exception { destinationStates = file2.getHistory(createTestMonitor()); // cleaning will remove any states the destination had in common // with the source since they don't fit into the policy - assertEquals("1.7", description.getMaxFileStates(), destinationStates.length); + assertThat(destinationStates).hasSize(description.getMaxFileStates()); sourceStates = file1.getHistory(createTestMonitor()); // the source should have any extra states removed as well, // but the ones left should still exist - assertEquals("1.7", description.getMaxFileStates(), sourceStates.length); - for (int i = 0; i < sourceStates.length; i++) { - assertTrue("1.8." + i, sourceStates[i].exists()); - } + assertThat(sourceStates).hasSize(description.getMaxFileStates()).allMatch(IFileState::exists); } } 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 0e78eb0d091..521f9e42926 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 @@ -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; @@ -86,21 +87,21 @@ public void testCopyFileHistory() throws CoreException { // modify the source file so it has some history sourceFile.setContents(createRandomContentsStream(), IResource.KEEP_HISTORY, createTestMonitor()); // check that the source file has the expected history - assertEquals("1.0", 1, sourceFile.getHistory(createTestMonitor()).length); + assertThat(sourceFile.getHistory(createTestMonitor())).hasSize(1); //copy the file sourceFile.copy(destinationFile.getFullPath(), IResource.NONE, createTestMonitor()); //make sure the history was copied - assertEquals("2.0", 1, sourceFile.getHistory(createTestMonitor()).length); - assertEquals("2.1", 1, destinationFile.getHistory(createTestMonitor()).length); + assertThat(sourceFile.getHistory(createTestMonitor())).hasSize(1); + assertThat(destinationFile.getHistory(createTestMonitor())).hasSize(1); //modify the destination to change its history destinationFile.setContents(createRandomContentsStream(), IResource.KEEP_HISTORY, createTestMonitor()); //make sure the history is correct - assertEquals("2.0", 1, sourceFile.getHistory(createTestMonitor()).length); - assertEquals("2.1", 2, destinationFile.getHistory(createTestMonitor()).length); + assertThat(sourceFile.getHistory(createTestMonitor())).hasSize(1); + assertThat(destinationFile.getHistory(createTestMonitor())).hasSize(2); } /** 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 c9ec6312ebe..0c910221a91 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 @@ -14,6 +14,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.regression; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.tests.harness.FileSystemHelper.canCreateSymLinks; import static org.eclipse.core.tests.harness.FileSystemHelper.createSymLink; import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInWorkspace; @@ -21,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.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; @@ -63,7 +63,7 @@ protected void symLinkAndRefresh(IContainer container, String linkName, IPath li container.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor()); IResource theLink = container.findMember(linkName); assertExistsInWorkspace(theLink); - assertTrue("2.2", theLink.getResourceAttributes().isSymbolicLink()); + assertTrue(theLink.getResourceAttributes().isSymbolicLink()); } /** @@ -96,8 +96,7 @@ public void testBug() throws Exception { symLinkAndRefresh(project, fileName, fileInTempDirPath); IFile[] files = root.findFilesForLocationURI(file.getLocationURI()); - assertEquals("7.0", 1, files.length); - assertEquals("7.1", file, files[0]); + assertThat(files).containsExactly(file); // Bug 198291: We do not track canonical symlink locations below project level // IFile[] files = root.findFilesForLocation(fileInTempDirPath); 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 1bb94eecc99..9f0abfc2ee2 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 org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.compareContent; import static org.eclipse.core.tests.resources.ResourceTestUtil.createInFileSystem; @@ -392,7 +393,7 @@ public void testDelete_Bug8754() throws Exception { IStatus status = exception.getStatus(); if (status.isMultiStatus()) { IStatus[] children = status.getChildren(); - assertEquals("1.1", 1, children.length); + assertThat(children).hasSize(1); status = children[0]; } assertEquals("1.2", IResourceStatus.OUT_OF_SYNC_LOCAL, status.getCode()); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IWorkspaceTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IWorkspaceTest.java index dd7835ddac1..06469b3e7ed 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IWorkspaceTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IWorkspaceTest.java @@ -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.createRandomContentsStream; @@ -59,7 +60,7 @@ public void testMultiMove_1GDKIHD() throws CoreException { getWorkspace().move(new IFile[] { file1 }, folder.getFullPath(), true, createTestMonitor()); file1.create(createRandomContentsStream(), true, createTestMonitor()); IFileState[] states = file1.getHistory(createTestMonitor()); - assertEquals("1.0", 3, states.length); + assertThat(states).hasSize(3); getWorkspace().delete(allResources, true, createTestMonitor()); project.clearHistory(createTestMonitor()); @@ -71,7 +72,7 @@ public void testMultiMove_1GDKIHD() throws CoreException { getWorkspace().move(new IFile[] { file1 }, folder.getFullPath(), false, createTestMonitor()); file1.create(createRandomContentsStream(), true, createTestMonitor()); states = file1.getHistory(createTestMonitor()); - assertEquals("2.0", 3, states.length); + assertThat(states).hasSize(3); getWorkspace().delete(allResources, true, createTestMonitor()); project.clearHistory(createTestMonitor()); } @@ -94,7 +95,7 @@ public void testMultiDelete_1GDGRIZ() throws CoreException { getWorkspace().delete(new IFile[] { file1 }, true, createTestMonitor()); file1.create(createRandomContentsStream(), true, createTestMonitor()); IFileState[] states = file1.getHistory(createTestMonitor()); - assertEquals("1.0", 3, states.length); + assertThat(states).hasSize(3); getWorkspace().delete(new IResource[] { file1 }, true, createTestMonitor()); project.clearHistory(createTestMonitor()); @@ -105,7 +106,7 @@ public void testMultiDelete_1GDGRIZ() throws CoreException { getWorkspace().delete(new IFile[] { file1 }, false, createTestMonitor()); file1.create(createRandomContentsStream(), true, createTestMonitor()); states = file1.getHistory(createTestMonitor()); - assertEquals("2.0", 3, states.length); + assertThat(states).hasSize(3); getWorkspace().delete(new IResource[] { file1 }, true, createTestMonitor()); project.clearHistory(createTestMonitor()); @@ -120,7 +121,7 @@ public void testMultiDelete_1GDGRIZ() throws CoreException { folder.create(true, true, createTestMonitor()); file2.create(createRandomContentsStream(), true, createTestMonitor()); states = file2.getHistory(createTestMonitor()); - assertEquals("3.0", 3, states.length); + assertThat(states).hasSize(3); getWorkspace().delete(new IResource[] { folder, file1, file2 }, true, createTestMonitor()); project.clearHistory(createTestMonitor()); @@ -133,7 +134,7 @@ public void testMultiDelete_1GDGRIZ() throws CoreException { folder.create(true, true, createTestMonitor()); file2.create(createRandomContentsStream(), true, createTestMonitor()); states = file2.getHistory(createTestMonitor()); - assertEquals("4.0", 3, states.length); + assertThat(states).hasSize(3); getWorkspace().delete(new IResource[] { folder, file1, file2 }, true, createTestMonitor()); project.clearHistory(createTestMonitor()); } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/TestMultipleBuildersOfSameType.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/TestMultipleBuildersOfSameType.java index 0b0e2e4b144..859e953fc84 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/TestMultipleBuildersOfSameType.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/TestMultipleBuildersOfSameType.java @@ -14,6 +14,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; @@ -85,10 +86,10 @@ public void test2() throws CoreException { getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, createTestMonitor()); //Only builder1 should have been built SortBuilder[] builders = SortBuilder.allInstances(); - assertEquals("1.0", 2, builders.length); - assertTrue("1.1", builders[0].wasBuilt()); - assertTrue("1.2", builders[0].wasIncrementalBuild()); - assertTrue("1.3", !builders[1].wasBuilt()); + assertThat(builders).hasSize(2).satisfiesExactly(first -> { + assertThat(first.wasBuilt()).isTrue(); + assertThat(first.wasIncrementalBuild()).isTrue(); + }, second -> assertThat(second.wasAutoBuild()).isFalse()); } public static Test suite() { diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/FindDeletedMembersTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/FindDeletedMembersTest.java index 1026cf8fdcb..effd49c19ce 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/FindDeletedMembersTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/FindDeletedMembersTest.java @@ -14,13 +14,12 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.session; +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.createRandomContentsStream; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; -import java.util.Arrays; -import java.util.List; import junit.framework.Test; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -71,8 +70,7 @@ public void test1() throws Exception { project.create(createTestMonitor()); project.open(createTestMonitor()); - IFile[] df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("0.1", 0, df.length); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); // test that a deleted file can be found // create and delete a file @@ -84,27 +82,17 @@ public void test1() throws Exception { public void test2() throws Exception { // the deleted file should show up as a deleted member of project - IFile[] df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("0.1", 1, df.length); - assertEquals("0.2", pfile, df[0]); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("0.3", 1, df.length); - assertEquals("0.4", pfile, df[0]); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("0.5", 0, df.length); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())) + .containsExactly(pfile); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())) + .containsExactly(pfile); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); // the deleted file should show up as a deleted member of workspace root - df = root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("0.5.1", 0, df.length); - - df = root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("0.5.2", 1, df.length); - assertEquals("0.5.3", pfile, df[0]); - - df = root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("0.5.4", 0, df.length); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())) + .containsExactly(pfile); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); // recreate the file pfile.create(createRandomContentsStream(), true, createTestMonitor()); @@ -114,32 +102,21 @@ public void test2() throws Exception { public void test3() throws Exception { // the deleted file should no longer show up as a deleted member of project - IFile[] df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("0.6", 0, df.length); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("0.7", 0, df.length); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("0.8", 0, df.length); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())).isEmpty(); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); // the deleted file should no longer show up as a deleted member of ws root - df = root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("0.8.1", 0, df.length); - - df = root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("0.8.2", 0, df.length); - - df = root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("0.8.3", 0, df.length); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())).isEmpty(); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); // scrub the project project.delete(true, createTestMonitor()); project.create(createTestMonitor()); project.open(createTestMonitor()); - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("0.9", 0, df.length); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); // test folder // create and delete a file in a folder @@ -152,28 +129,18 @@ public void test3() throws Exception { public void test4() throws Exception { // the deleted file should show up as a deleted member - IFile[] df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("1.1", 0, df.length); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("1.2", 1, df.length); - assertEquals("1.3", file, df[0]); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("1.4", 0, df.length); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())) + .containsExactly(file); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); // recreate the file file.create(createRandomContentsStream(), true, createTestMonitor()); // the recreated file should no longer show up as a deleted member - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("1.5", 0, df.length); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("1.6", 0, df.length); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("1.7", 0, df.length); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())).isEmpty(); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); // deleting the folder should bring it back into history folder.delete(true, true, createTestMonitor()); @@ -183,15 +150,10 @@ public void test4() throws Exception { public void test5() throws Exception { // the deleted file should show up as a deleted member of project - IFile[] df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("1.8", 0, df.length); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("1.9", 1, df.length); - assertEquals("1.10", file, df[0]); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("1.11", 0, df.length); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())) + .containsExactly(file); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); // create and delete a file where the folder was folderAsFile.create(createRandomContentsStream(), true, createTestMonitor()); @@ -199,29 +161,19 @@ public void test5() throws Exception { folder.create(true, true, createTestMonitor()); // the deleted file should show up as a deleted member of folder - df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("1.12", 1, df.length); - assertEquals("1.13", folderAsFile, df[0]); - - df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("1.14", 2, df.length); - List dfList = Arrays.asList(df); - assertTrue("1.15", dfList.contains(file)); - assertTrue("1.16", dfList.contains(folderAsFile)); - - df = folder.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("1.17", 2, df.length); - dfList = Arrays.asList(df); - assertTrue("1.18", dfList.contains(file)); - assertTrue("1.19", dfList.contains(folderAsFile)); + assertThat(folder.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())) + .containsExactly(folderAsFile); + assertThat(folder.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())) + .containsExactlyInAnyOrder(file, folderAsFile); + assertThat(folder.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())) + .containsExactlyInAnyOrder(file, folderAsFile); // scrub the project project.delete(true, createTestMonitor()); project.create(createTestMonitor()); project.open(createTestMonitor()); - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("1.50", 0, df.length); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); // test a bunch of deletes // create and delete a file in a folder @@ -237,52 +189,26 @@ public void test5() throws Exception { public void test6() throws Exception { // under root - IFile[] df = root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("3.1", 0, df.length); - - df = root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("3.2", 0, df.length); - - df = root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("3.3", 3, df.length); - List dfList = Arrays.asList(df); - assertTrue("3.3.1", dfList.contains(file1)); - assertTrue("3.3.2", dfList.contains(file2)); - assertTrue("3.3.3", dfList.contains(file3)); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())) + .containsExactlyInAnyOrder(file1, file2, file3); // under project - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("3.4", 0, df.length); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("3.5", 0, df.length); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("3.6", 3, df.length); - dfList = Arrays.asList(df); - assertTrue("3.6.1", dfList.contains(file1)); - assertTrue("3.6.2", dfList.contains(file2)); - assertTrue("3.6.3", dfList.contains(file3)); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())) + .containsExactlyInAnyOrder(file1, file2, file3); // under folder - df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("3.7", 0, df.length); - - df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("3.8", 2, df.length); - - df = folder.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("3.9", 3, df.length); + assertThat(folder.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); + assertThat(folder.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).hasSize(2); + assertThat(folder.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())).hasSize(3); // under folder2 - df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("3.10", 0, df.length); - - df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("3.11", 1, df.length); - - df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("3.12", 1, df.length); + assertThat(folder2.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); + assertThat(folder2.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).hasSize(1); + assertThat(folder2.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())).hasSize(1); project.delete(true, createTestMonitor()); @@ -292,44 +218,24 @@ public void test6() throws Exception { public void test7() throws Exception { // once the project is gone, so is all the history for that project // under root - IFile[] df = root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("4.1", 0, df.length); - - df = root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("4.2", 0, df.length); - - df = root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("4.3", 0, df.length); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())).isEmpty(); // under project - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("4.4", 0, df.length); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("4.5", 0, df.length); - - df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("4.6", 0, df.length); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())).isEmpty(); // under folder - df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("4.7", 0, df.length); - - df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("4.8", 0, df.length); - - df = folder.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("4.9", 0, df.length); + assertThat(folder.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); + assertThat(folder.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(folder.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())).isEmpty(); // under folder2 - df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor()); - assertEquals("4.10", 0, df.length); - - df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor()); - assertEquals("4.11", 0, df.length); - - df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor()); - assertEquals("4.12", 0, df.length); + assertThat(folder2.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, createTestMonitor())).isEmpty(); + assertThat(folder2.findDeletedMembersWithHistory(IResource.DEPTH_ONE, createTestMonitor())).isEmpty(); + assertThat(folder2.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, createTestMonitor())).isEmpty(); saveWorkspace(); } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBuilderDeltaSerialization.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBuilderDeltaSerialization.java index c90fe8a973d..8e6a3b9a327 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBuilderDeltaSerialization.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBuilderDeltaSerialization.java @@ -14,6 +14,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.session; +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; @@ -95,10 +96,10 @@ public void test2() throws CoreException { getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, createTestMonitor()); //Only builder1 should have been built SortBuilder[] builders = SortBuilder.allInstances(); - assertEquals("1.0", 2, builders.length); - assertTrue("1.1", builders[0].wasBuilt()); - assertTrue("1.2", builders[0].wasIncrementalBuild()); - assertTrue("1.3", !builders[1].wasBuilt()); + assertThat(builders).hasSize(2).satisfiesExactly(first -> { + assertThat(first.wasBuilt()).isTrue(); + assertThat(first.wasIncrementalBuild()).isTrue(); + }, second -> assertThat(second.wasAutoBuild()).isFalse()); } public static Test suite() { diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestCloseNoSave.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestCloseNoSave.java index 49cb2e31904..1e799c4d715 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestCloseNoSave.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestCloseNoSave.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.session; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS; import static org.eclipse.core.tests.resources.ResourceTestUtil.createRandomContentsStream; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; @@ -44,8 +45,7 @@ public void test2() throws CoreException { // projects should exist immediately due to snapshot - files may or // may not exist due to snapshot timing. All resources should exist after refresh. IResource[] members = workspace.getRoot().members(); - assertEquals("1.0", 1, members.length); - assertTrue("1.1", members[0].getType() == IResource.PROJECT); + assertThat(members).hasSize(1).allSatisfy(member -> assertThat(member.getType()).isEqualTo(IResource.PROJECT)); IProject project = (IProject) members[0]; assertTrue("1.2", project.exists()); IFolder folder = project.getFolder(FOLDER); @@ -56,7 +56,7 @@ public void test2() throws CoreException { project.open(null); } - assertEquals("2.0", 3, project.members().length); + assertThat(project.members()).hasSize(3); assertTrue("2.1", folder.exists()); assertTrue("2.2", file.exists()); } diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestMultiSnap.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestMultiSnap.java index c0b8521e807..d1423169478 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestMultiSnap.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestMultiSnap.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.session; +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.assertExistsInWorkspace; @@ -66,8 +67,7 @@ public void test2() throws CoreException { /* see if the workspace contains the resources created earlier*/ IResource[] children = getWorkspace().getRoot().members(); - assertEquals("1.0", 1, children.length); - assertEquals("1.1", children[0], project); + assertThat(children).containsExactly(project); assertTrue("1.2", project.exists()); assertTrue("1.3", project.isOpen()); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSave.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSave.java index ce15fa658bd..00fc7d1c487 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSave.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSave.java @@ -13,10 +13,12 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.session; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import junit.framework.Test; +import org.assertj.core.api.InstanceOfAssertFactories; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; @@ -40,13 +42,14 @@ public void test1() throws CoreException { public void test2() throws CoreException { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - assertTrue("1.0", root.exists()); + assertThat(root.exists()).isTrue(); IResource[] children = root.members(); - assertEquals("1.2", 1, children.length); - IProject project = (IProject) children[0]; - assertTrue("1.3", project.exists()); - assertTrue("1.4", project.isOpen()); - assertEquals("1.5", PROJECT, project.getName()); + assertThat(children).singleElement().asInstanceOf(InstanceOfAssertFactories.type(IProject.class)) + .satisfies(project -> { + assertThat(project.exists()).isTrue(); + assertThat(project.isOpen()).isTrue(); + assertThat(project.getName()).isEqualTo(PROJECT); + }); } public static Test suite() { diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSaveCreateProject.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSaveCreateProject.java index 6cad52b8eea..e05519b2f48 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSaveCreateProject.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSaveCreateProject.java @@ -13,10 +13,12 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.session; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS; import static org.eclipse.core.tests.resources.ResourceTestUtil.createTestMonitor; import junit.framework.Test; +import org.assertj.core.api.InstanceOfAssertFactories; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; @@ -39,12 +41,13 @@ public void test1() throws CoreException { public void test2() throws CoreException { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - assertTrue("1.0", root.exists()); + assertThat(root.exists()).isTrue(); IResource[] children = root.members(); - assertEquals("1.2", 1, children.length); - IProject project = (IProject) children[0]; - assertTrue("1.3", project.exists()); - assertEquals("1.4", PROJECT, project.getName()); + assertThat(children).singleElement().asInstanceOf(InstanceOfAssertFactories.type(IProject.class)) + .satisfies(project -> { + assertThat(project.exists()).isTrue(); + assertThat(project.getName()).isEqualTo(PROJECT); + }); } public static Test suite() { diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSaveSnap.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSaveSnap.java index e324b7e87e4..1e398b781c2 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSaveSnap.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSaveSnap.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.session; +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.assertExistsInWorkspace; @@ -71,8 +72,7 @@ public void test2() throws CoreException { /* see if the workspace contains the resources created earlier*/ IResource[] children = getWorkspace().getRoot().members(); - assertEquals("1.0", 1, children.length); - assertEquals("1.1", children[0], project); + assertThat(children).containsExactly(project); assertTrue("1.2", project.exists()); assertTrue("1.3", project.isOpen()); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSnapSaveSnap.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSnapSaveSnap.java index e48d71917fb..18dde3755a4 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSnapSaveSnap.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSnapSaveSnap.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.session; +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.assertExistsInWorkspace; @@ -67,8 +68,7 @@ public void test2() throws CoreException { /* see if the workspace contains the resources created earlier*/ IResource[] children = getWorkspace().getRoot().members(); - assertEquals("1.0", 1, children.length); - assertEquals("1.1", children[0], project); + assertThat(children).containsExactly(project); assertTrue("1.2", project.exists()); assertTrue("1.3", project.isOpen()); diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot3Test.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot3Test.java index 7257f8c9f92..01a4a67cec5 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot3Test.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot3Test.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.usecase; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInFileSystem; import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInWorkspace; @@ -57,7 +58,7 @@ public void testVerifyPreviousSession() throws CoreException { assertTrue("3.0", project.exists()); assertTrue("3.1", project.isOpen()); - assertEquals("4.0", 4, project.members().length); + assertThat(project.members()).hasSize(4); assertNotNull("4.1", project.findMember(IProjectDescription.DESCRIPTION_FILE_NAME)); // verify existence of children diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot4Test.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot4Test.java index 9f36feac7df..61752081683 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot4Test.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot4Test.java @@ -14,6 +14,7 @@ *******************************************************************************/ package org.eclipse.core.tests.resources.usecase; +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; @@ -114,7 +115,7 @@ public void testVerifyPreviousSession() throws CoreException { assertTrue("3.0", project.exists()); assertTrue("3.1", project.isOpen()); - assertEquals("4.0", 4, project.members().length); + assertThat(project.members()).hasSize(4); assertNotNull("4.1", project.findMember(IProjectDescription.DESCRIPTION_FILE_NAME)); // verify existence of children