Skip to content

Commit

Permalink
Revert "Remove useless assert/fail methods from CoreTest"
Browse files Browse the repository at this point in the history
Test for fix for eclipse-platform#265
This reverts commit 41e20d4.
  • Loading branch information
akurtakov committed Nov 20, 2022
1 parent c5af991 commit 63f9349
Show file tree
Hide file tree
Showing 22 changed files with 605 additions and 407 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@ public void assertNotSame(String message, byte[] expected, byte[] actual) {
* Returns the byte[] contents of the given file.
*/
private byte[] getBytes(File cachedFile) {
try (FileInputStream in = new FileInputStream(cachedFile);
ByteArrayOutputStream out = new ByteArrayOutputStream();) {
in.transferTo(out);
FileInputStream in = null;
ByteArrayOutputStream out = null;
try {
in = new FileInputStream(cachedFile);
out = new ByteArrayOutputStream();
transferData(in, out);
in.close();
out.close();
return out.toByteArray();
} catch (IOException e) {
fail("Exception in FileCacheTest.getBytes", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
*******************************************************************************/
package org.eclipse.core.tests.internal.builders;

import static org.junit.Assert.assertArrayEquals;

import org.eclipse.core.internal.events.BuildContext;
import org.eclipse.core.internal.resources.BuildConfiguration;
import org.eclipse.core.resources.*;
Expand Down Expand Up @@ -135,22 +133,22 @@ public void testBuildContext() {
IBuildContext context;

context = new BuildContext(p0v0, new IBuildConfiguration[] {p0v0, p1v0}, buildOrder);
assertArrayEquals("1.0", new IBuildConfiguration[] {}, context.getAllReferencedBuildConfigs());
assertArrayEquals("1.1", new IBuildConfiguration[] { p0v1, p1v0 }, context.getAllReferencingBuildConfigs());
assertArrayEquals("1.2", new IBuildConfiguration[] { p0v0, p1v0 }, context.getRequestedConfigs());
assertEquals("1.0", new IBuildConfiguration[] {}, context.getAllReferencedBuildConfigs());
assertEquals("1.1", new IBuildConfiguration[] {p0v1, p1v0}, context.getAllReferencingBuildConfigs());
assertEquals("1.2", new IBuildConfiguration[] {p0v0, p1v0}, context.getRequestedConfigs());

context = new BuildContext(p0v1, buildOrder, buildOrder);
assertArrayEquals("2.0", new IBuildConfiguration[] { p0v0 }, context.getAllReferencedBuildConfigs());
assertArrayEquals("2.1", new IBuildConfiguration[] { p1v0 }, context.getAllReferencingBuildConfigs());
assertEquals("2.0", new IBuildConfiguration[] {p0v0}, context.getAllReferencedBuildConfigs());
assertEquals("2.1", new IBuildConfiguration[] {p1v0}, context.getAllReferencingBuildConfigs());

context = new BuildContext(p1v0, buildOrder, buildOrder);
assertArrayEquals("3.0", new IBuildConfiguration[] { p0v0, p0v1 }, context.getAllReferencedBuildConfigs());
assertArrayEquals("3.1", new IBuildConfiguration[] {}, context.getAllReferencingBuildConfigs());
assertEquals("3.0", new IBuildConfiguration[] {p0v0, p0v1}, context.getAllReferencedBuildConfigs());
assertEquals("3.1", new IBuildConfiguration[] {}, context.getAllReferencingBuildConfigs());

// And it works with no build context too
context = new BuildContext(p1v0);
assertArrayEquals("4.0", new IBuildConfiguration[] {}, context.getAllReferencedBuildConfigs());
assertArrayEquals("4.1", new IBuildConfiguration[] {}, context.getAllReferencingBuildConfigs());
assertEquals("4.0", new IBuildConfiguration[] {}, context.getAllReferencedBuildConfigs());
assertEquals("4.1", new IBuildConfiguration[] {}, context.getAllReferencingBuildConfigs());
}

public void testSingleProjectBuild() throws CoreException {
Expand Down Expand Up @@ -188,22 +186,16 @@ public void testWorkspaceBuildProject() throws CoreException {
assertTrue("1.0", ContextBuilder.checkValid());

IBuildContext context = ContextBuilder.getContext(project0.getActiveBuildConfig());
assertArrayEquals("2.0",
new IBuildConfiguration[] { project2.getActiveBuildConfig(), project1.getActiveBuildConfig() },
context.getAllReferencedBuildConfigs());
assertEquals("2.0", new IBuildConfiguration[] {project2.getActiveBuildConfig(), project1.getActiveBuildConfig()}, context.getAllReferencedBuildConfigs());
assertEquals("2.1", 0, context.getAllReferencingBuildConfigs().length);

context = ContextBuilder.getBuilder(project1.getActiveBuildConfig()).contextForLastBuild;
assertArrayEquals("3.0", new IBuildConfiguration[] { project2.getActiveBuildConfig() },
context.getAllReferencedBuildConfigs());
assertArrayEquals("3.1", new IBuildConfiguration[] { project0.getActiveBuildConfig() },
context.getAllReferencingBuildConfigs());
assertEquals("3.0", new IBuildConfiguration[] {project2.getActiveBuildConfig()}, context.getAllReferencedBuildConfigs());
assertEquals("3.1", new IBuildConfiguration[] {project0.getActiveBuildConfig()}, context.getAllReferencingBuildConfigs());

context = ContextBuilder.getBuilder(project2.getActiveBuildConfig()).contextForLastBuild;
assertEquals("4.0", 0, context.getAllReferencedBuildConfigs().length);
assertArrayEquals("4.1",
new IBuildConfiguration[] { project1.getActiveBuildConfig(), project0.getActiveBuildConfig() },
context.getAllReferencingBuildConfigs());
assertEquals("4.1", new IBuildConfiguration[] {project1.getActiveBuildConfig(), project0.getActiveBuildConfig()}, context.getAllReferencingBuildConfigs());

// Build just project0
ContextBuilder.clearStats();
Expand All @@ -227,22 +219,16 @@ public void testWorkspaceBuildProjects() throws CoreException {
assertTrue("1.0", ContextBuilder.checkValid());

IBuildContext context = ContextBuilder.getContext(project0.getActiveBuildConfig());
assertArrayEquals("2.0",
new IBuildConfiguration[] { project2.getActiveBuildConfig(), project1.getActiveBuildConfig() },
context.getAllReferencedBuildConfigs());
assertEquals("2.0", new IBuildConfiguration[] {project2.getActiveBuildConfig(), project1.getActiveBuildConfig()}, context.getAllReferencedBuildConfigs());
assertEquals("2.1", 0, context.getAllReferencingBuildConfigs().length);

context = ContextBuilder.getBuilder(project1.getActiveBuildConfig()).contextForLastBuild;
assertArrayEquals("3.0", new IBuildConfiguration[] { project2.getActiveBuildConfig() },
context.getAllReferencedBuildConfigs());
assertArrayEquals("3.1", new IBuildConfiguration[] { project0.getActiveBuildConfig() },
context.getAllReferencingBuildConfigs());
assertEquals("3.0", new IBuildConfiguration[] {project2.getActiveBuildConfig()}, context.getAllReferencedBuildConfigs());
assertEquals("3.1", new IBuildConfiguration[] {project0.getActiveBuildConfig()}, context.getAllReferencingBuildConfigs());

context = ContextBuilder.getBuilder(project2.getActiveBuildConfig()).contextForLastBuild;
assertEquals("4.0", 0, context.getAllReferencedBuildConfigs().length);
assertArrayEquals("4.1",
new IBuildConfiguration[] { project1.getActiveBuildConfig(), project0.getActiveBuildConfig() },
context.getAllReferencingBuildConfigs());
assertEquals("4.1", new IBuildConfiguration[] {project1.getActiveBuildConfig(), project0.getActiveBuildConfig()}, context.getAllReferencingBuildConfigs());
}

/**
Expand All @@ -259,22 +245,16 @@ public void testReferenceActiveVariant() throws CoreException {
assertTrue("1.0", ContextBuilder.checkValid());

IBuildContext context = ContextBuilder.getContext(project0.getActiveBuildConfig());
assertArrayEquals("2.0",
new IBuildConfiguration[] { project2.getActiveBuildConfig(), project1.getActiveBuildConfig() },
context.getAllReferencedBuildConfigs());
assertEquals("2.0", new IBuildConfiguration[] {project2.getActiveBuildConfig(), project1.getActiveBuildConfig()}, context.getAllReferencedBuildConfigs());
assertEquals("2.1", 0, context.getAllReferencingBuildConfigs().length);

context = ContextBuilder.getBuilder(project1.getActiveBuildConfig()).contextForLastBuild;
assertArrayEquals("3.0", new IBuildConfiguration[] { project2.getActiveBuildConfig() },
context.getAllReferencedBuildConfigs());
assertArrayEquals("3.1", new IBuildConfiguration[] { project0.getActiveBuildConfig() },
context.getAllReferencingBuildConfigs());
assertEquals("3.0", new IBuildConfiguration[] {project2.getActiveBuildConfig()}, context.getAllReferencedBuildConfigs());
assertEquals("3.1", new IBuildConfiguration[] {project0.getActiveBuildConfig()}, context.getAllReferencingBuildConfigs());

context = ContextBuilder.getBuilder(project2.getActiveBuildConfig()).contextForLastBuild;
assertEquals("4.0", 0, context.getAllReferencedBuildConfigs().length);
assertArrayEquals("4.1",
new IBuildConfiguration[] { project1.getActiveBuildConfig(), project0.getActiveBuildConfig() },
context.getAllReferencingBuildConfigs());
assertEquals("4.1", new IBuildConfiguration[] {project1.getActiveBuildConfig(), project0.getActiveBuildConfig()}, context.getAllReferencingBuildConfigs());
}

/**
Expand All @@ -292,16 +272,13 @@ public void testReferenceVariantTwice() throws CoreException {
assertTrue("1.0", ContextBuilder.checkValid());

IBuildContext context = ContextBuilder.getContext(project0.getActiveBuildConfig());
assertArrayEquals("2.0", new IBuildConfiguration[] { project1.getActiveBuildConfig() },
context.getAllReferencedBuildConfigs());
assertEquals("2.0", new IBuildConfiguration[] {project1.getActiveBuildConfig()}, context.getAllReferencedBuildConfigs());
assertEquals("2.1", 0, context.getAllReferencingBuildConfigs().length);
assertArrayEquals("2.2", new IBuildConfiguration[] { project0.getActiveBuildConfig() },
context.getRequestedConfigs());
assertEquals("2.2", new IBuildConfiguration[] {project0.getActiveBuildConfig()}, context.getRequestedConfigs());

context = ContextBuilder.getBuilder(project1.getActiveBuildConfig()).contextForLastBuild;
assertEquals("3.0", 0, context.getAllReferencedBuildConfigs().length);
assertArrayEquals("3.1", new IBuildConfiguration[] { project0.getActiveBuildConfig() },
context.getAllReferencingBuildConfigs());
assertEquals("3.1", new IBuildConfiguration[] {project0.getActiveBuildConfig()}, context.getAllReferencingBuildConfigs());

// Change the active configuration of project1, and test that two configurations are built
ContextBuilder.clearStats();
Expand All @@ -311,10 +288,8 @@ public void testReferenceVariantTwice() throws CoreException {
assertTrue("4.0", ContextBuilder.checkValid());

context = ContextBuilder.getContext(project0.getActiveBuildConfig());
assertArrayEquals("4.1", new IBuildConfiguration[] { project1PreviousActive, project1NewActive },
context.getAllReferencedBuildConfigs());
assertEquals("4.1", new IBuildConfiguration[] {project1PreviousActive, project1NewActive}, context.getAllReferencedBuildConfigs());
assertEquals("4.2", 0, context.getAllReferencingBuildConfigs().length);
assertArrayEquals("4.3", new IBuildConfiguration[] { project0.getActiveBuildConfig() },
context.getRequestedConfigs());
assertEquals("4.3", new IBuildConfiguration[] {project0.getActiveBuildConfig()}, context.getRequestedConfigs());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*******************************************************************************/
package org.eclipse.core.tests.internal.localstore;

import java.io.IOException;
import java.io.InputStream;
import org.eclipse.core.filesystem.*;
import org.eclipse.core.internal.localstore.BlobStore;
Expand Down Expand Up @@ -90,7 +89,7 @@ private IFileStore createStore() {
return root;
}

public void testDeleteBlob() throws CoreException, IOException {
public void testDeleteBlob() {
/* initialize common objects */
IFileStore root = createStore();
BlobStore store = new BlobStore(root, 64);
Expand All @@ -103,14 +102,18 @@ public void testDeleteBlob() throws CoreException, IOException {

/* delete existing blob */
IFileStore target = root.getChild("target");
createFile(target, "bla bla bla");
uuid = store.addBlob(target, true);
try {
createFile(target, "bla bla bla");
uuid = store.addBlob(target, true);
} catch (CoreException e) {
fail("4.1", e);
}
assertTrue("4.2", store.fileFor(uuid).fetchInfo().exists());
store.deleteBlob(uuid);
assertTrue("4.3", !store.fileFor(uuid).fetchInfo().exists());
}

public void testGetBlob() throws CoreException, IOException {
public void testGetBlob() {
/* initialize common objects */
IFileStore root = createStore();
BlobStore store = new BlobStore(root, 64);
Expand All @@ -121,20 +124,31 @@ public void testGetBlob() throws CoreException, IOException {
store.getBlob(null);
} catch (RuntimeException e) {
ok = true;
} catch (CoreException e) {
fail("2.0", e);
}
assertTrue("2.1", ok);

/* get existing blob */
IFileStore target = root.getChild("target");
UniversalUniqueIdentifier uuid = null;
String content = "nothing important........tnatropmi gnihton";
createFile(target, content);
uuid = store.addBlob(target, true);
InputStream input = store.getBlob(uuid);
try {
createFile(target, content);
uuid = store.addBlob(target, true);
} catch (CoreException e) {
fail("3.1", e);
}
InputStream input = null;
try {
input = store.getBlob(uuid);
} catch (CoreException e) {
fail("3.4", e);
}
assertTrue("4.1", compareContent(getContents(content), input));
}

public void testSetBlob() throws CoreException, IOException {
public void testSetBlob() {
/* initialize common objects */
IFileStore root = createStore();
BlobStore store = new BlobStore(root, 64);
Expand All @@ -143,9 +157,18 @@ public void testSetBlob() throws CoreException, IOException {
IFileStore target = root.getChild("target");
UniversalUniqueIdentifier uuid = null;
String content = "nothing important........tnatropmi gnihton";
createFile(target, content);
uuid = store.addBlob(target, true);
InputStream input = store.getBlob(uuid);
try {
createFile(target, content);
uuid = store.addBlob(target, true);
} catch (CoreException e) {
fail("2.1", e);
}
InputStream input = null;
try {
input = store.getBlob(uuid);
} catch (CoreException e) {
fail("2.4", e);
}
assertTrue("2.5", compareContent(getContents(content), input));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ public int countChildren(IFolder root) throws CoreException {
* Create a file with random content. If a resource exists in the same path,
* the resource is deleted.
*/
protected void createFile(IFileStore target, String content) throws CoreException, IOException {
protected void createFile(IFileStore target, String content) throws CoreException {
target.delete(EFS.NONE, null);
try (InputStream input = new ByteArrayInputStream(content.getBytes())) {
input.transferTo(target.openOutputStream(EFS.NONE, null));
}
InputStream input = new ByteArrayInputStream(content.getBytes());
transferData(input, target.openOutputStream(EFS.NONE, null));
IFileInfo info = target.fetchInfo();
assertTrue(info.exists() && !info.isDirectory());
}
Expand All @@ -87,24 +86,23 @@ protected void createFile(IFileStore target, String content) throws CoreExceptio
*/
protected void createIOFile(java.io.File target, String content) throws IOException {
target.delete();
try (InputStream input = new ByteArrayInputStream(content.getBytes())) {
input.transferTo(new FileOutputStream(target));
}
InputStream input = new ByteArrayInputStream(content.getBytes());
transferData(input, new FileOutputStream(target));
assertTrue(target.exists() && !target.isDirectory());
}

protected void createNode(IFileStore node) throws CoreException, IOException {
protected void createNode(IFileStore node) throws CoreException {
char type = node.getName().charAt(0);
if (type == 'd') {
node.mkdir(EFS.NONE, null);
} else {
try (InputStream input = getRandomContents(); OutputStream output = node.openOutputStream(EFS.NONE, null)) {
input.transferTo(output);
}
InputStream input = getRandomContents();
OutputStream output = node.openOutputStream(EFS.NONE, null);
transferData(input, output);
}
}

protected void createTree(IFileStore[] tree) throws CoreException, IOException {
protected void createTree(IFileStore[] tree) throws CoreException {
for (IFileStore element : tree) {
createNode(element);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*******************************************************************************/
package org.eclipse.core.tests.internal.resources;

import static org.junit.Assert.assertArrayEquals;

import java.io.*;
import java.net.URI;
import java.net.URL;
Expand Down Expand Up @@ -272,10 +270,14 @@ private String getLongDescriptionURI() {
* @throws CoreException
* @throws IOException
*/
private ProjectDescription readDescription(IFileStore store) throws CoreException, IOException {
try (InputStream input = store.openInputStream(EFS.NONE, getMonitor())) {
private ProjectDescription readDescription(IFileStore store) throws CoreException {
InputStream input = null;
try {
input = store.openInputStream(EFS.NONE, getMonitor());
InputSource in = new InputSource(input);
return new ProjectDescriptionReader(getWorkspace()).read(in);
} finally {
assertClose(input);
}
}

Expand Down Expand Up @@ -352,9 +354,9 @@ public void testInvalidProjectDescription2() throws Throwable {
assertNull("2.1", projDesc.getName());
assertEquals("2.2", 0, projDesc.getComment().length());
assertNull("2.3", projDesc.getLocationURI());
assertArrayEquals("2.4", new IProject[0], projDesc.getReferencedProjects());
assertArrayEquals("2.5", new String[0], projDesc.getNatureIds());
assertArrayEquals("2.6", new ICommand[0], projDesc.getBuildSpec());
assertEquals("2.4", new IProject[0], projDesc.getReferencedProjects());
assertEquals("2.5", new String[0], projDesc.getNatureIds());
assertEquals("2.6", new ICommand[0], projDesc.getBuildSpec());
assertNull("2.7", projDesc.getLinks());
}

Expand All @@ -371,9 +373,9 @@ public void testInvalidProjectDescription3() throws Throwable {
assertTrue("3.1", projDesc.getName().equals("abc"));
assertEquals("3.2", 0, projDesc.getComment().length());
assertNull("3.3", projDesc.getLocationURI());
assertArrayEquals("3.4", new IProject[0], projDesc.getReferencedProjects());
assertArrayEquals("3.5", new String[0], projDesc.getNatureIds());
assertArrayEquals("3.6", new ICommand[0], projDesc.getBuildSpec());
assertEquals("3.4", new IProject[0], projDesc.getReferencedProjects());
assertEquals("3.5", new String[0], projDesc.getNatureIds());
assertEquals("3.6", new ICommand[0], projDesc.getBuildSpec());
assertNull("3.7", projDesc.getLinks());
}

Expand All @@ -389,9 +391,9 @@ public void testInvalidProjectDescription4() throws Throwable {
assertTrue("3.1", projDesc.getName().equals("abc"));
assertEquals("3.2", 0, projDesc.getComment().length());
assertNull("3.3", projDesc.getLocationURI());
assertArrayEquals("3.4", new IProject[0], projDesc.getReferencedProjects());
assertArrayEquals("3.5", new String[0], projDesc.getNatureIds());
assertArrayEquals("3.6", new ICommand[0], projDesc.getBuildSpec());
assertEquals("3.4", new IProject[0], projDesc.getReferencedProjects());
assertEquals("3.5", new String[0], projDesc.getNatureIds());
assertEquals("3.6", new ICommand[0], projDesc.getBuildSpec());
LinkDescription link = projDesc.getLinks().values().iterator().next();
assertEquals("3.7", new Path("newLink"), link.getProjectRelativePath());
assertEquals("3.8", PATH_STRING, URIUtil.toPath(link.getLocationURI()).toString());
Expand Down Expand Up @@ -654,8 +656,12 @@ protected URI uriFromPortableString(String pathString) {
* @throws CoreException
*/
private void writeDescription(IFileStore store, ProjectDescription description) throws IOException, CoreException {
try (OutputStream output = store.openOutputStream(EFS.NONE, getMonitor());) {
OutputStream output = null;
try {
output = store.openOutputStream(EFS.NONE, getMonitor());
new ModelObjectWriter().write(description, output, System.lineSeparator());
} finally {
assertClose(output);
}

}
Expand Down
Loading

0 comments on commit 63f9349

Please sign in to comment.