Skip to content

Commit

Permalink
Remove ResourceTest#assert*(String, ...) methods eclipse-platform#903
Browse files Browse the repository at this point in the history
This change removes all assert*() methods from ResourceTest that accept
a string and replaces all calls to use the according methods that do not
accept a string. All callers only pass order numbers of assertions
within the test methods to this assertion utility, which are unnecessary
as failing tests deliver stack traces from which the failing statement
is obvious.

Contributes to
eclipse-platform#903
  • Loading branch information
HeikoKlare committed Dec 4, 2023
1 parent 709702c commit 326506c
Show file tree
Hide file tree
Showing 33 changed files with 383 additions and 455 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ public void testAnotherProject() throws CoreException {
// create some children
IResource[] resources = buildResources(project, defineHierarchy(PROJECT_1));
ensureExistsInWorkspace(resources, true);
assertExistsInFileSystem("3.1", resources);
assertExistsInWorkspace("3.2", resources);
assertExistsInFileSystem(resources);
assertExistsInWorkspace(resources);

project.close(null);
project.open(null);
assertExistsInFileSystem("4.1", resources);
assertExistsInWorkspace("4.2", resources);
assertExistsInFileSystem(resources);
assertExistsInWorkspace(resources);

getWorkspace().save(true, null);
}
Expand Down Expand Up @@ -202,13 +202,13 @@ public void testCreateMyProject() throws CoreException {
// create some children
IResource[] resources = buildResources(project, defineHierarchy(PROJECT_1));
ensureExistsInWorkspace(resources, true);
assertExistsInFileSystem("3.1", resources);
assertExistsInWorkspace("3.2", resources);
assertExistsInFileSystem(resources);
assertExistsInWorkspace(resources);

project.close(null);
project.open(null);
assertExistsInFileSystem("4.1", resources);
assertExistsInWorkspace("4.2", resources);
assertExistsInFileSystem(resources);
assertExistsInWorkspace(resources);
}

/**
Expand All @@ -224,8 +224,8 @@ public void testCreateProject2() throws CoreException {
// create some children
IResource[] resources = buildResources(project, defineHierarchy(PROJECT_2));
ensureExistsInWorkspace(resources, true);
assertExistsInFileSystem("3.1", resources);
assertExistsInWorkspace("3.2", resources);
assertExistsInFileSystem(resources);
assertExistsInWorkspace(resources);

// add a builder to this project
IProjectDescription description = project.getDescription();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ public void testVerifyProject2() throws CoreException {

// verify its children
IResource[] resources = buildResources(project, defineHierarchy(PROJECT_2));
assertExistsInFileSystem("1.0", resources);
assertDoesNotExistInWorkspace("1.1", resources);
assertExistsInFileSystem(resources);
assertDoesNotExistInWorkspace(resources);

project.open(null);
assertTrue("2.1", project.exists());
assertTrue("2.2", project.isOpen());
assertExistsInFileSystem("2.3", resources);
assertExistsInWorkspace("2.4", resources);
assertExistsInFileSystem(resources);
assertExistsInWorkspace(resources);

// verify builder -- cause an incremental build
touch(project);
Expand All @@ -135,8 +135,8 @@ public void testVerifyRestoredWorkspace() throws CoreException {

// verify children still exist
IResource[] resources = buildResources(project, defineHierarchy(PROJECT_1));
assertExistsInFileSystem("1.0", resources);
assertExistsInWorkspace("1.1", resources);
assertExistsInFileSystem(resources);
assertExistsInWorkspace(resources);

// add a file to test save participant delta
IFile file = project.getFile("addedFile");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,17 +533,17 @@ public void testCopyFolder() throws CoreException {
IFolder destFolder1 = fLinkOverlap1.getFolder(source.getName());
IFolder destFolder2 = fLinkOverlap2.getFolder(source.getName());
IResource[] allDest = new IResource[] {destFolder1, destFolder2};
assertDoesNotExistInWorkspace("1.0", allDest);
assertDoesNotExistInWorkspace(allDest);

//copy to dest 1
source.copy(destFolder1.getFullPath(), IResource.NONE, getMonitor());
assertExistsInWorkspace("1.2", allDest);
assertExistsInWorkspace(allDest);

destFolder2.delete(IResource.NONE, getMonitor());

//copy to dest 2
source.copy(destFolder2.getFullPath(), IResource.NONE, getMonitor());
assertExistsInWorkspace("1.5", allDest);
assertExistsInWorkspace(allDest);

destFolder1.delete(IResource.NONE, getMonitor());
}
Expand Down Expand Up @@ -786,9 +786,10 @@ public void testDeleteProjectContents() throws CoreException {
//delete the overlapping project - it should delete the children of the linked folder
//but leave the actual links intact in the resource tree
pOverlap.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor());
assertDoesNotExistInWorkspace("1.1", new IResource[] {pOverlap, fOverlap, lOverlap, lChildOverlap, lChildLinked});
assertDoesNotExistInFileSystem("1.2", new IResource[] {pOverlap, fOverlap, lOverlap, lChildOverlap, lChildLinked, lLinked, fLinked});
assertExistsInWorkspace("1.3", new IResource[] {pLinked, fLinked, lLinked});
assertDoesNotExistInWorkspace(new IResource[] { pOverlap, fOverlap, lOverlap, lChildOverlap, lChildLinked });
assertDoesNotExistInFileSystem(
new IResource[] { pOverlap, fOverlap, lOverlap, lChildOverlap, lChildLinked, lLinked, fLinked });
assertExistsInWorkspace(new IResource[] { pLinked, fLinked, lLinked });
}

@Test
Expand Down Expand Up @@ -834,43 +835,43 @@ public void testMoveFile() throws CoreException {
IFile destination = pNoOverlap.getFile("MoveDestination");
//file in linked folder
lChildLinked.move(destination.getFullPath(), IResource.NONE, getMonitor());
assertDoesNotExistInWorkspace("1.1", lChildLinked);
assertDoesNotExistInWorkspace("1.2", lChildOverlap);
assertExistsInWorkspace("1.3", destination);
assertDoesNotExistInWorkspace(lChildLinked);
assertDoesNotExistInWorkspace(lChildOverlap);
assertExistsInWorkspace(destination);
assertOverlap("1.4", lChildLinked, lChildOverlap);
assertTrue("1.5", lChildLinked.isSynchronized(IResource.DEPTH_INFINITE));
assertTrue("1.6", destination.isSynchronized(IResource.DEPTH_INFINITE));

destination.move(lChildLinked.getFullPath(), IResource.NONE, getMonitor());
assertExistsInWorkspace("2.1", lChildLinked);
assertExistsInWorkspace("2.2", lChildOverlap);
assertDoesNotExistInWorkspace("2.3", destination);
assertExistsInWorkspace(lChildLinked);
assertExistsInWorkspace(lChildOverlap);
assertDoesNotExistInWorkspace(destination);
assertOverlap("2.4", lChildLinked, lChildOverlap);
//duplicate file
lOverlap.move(destination.getFullPath(), IResource.NONE, getMonitor());
assertDoesNotExistInWorkspace("3.1", lOverlap);
assertExistsInWorkspace("3.2", lLinked);
assertDoesNotExistInFileSystem("3.25", lLinked);
assertExistsInWorkspace("3.3", destination);
assertDoesNotExistInWorkspace(lOverlap);
assertExistsInWorkspace(lLinked);
assertDoesNotExistInFileSystem(lLinked);
assertExistsInWorkspace(destination);
assertEquals("3.4", lLinked.getLocation(), lOverlap.getLocation());
assertTrue("3.4.1", lLinked.isSynchronized(IResource.DEPTH_INFINITE));

destination.move(lOverlap.getFullPath(), IResource.NONE, getMonitor());
assertExistsInWorkspace("3.5", lLinked);
assertExistsInWorkspace("3.6", lOverlap);
assertDoesNotExistInWorkspace("3.7", destination);
assertExistsInWorkspace(lLinked);
assertExistsInWorkspace(lOverlap);
assertDoesNotExistInWorkspace(destination);
assertOverlap("3.8", lLinked, lOverlap);
//file in duplicate folder
lChildOverlap.move(destination.getFullPath(), IResource.NONE, getMonitor());
assertDoesNotExistInWorkspace("3.1", lChildLinked);
assertDoesNotExistInWorkspace("3.2", lChildOverlap);
assertExistsInWorkspace("3.3", destination);
assertDoesNotExistInWorkspace(lChildLinked);
assertDoesNotExistInWorkspace(lChildOverlap);
assertExistsInWorkspace(destination);
assertOverlap("3.4", lChildLinked, lChildOverlap);

destination.move(lChildOverlap.getFullPath(), IResource.NONE, getMonitor());
assertExistsInWorkspace("3.5", lChildLinked);
assertExistsInWorkspace("3.6", lChildOverlap);
assertDoesNotExistInWorkspace("3.7", destination);
assertExistsInWorkspace(lChildLinked);
assertExistsInWorkspace(lChildOverlap);
assertDoesNotExistInWorkspace(destination);
assertOverlap("3.8", lChildLinked, lChildOverlap);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ public void testMoveFileAcrossVolumes() throws CoreException {

// assert file was moved
IFile newFile = destination.getFile(fileName);
assertDoesNotExistInWorkspace("4.1", file);
assertDoesNotExistInFileSystem("4.2", file);
assertExistsInWorkspace("4.3", newFile);
assertExistsInFileSystem("4.4", newFile);
assertDoesNotExistInWorkspace(file);
assertDoesNotExistInFileSystem(file);
assertExistsInWorkspace(newFile);
assertExistsInFileSystem(newFile);

// assert properties still exist (server, local and session)
for (int j = 0; j < numberOfProperties; j++) {
Expand Down Expand Up @@ -193,10 +193,10 @@ public void testMoveFolderAcrossVolumes() throws CoreException {

// assert folder was renamed
IFolder newFolder = destination.getFolder(folderName);
assertDoesNotExistInWorkspace("4.1", folder);
assertDoesNotExistInFileSystem("4.2", folder);
assertExistsInWorkspace("4.3", newFolder);
assertExistsInFileSystem("4.4", newFolder);
assertDoesNotExistInWorkspace(folder);
assertDoesNotExistInFileSystem(folder);
assertExistsInWorkspace(newFolder);
assertExistsInFileSystem(newFolder);

// assert properties still exist (server, local and session)
for (int j = 0; j < numberOfProperties; j++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,8 @@ public void testBug207510() throws CoreException, InterruptedException, BackingS
verifier.waitForEvent(10000);
IFile regularPrefs = getResourcesPreferenceFile(project1, false);
IFile derivedPrefs = getResourcesPreferenceFile(project1, true);
assertExistsInWorkspace("0.2", regularPrefs);
assertDoesNotExistInWorkspace("0.3", derivedPrefs);
assertExistsInWorkspace(regularPrefs);
assertDoesNotExistInWorkspace(derivedPrefs);

//1 - setting preference on project
verifier.reset();
Expand All @@ -534,8 +534,8 @@ public void testBug207510() throws CoreException, InterruptedException, BackingS
setDerivedEncodingStoredSeparately(project1, true);
assertTrue("1.1", verifier.waitForEvent(10000));
assertTrue("1.2 " + verifier.getMessage(), verifier.isDeltaValid());
assertExistsInWorkspace("1.3", regularPrefs);
assertDoesNotExistInWorkspace("1.4", derivedPrefs);
assertExistsInWorkspace(regularPrefs);
assertDoesNotExistInWorkspace(derivedPrefs);
assertTrue("1.5", isDerivedEncodingStoredSeparately(project1));

//2 - changing charset for file
Expand All @@ -545,17 +545,17 @@ public void testBug207510() throws CoreException, InterruptedException, BackingS
a.setCharset("UTF-8", getMonitor());
assertTrue("2.1", verifier.waitForEvent(10000));
assertTrue("2.2 " + verifier.getMessage(), verifier.isDeltaValid());
assertExistsInWorkspace("2.3", regularPrefs);
assertDoesNotExistInWorkspace("2.4", derivedPrefs);
assertExistsInWorkspace(regularPrefs);
assertDoesNotExistInWorkspace(derivedPrefs);

//3 - setting derived == 'true' for file
// TODO update the test when bug 345271 is fixed
a.setDerived(true, getMonitor());
//wait for all resource deltas
// Thread.sleep(500);
waitForCharsetManagerJob();
assertExistsInWorkspace("3.1", regularPrefs);
assertExistsInWorkspace("3.2", derivedPrefs);
assertExistsInWorkspace(regularPrefs);
assertExistsInWorkspace(derivedPrefs);
assertTrue("3.3", derivedPrefs.isDerived());

//4 - setting derived == 'false' for file
Expand All @@ -564,8 +564,8 @@ public void testBug207510() throws CoreException, InterruptedException, BackingS
//wait for all resource deltas
// Thread.sleep(500);
waitForCharsetManagerJob();
assertExistsInWorkspace("4.1", regularPrefs);
assertDoesNotExistInWorkspace("4.2", derivedPrefs);
assertExistsInWorkspace(regularPrefs);
assertDoesNotExistInWorkspace(derivedPrefs);

//5 - moving file to derived folder
IFile source = project1.getFolder("a1").getFile("a.txt");
Expand All @@ -578,10 +578,10 @@ public void testBug207510() throws CoreException, InterruptedException, BackingS
waitForCharsetManagerJob();
assertTrue("5.1", backgroundVerifier.waitForAllDeltas(10000, 15000));
backgroundVerifier.assertExpectedDeltasWereReceived("5.2");
assertExistsInWorkspace("5.3", regularPrefs);
assertExistsInWorkspace("5.4", derivedPrefs);
assertDoesNotExistInWorkspace("5.5", source);
assertExistsInWorkspace("5.6", destination);
assertExistsInWorkspace(regularPrefs);
assertExistsInWorkspace(derivedPrefs);
assertDoesNotExistInWorkspace(source);
assertExistsInWorkspace(destination);
assertTrue("5.7", derivedPrefs.isDerived());
assertCharsetIs("5.8", "UTF-8", new IResource[] { a }, true);

Expand All @@ -595,8 +595,8 @@ public void testBug207510() throws CoreException, InterruptedException, BackingS
assertTrue("6.1.2", backgroundVerifier.waitForFirstDelta(10000));
assertTrue("6.2.1 " + verifier.getMessage(), verifier.isDeltaValid());
backgroundVerifier.assertExpectedDeltasWereReceived("6.2.2");
assertExistsInWorkspace("6.3", regularPrefs);
assertDoesNotExistInWorkspace("6.4", derivedPrefs);
assertExistsInWorkspace(regularPrefs);
assertDoesNotExistInWorkspace(derivedPrefs);

//7 - setting preference on project with derived files
verifier.reset();
Expand All @@ -608,8 +608,8 @@ public void testBug207510() throws CoreException, InterruptedException, BackingS
assertTrue("7.1.2", backgroundVerifier.waitForFirstDelta(10000));
assertTrue("7.2.1 " + verifier.getMessage(), verifier.isDeltaValid());
backgroundVerifier.assertExpectedDeltasWereReceived("7.2.2");
assertExistsInWorkspace("7.3", regularPrefs);
assertExistsInWorkspace("7.4", derivedPrefs);
assertExistsInWorkspace(regularPrefs);
assertExistsInWorkspace(derivedPrefs);
assertTrue("7.5", isDerivedEncodingStoredSeparately(project1));
assertTrue("7.6", derivedPrefs.isDerived());

Expand Down Expand Up @@ -846,7 +846,7 @@ public void testClosingAndReopeningProject() throws CoreException {
// now reopen the project and ensure the settings were not forgotten
IProject projectB = workspace.getRoot().getProject(project.getName());
projectB.open(null);
assertExistsInWorkspace("0.9", getResourcesPreferenceFile(projectB, false));
assertExistsInWorkspace(getResourcesPreferenceFile(projectB, false));
assertEquals("1.0", "FOO", projectB.getDefaultCharset());
assertEquals("3.0", "FRED", projectB.getFile("file1.txt").getCharset());
assertEquals("2.0", "BAR", projectB.getFolder("folder").getDefaultCharset());
Expand Down Expand Up @@ -1255,19 +1255,19 @@ public void testFileCreation() throws CoreException {
IFile file1 = project.getFile("file1.txt");
IFile file2 = folder.getFile("file2.txt");
ensureExistsInWorkspace(new IResource[] {file1, file2}, true);
assertExistsInWorkspace("1.0", getResourcesPreferenceFile(project, false));
assertExistsInWorkspace(getResourcesPreferenceFile(project, false));
project.setDefaultCharset("FOO", getMonitor());
assertExistsInWorkspace("2.0", getResourcesPreferenceFile(project, false));
assertExistsInWorkspace(getResourcesPreferenceFile(project, false));
project.setDefaultCharset(null, getMonitor());
assertDoesNotExistInWorkspace("3.0", getResourcesPreferenceFile(project, false));
assertDoesNotExistInWorkspace(getResourcesPreferenceFile(project, false));
file1.setCharset("FRED", getMonitor());
assertExistsInWorkspace("4.0", getResourcesPreferenceFile(project, false));
assertExistsInWorkspace(getResourcesPreferenceFile(project, false));
folder.setDefaultCharset("BAR", getMonitor());
assertExistsInWorkspace("5.0", getResourcesPreferenceFile(project, false));
assertExistsInWorkspace(getResourcesPreferenceFile(project, false));
file1.setCharset(null, getMonitor());
assertExistsInWorkspace("6.0", getResourcesPreferenceFile(project, false));
assertExistsInWorkspace(getResourcesPreferenceFile(project, false));
folder.setDefaultCharset(null, getMonitor());
assertDoesNotExistInWorkspace("7.0", getResourcesPreferenceFile(project, false));
assertDoesNotExistInWorkspace(getResourcesPreferenceFile(project, false));
} finally {
clearAllEncodings(project);
}
Expand Down Expand Up @@ -1370,15 +1370,15 @@ public void testNonExistingResource() throws CoreException {
ensureExistsInWorkspace(project, true);
project.setDefaultCharset("FOO", getMonitor());
IFile file = project.getFile("file.xml");
assertDoesNotExistInWorkspace("2.0", file);
assertDoesNotExistInWorkspace(file);
assertEquals("2.2", "FOO", file.getCharset());
e = assertThrows(CoreException.class, () -> file.setCharset("BAR", getMonitor()));
assertEquals("file should not exist yet", IResourceStatus.RESOURCE_NOT_FOUND, e.getStatus().getCode());
ensureExistsInWorkspace(file, true);
file.setCharset("BAR", getMonitor());
assertEquals("2.8", "BAR", file.getCharset());
file.delete(IResource.NONE, null);
assertDoesNotExistInWorkspace("2.10", file);
assertDoesNotExistInWorkspace(file);
assertEquals("2.11", "FOO", file.getCharset());
} finally {
clearAllEncodings(project);
Expand Down
Loading

0 comments on commit 326506c

Please sign in to comment.