Skip to content

Commit

Permalink
Remove clear() method from ResourceTest
Browse files Browse the repository at this point in the history
The ResourceTest#clear() method is unnecessary. It only deletes the
given IFileStore and is only called at few places. All other tests using
IFileStores directly delete the store and get a proper error message at
that specific place in case the deletion fails.

This change removes the clear() method and inlines the file stores
deletions.
  • Loading branch information
HeikoKlare committed Nov 3, 2023
1 parent bda43e5 commit b434b24
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,16 @@ 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) {
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));

IResource[] children1 = null;
IResource[] children2 = null;
try {
children1 = getSortedChildren(resource1);
children2 = getSortedChildren(resource2);
} catch (CoreException e) {
fail(errMsg, e);
}
children1 = getSortedChildren(resource1);
children2 = getSortedChildren(resource2);
assertEquals(errMsg + "(child count)", children1.length, children2.length);
for (int i = 0; i < children2.length; i++) {
assertOverlap(message, children1[i], children2[i]);
Expand Down Expand Up @@ -186,16 +182,11 @@ protected void setUp() throws Exception {

linkOverlapLocation = getRandomLocation();
linkOverlapLocation.toFile().mkdirs();
deleteOnTearDown(linkOverlapLocation);
fLinkOverlap1.createLink(linkOverlapLocation, IResource.NONE, null);
fLinkOverlap2.createLink(linkOverlapLocation, IResource.NONE, null);
}

@Override
protected void tearDown() throws Exception {
super.tearDown();
Workspace.clear(linkOverlapLocation.toFile());
}

/**
* This tests regression of bug 32785. In this bug, moving a linked folder,
* then copying a linked folder, resulted in the alias table having a stale entry
Expand All @@ -207,30 +198,27 @@ public void testBug32785() throws CoreException {
IFile child = link.getFile("Child.txt");
IPath location = getRandomLocation();
location.toFile().mkdirs();
try {
link.createLink(location, IResource.NONE, getMonitor());
ensureExistsInWorkspace(child, getRandomContents());
//move the link (rename)
IFolder movedLink = project.getFolder("MovedLink");
link.move(movedLink.getFullPath(), IResource.SHALLOW, getMonitor());
assertFalse("3.0", link.exists());
assertTrue("3.1", movedLink.exists());
assertEquals("3.2", location, movedLink.getLocation());
assertTrue("3.3", movedLink.isSynchronized(IResource.DEPTH_INFINITE));

//now copy the moved link
IFolder copiedLink = project.getFolder("CopiedLink");
movedLink.copy(copiedLink.getFullPath(), IResource.SHALLOW, getMonitor());
assertFalse("4.0", link.exists());
assertTrue("4.1", movedLink.exists());
assertTrue("4.2", copiedLink.exists());
assertEquals("4.3", location, movedLink.getLocation());
assertEquals("4.4", location, copiedLink.getLocation());
assertTrue("4.5", movedLink.isSynchronized(IResource.DEPTH_INFINITE));
assertTrue("4.6", copiedLink.isSynchronized(IResource.DEPTH_INFINITE));
} finally {
Workspace.clear(location.toFile());
}
deleteOnTearDown(location);
link.createLink(location, IResource.NONE, getMonitor());
ensureExistsInWorkspace(child, getRandomContents());
// move the link (rename)
IFolder movedLink = project.getFolder("MovedLink");
link.move(movedLink.getFullPath(), IResource.SHALLOW, getMonitor());
assertFalse("3.0", link.exists());
assertTrue("3.1", movedLink.exists());
assertEquals("3.2", location, movedLink.getLocation());
assertTrue("3.3", movedLink.isSynchronized(IResource.DEPTH_INFINITE));

// now copy the moved link
IFolder copiedLink = project.getFolder("CopiedLink");
movedLink.copy(copiedLink.getFullPath(), IResource.SHALLOW, getMonitor());
assertFalse("4.0", link.exists());
assertTrue("4.1", movedLink.exists());
assertTrue("4.2", copiedLink.exists());
assertEquals("4.3", location, movedLink.getLocation());
assertEquals("4.4", location, copiedLink.getLocation());
assertTrue("4.5", movedLink.isSynchronized(IResource.DEPTH_INFINITE));
assertTrue("4.6", copiedLink.isSynchronized(IResource.DEPTH_INFINITE));
}

/**
Expand Down Expand Up @@ -263,7 +251,7 @@ public void testBug156082() throws CoreException {
* used in the locations map of AliasManager.
*/
@Test
public void testBug198571() {
public void testBug198571() throws CoreException {
Assume.assumeTrue(OS.isWindows());

/* look for the adequate environment */
Expand All @@ -279,41 +267,29 @@ public void testBug198571() {
IPath location1 = IPath.fromOSString(devices[0] + location);
assertTrue("0.1", !location1.toFile().exists());
desc1.setLocation(location1);
deleteOnTearDown(location1);
IProjectDescription desc2 = getWorkspace().newProjectDescription(testProject2.getName());
IPath location2 = IPath.fromOSString(devices[1] + location);
assertTrue("0.2", !location2.toFile().exists());
desc2.setLocation(location2);
deleteOnTearDown(location2);

try {
try {
testProject1.create(desc1, getMonitor());
testProject1.open(getMonitor());
testProject2.create(desc2, getMonitor());
testProject2.open(getMonitor());
} catch (CoreException e) {
fail("1.0", e);
}
testProject1.create(desc1, getMonitor());
testProject1.open(getMonitor());
testProject2.create(desc2, getMonitor());
testProject2.open(getMonitor());

final AliasManager aliasManager = ((Workspace) getWorkspace()).getAliasManager();
//force AliasManager to restart (simulates a shutdown/startup)
aliasManager.startup(null);
final AliasManager aliasManager = ((Workspace) getWorkspace()).getAliasManager();
// force AliasManager to restart (simulates a shutdown/startup)
aliasManager.startup(null);

// new folder in one of the projects
IFolder folder = testProject2.getFolder("NewFolder");
ensureExistsInFileSystem(folder);
// new folder in one of the projects
IFolder folder = testProject2.getFolder("NewFolder");
ensureExistsInFileSystem(folder);

try {
testProject2.refreshLocal(IResource.DEPTH_INFINITE, null);
IResource[] resources = aliasManager.computeAliases(folder, ((Folder) folder).getStore());
assertNull(resources);
} catch (CoreException e) {
fail("2.0", e);
}
} finally {
//make sure we don't leave behind a mess on the test machine
clear(EFS.getLocalFileSystem().getStore(location1));
clear(EFS.getLocalFileSystem().getStore(location2));
}
testProject2.refreshLocal(IResource.DEPTH_INFINITE, null);
IResource[] resources = aliasManager.computeAliases(folder, ((Folder) folder).getStore());
assertNull(resources);
}

private void replaceProject(IProject project, URI newLocation) throws CoreException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.ByteArrayInputStream;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.internal.resources.Resource;
import org.eclipse.core.internal.resources.Workspace;
Expand Down Expand Up @@ -758,7 +759,7 @@ public void testProjectDeletionClosedDefaultInSync() throws CoreException {
assertTrue("3.14", fileStore.fetchInfo().exists());
assertTrue("3.15", otherFileStore.fetchInfo().exists());
// cleanup
clear(projectStore);
projectStore.delete(EFS.NONE, null);

/* ======================================================================
* Force = FALSE
Expand Down Expand Up @@ -790,7 +791,7 @@ public void testProjectDeletionClosedDefaultInSync() throws CoreException {
assertTrue("4.14", fileStore.fetchInfo().exists());
assertTrue("4.15", otherFileStore.fetchInfo().exists());
// cleanup
clear(projectStore);
projectStore.delete(EFS.NONE, null);

/* ======================================================================
* Force = TRUE
Expand Down Expand Up @@ -822,7 +823,7 @@ public void testProjectDeletionClosedDefaultInSync() throws CoreException {
assertTrue("5.14", fileStore.fetchInfo().exists());
assertTrue("5.15", otherFileStore.fetchInfo().exists());
// cleanup
clear(projectStore);
projectStore.delete(EFS.NONE, null);

/* ======================================================================
* Force = FALSE
Expand Down Expand Up @@ -854,7 +855,7 @@ public void testProjectDeletionClosedDefaultInSync() throws CoreException {
assertTrue("6.14", fileStore.fetchInfo().exists());
assertTrue("6.15", otherFileStore.fetchInfo().exists());
// cleanup
clear(projectStore);
projectStore.delete(EFS.NONE, null);
}

/**
Expand Down Expand Up @@ -964,7 +965,7 @@ public void testProjectDeletionClosedDefaultOutOfSync() throws CoreException {
assertTrue("3.16", fileStore.fetchInfo().exists());
assertTrue("3.17", otherFileStore.fetchInfo().exists());
// cleanup
clear(projectStore);
projectStore.delete(EFS.NONE, null);

/* ======================================================================
* Force = FALSE
Expand Down Expand Up @@ -997,7 +998,7 @@ public void testProjectDeletionClosedDefaultOutOfSync() throws CoreException {
assertTrue("4.16", fileStore.fetchInfo().exists());
assertTrue("4.17", otherFileStore.fetchInfo().exists());
// cleanup
clear(projectStore);
projectStore.delete(EFS.NONE, null);

/* ======================================================================
* Force = TRUE
Expand Down Expand Up @@ -1030,7 +1031,7 @@ public void testProjectDeletionClosedDefaultOutOfSync() throws CoreException {
assertTrue("5.16", fileStore.fetchInfo().exists());
assertTrue("5.17", otherFileStore.fetchInfo().exists());
// cleanup
clear(projectStore);
projectStore.delete(EFS.NONE, null);

/* ======================================================================
* Force = FALSE
Expand Down Expand Up @@ -1063,7 +1064,7 @@ public void testProjectDeletionClosedDefaultOutOfSync() throws CoreException {
assertTrue("6.16", fileStore.fetchInfo().exists());
assertTrue("6.17", otherFileStore.fetchInfo().exists());
// cleanup
clear(projectStore);
projectStore.delete(EFS.NONE, null);
}

/**
Expand Down Expand Up @@ -1102,7 +1103,7 @@ public void testProjectDeletionClosedUserDefinedInSync() throws CoreException {
// ensure the project directory and files no longer exist
assertFalse("1.8", projectStore.fetchInfo().exists());
assertFalse("1.9", fileStore.fetchInfo().exists());
clear(projectStore);
projectStore.delete(EFS.NONE, null);

/* ======================================================================
* Force = FALSE
Expand All @@ -1126,7 +1127,7 @@ public void testProjectDeletionClosedUserDefinedInSync() throws CoreException {
// ensure the project directory and files no longer exist
assertFalse("2.8", projectStore.fetchInfo().exists());
assertFalse("2.9", fileStore.fetchInfo().exists());
clear(projectStore);
projectStore.delete(EFS.NONE, null);

/* ======================================================================
* Force = TRUE
Expand All @@ -1150,7 +1151,7 @@ public void testProjectDeletionClosedUserDefinedInSync() throws CoreException {
assertTrue("3.8", projectStore.fetchInfo().exists());
assertTrue("3.9", fileStore.fetchInfo().exists());
// cleanup
clear(projectStore);
projectStore.delete(EFS.NONE, null);

/* ======================================================================
* Force = FALSE
Expand All @@ -1174,7 +1175,7 @@ public void testProjectDeletionClosedUserDefinedInSync() throws CoreException {
assertTrue("4.8", projectStore.fetchInfo().exists());
assertTrue("4.9", fileStore.fetchInfo().exists());
// cleanup
clear(projectStore);
projectStore.delete(EFS.NONE, null);

/* ======================================================================
* Force = TRUE
Expand All @@ -1198,7 +1199,7 @@ public void testProjectDeletionClosedUserDefinedInSync() throws CoreException {
assertTrue("5.8", projectStore.fetchInfo().exists());
assertTrue("5.9", fileStore.fetchInfo().exists());
// cleanup
clear(projectStore);
projectStore.delete(EFS.NONE, null);

/* ======================================================================
* Force = FALSE
Expand All @@ -1222,7 +1223,7 @@ public void testProjectDeletionClosedUserDefinedInSync() throws CoreException {
assertTrue("6.8", projectStore.fetchInfo().exists());
assertTrue("6.9", fileStore.fetchInfo().exists());
// cleanup
clear(projectStore);
projectStore.delete(EFS.NONE, null);
}

/**
Expand Down Expand Up @@ -1267,7 +1268,7 @@ public void testProjectDeletionClosedUserDefinedOutOfSync() throws CoreException
assertFalse("1.8", projectStore.fetchInfo().exists());
assertFalse("1.9", fileStore.fetchInfo().exists());
assertFalse("1.10", otherFileStore.fetchInfo().exists());
clear(projectStore);
projectStore.delete(EFS.NONE, null);

/* ======================================================================
* Force = FALSE
Expand Down Expand Up @@ -1296,7 +1297,7 @@ public void testProjectDeletionClosedUserDefinedOutOfSync() throws CoreException
assertFalse("2.8", projectStore.fetchInfo().exists());
assertFalse("2.9", fileStore.fetchInfo().exists());
assertFalse("2.10", otherFileStore.fetchInfo().exists());
clear(projectStore);
projectStore.delete(EFS.NONE, null);

/* ======================================================================
* Force = TRUE
Expand Down Expand Up @@ -1412,7 +1413,7 @@ public void testProjectDeletionClosedUserDefinedOutOfSync() throws CoreException
assertTrue("6.9", fileStore.fetchInfo().exists());
assertTrue("6.10", otherFileStore.fetchInfo().exists());
// cleanup
clear(projectStore);
projectStore.delete(EFS.NONE, null);
}

/**
Expand Down Expand Up @@ -1597,7 +1598,7 @@ public void testProjectDeletionOpenDefaultOutOfSync() throws CoreException {
assertTrue("3.5", projectStore.fetchInfo().exists());
assertTrue("3.6", fileStore.fetchInfo().exists());
// cleanup
clear(projectStore);
projectStore.delete(EFS.NONE, null);

/* ======================================================================
* Force = FALSE
Expand All @@ -1617,7 +1618,7 @@ public void testProjectDeletionOpenDefaultOutOfSync() throws CoreException {
assertTrue("4.5", projectStore.fetchInfo().exists());
assertTrue("4.6", fileStore.fetchInfo().exists());
// cleanup
clear(projectStore);
projectStore.delete(EFS.NONE, null);

/* ======================================================================
* Force = TRUE
Expand Down Expand Up @@ -1750,7 +1751,7 @@ public void testProjectDeletionOpenUserDefinedInSync() throws CoreException {
assertTrue("4.7", projectStore.fetchInfo().exists());
assertTrue("4.8", fileStore.fetchInfo().exists());
// cleanup
clear(projectStore);
projectStore.delete(EFS.NONE, null);

/* ======================================================================
* Force = TRUE
Expand Down Expand Up @@ -1832,7 +1833,7 @@ public void testProjectDeletionOpenUserDefinedOutOfSync() throws CoreException {
assertFalse("1.7", projectStore.fetchInfo().exists());
assertFalse("1.8", fileStore.fetchInfo().exists());
assertFalse("1.9", otherFileStore.fetchInfo().exists());
clear(projectStore);
projectStore.delete(EFS.NONE, null);

/* ======================================================================
* Force = FALSE
Expand All @@ -1858,7 +1859,7 @@ public void testProjectDeletionOpenUserDefinedOutOfSync() throws CoreException {
assertFalse("2.7", projectStore.fetchInfo().exists());
assertFalse("2.8", fileStore.fetchInfo().exists());
assertFalse("2.9", otherFileStore.fetchInfo().exists());
clear(projectStore);
projectStore.delete(EFS.NONE, null);

/* ======================================================================
* Force = TRUE
Expand All @@ -1884,7 +1885,7 @@ public void testProjectDeletionOpenUserDefinedOutOfSync() throws CoreException {
assertTrue("3.8", fileStore.fetchInfo().exists());
assertTrue("3.9", otherFileStore.fetchInfo().exists());
// cleanup
clear(projectStore);
projectStore.delete(EFS.NONE, null);

/* ======================================================================
* Force = FALSE
Expand Down
Loading

0 comments on commit b434b24

Please sign in to comment.