Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move getWorkspace() method from ResourceTest to utility class #903 #906

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
import org.eclipse.core.tests.resources.saveparticipant3.SaveParticipant3Plugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInFileSystem;
import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.ensureExistsInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;

/**
* This class needs to be used with SaveManager2Test. Basically this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

import junit.framework.Test;
import junit.framework.TestSuite;
import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.assertDoesNotExistInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInFileSystem;

/**
* @see SaveManager1Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import junit.framework.Test;
import junit.framework.TestSuite;

import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;

import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.*;
import org.eclipse.core.tests.internal.builders.DeltaVerifierBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*******************************************************************************/
package org.eclipse.core.tests.resources.saveparticipant;

import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;

import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.tests.resources.WorkspaceSessionTest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*******************************************************************************/
package org.eclipse.core.tests.filesystem;

import static org.eclipse.core.tests.resources.ResourceTestUtil.createFile;
import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;
import static org.junit.Assert.assertThrows;

import java.io.File;
Expand Down Expand Up @@ -156,7 +158,7 @@ public void testCopyAcrossVolumes() throws Throwable {
destination = tempDest.getChild(subfolderName);
deleteOnTearDown(destination);
String anotherContent = "nothing..................gnihton";
createFile(destination, anotherContent);
createOrOverwriteFile(destination, anotherContent);
assertTrue("5.1", !destination.fetchInfo().isDirectory());
final IFileStore immutableDestination = destination;
assertThrows(CoreException.class, () -> target.copy(immutableDestination, EFS.NONE, null));
Expand Down Expand Up @@ -195,7 +197,7 @@ public void testCopyDirectoryParentMissing() throws Throwable {
IFileStore parent = getTempStore();
IFileStore child = parent.getChild("child");
IFileStore existing = getTempStore();
createFile(existing, getRandomString());
createOrOverwriteFile(existing, getRandomString());
// try to copy when parent of destination does not exist
assertThrows(CoreException.class, () -> existing.copy(child, EFS.NONE, getMonitor()));
// destination should not exist
Expand All @@ -212,7 +214,7 @@ public void testCaseInsensitive() throws Throwable {
String content = "this is just a simple content \n to a simple file \n to test a 'simple' copy";
IFileStore fileWithSmallName = temp.getChild("filename");
fileWithSmallName.delete(EFS.NONE, null);
createFile(fileWithSmallName, content);
createOrOverwriteFile(fileWithSmallName, content);
System.out.println(fileWithSmallName.fetchInfo().getName());
assertTrue("1.3", fileWithSmallName.fetchInfo().exists());
assertTrue("1.4", compareContent(getContents(content), fileWithSmallName.openInputStream(EFS.NONE, null)));
Expand Down Expand Up @@ -243,7 +245,7 @@ public void testCopyFile() throws Throwable {
String content = "this is just a simple content \n to a simple file \n to test a 'simple' copy";
IFileStore target = temp.getChild("target");
target.delete(EFS.NONE, null);
createFile(target, content);
createOrOverwriteFile(target, content);
assertTrue("1.3", target.fetchInfo().exists());
assertTrue("1.4", compareContent(getContents(content), target.openInputStream(EFS.NONE, null)));

Expand Down Expand Up @@ -276,7 +278,7 @@ public void testCopyFile() throws Throwable {
sb.append("asdjhasldhaslkfjhasldkfjhasdlkfjhasdlfkjhasdflkjhsdaf");
}
IFileStore bigFile = temp.getChild("bigFile");
createFile(bigFile, sb.toString());
createOrOverwriteFile(bigFile, sb.toString());
assertTrue("7.1", bigFile.fetchInfo().exists());
assertTrue("7.2", compareContent(getContents(sb.toString()), bigFile.openInputStream(EFS.NONE, null)));
IFileStore destination = temp.getChild("copy of bigFile");
Expand Down Expand Up @@ -309,7 +311,7 @@ public void testCopyFileAcrossVolumes() throws Throwable {

IFileStore target = tempSrc.getChild(subfolderName);
target.delete(EFS.NONE, null);
createFile(target, content);
createOrOverwriteFile(target, content);
deleteOnTearDown(target);
assertTrue("1.3", target.fetchInfo().exists());
assertTrue("1.4", compareContent(getContents(content), target.openInputStream(EFS.NONE, null)));
Expand All @@ -333,7 +335,7 @@ public void testCopyFileAcrossVolumes() throws Throwable {
destination = tempDest.getChild(subfolderName);
deleteOnTearDown(destination);
String anotherContent = "nothing..................gnihton";
createFile(destination, anotherContent);
createOrOverwriteFile(destination, anotherContent);
assertTrue("5.1", !destination.fetchInfo().isDirectory());
target.copy(destination, IResource.DEPTH_INFINITE, null);
assertTrue("5.2", compareContent(getContents(content), destination.openInputStream(EFS.NONE, null)));
Expand All @@ -347,7 +349,7 @@ public void testCopyFileAcrossVolumes() throws Throwable {
assertThrows(CoreException.class, () -> target.copy(immutableDestination, EFS.NONE, null));
/* test if the input stream inside the copy method was closed */
target.delete(EFS.NONE, null);
createFile(target, content);
createOrOverwriteFile(target, content);
assertTrue("6.3", destination.fetchInfo().isDirectory());
destination.delete(EFS.NONE, null);
}
Expand Down Expand Up @@ -401,7 +403,7 @@ public void testMove() throws Throwable {
// create target file
IFileStore target = tempC.getChild("target");
String content = "just a content.....tnetnoc a tsuj";
createFile(target, content);
createOrOverwriteFile(target, content);
assertTrue("1.3", target.fetchInfo().exists());
// create target tree
IFileStore tree = tempC.getChild("tree");
Expand All @@ -419,7 +421,7 @@ public void testMove() throws Throwable {

/* rename file (but destination is already a file) */
String anotherContent = "another content";
createFile(destination, anotherContent);
createOrOverwriteFile(destination, anotherContent);
final IFileStore immutableFileDestination = destination;
assertThrows(CoreException.class, () -> target.move(immutableFileDestination, EFS.NONE, null));
assertTrue("3.2", !target.fetchInfo().isDirectory());
Expand Down Expand Up @@ -463,7 +465,7 @@ public void testMoveAcrossVolumes() throws Throwable {
IFileStore target = tempSrc.getChild(subfolderName);
deleteOnTearDown(target);
String content = "just a content.....tnetnoc a tsuj";
createFile(target, content);
createOrOverwriteFile(target, content);
assertTrue("1.3", target.fetchInfo().exists());
// create target tree
IFileStore tree = tempSrc.getChild("tree");
Expand Down Expand Up @@ -496,7 +498,7 @@ public void testMoveDirectoryParentMissing() throws Throwable {
IFileStore parent = getTempStore();
IFileStore child = parent.getChild("child");
IFileStore existing = getTempStore();
createFile(existing, getRandomString());
createOrOverwriteFile(existing, getRandomString());
// try to move when parent of destination does not exist
assertThrows(CoreException.class, () -> existing.move(child, EFS.NONE, getMonitor()));
// destination should not exist
Expand Down Expand Up @@ -571,7 +573,7 @@ private void testAttribute(int attribute) throws CoreException {
IFileStore targetFolder = createDir(root.toString(), true);
deleteOnTearDown(targetFolder);
IFileStore targetFile = targetFolder.getChild("targetFile");
createFileInFileSystem(targetFile);
createFile(targetFile);

// file
boolean init = targetFile.fetchInfo().getAttribute(attribute);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
*******************************************************************************/
package org.eclipse.core.tests.internal.alias;

import static org.eclipse.core.tests.resources.ResourceTestUtil.assertDoesNotExistInFileSystem;
import static org.eclipse.core.tests.resources.ResourceTestUtil.assertDoesNotExistInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.createFile;
import static org.eclipse.core.tests.resources.ResourceTestUtil.ensureExistsInFileSystem;
import static org.eclipse.core.tests.resources.ResourceTestUtil.ensureExistsInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThrows;

Expand Down Expand Up @@ -430,7 +437,7 @@ public void testBug258987() throws CoreException {
assertTrue("3.0", dirStore.fetchInfo().isDirectory());

IFileStore childStore = dirStore.getChild("child");
createFileInFileSystem(childStore);
createFile(childStore);
assertTrue("4.0", childStore.fetchInfo().exists());

// Create and open the first project. Project links to the directory.
Expand Down Expand Up @@ -701,7 +708,7 @@ public void testDeepLink() throws CoreException {

// delete the project that contains the links
IFile fileInLinkedProject = pLinked.getFile("fileInLinkedProject.txt");
createFileInFileSystem(((Resource) fileInLinkedProject).getStore(), getRandomContents());
createFile(((Resource) fileInLinkedProject).getStore(), getRandomContents());
// failure expected here because it is out of sync
assertThrows(CoreException.class, () -> getWorkspace().getRoot().delete(IResource.NONE, getMonitor()));
waitForRefresh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*******************************************************************************/
package org.eclipse.core.tests.internal.alias;

import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.core.tests.internal.builders;

import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;
import static org.junit.Assert.assertThrows;

import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
******************************************************************************/
package org.eclipse.core.tests.internal.builders;

import static org.eclipse.core.tests.resources.ResourceTestUtil.ensureExistsInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;

import java.util.Map;
import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.ICommand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*******************************************************************************/
package org.eclipse.core.tests.internal.builders;

import static org.eclipse.core.tests.resources.ResourceTestUtil.ensureExistsInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;

import org.eclipse.core.internal.events.BuildContext;
import org.eclipse.core.internal.resources.BuildConfiguration;
import org.eclipse.core.resources.IBuildConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*******************************************************************************/
package org.eclipse.core.tests.internal.builders;

import static org.eclipse.core.tests.resources.ResourceTestUtil.create;
import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;

import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*******************************************************************************/
package org.eclipse.core.tests.internal.builders;

import static org.eclipse.core.tests.resources.ResourceTestUtil.ensureExistsInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;

import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*******************************************************************************/
package org.eclipse.core.tests.internal.builders;

import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;

import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_SNOW;
import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.NATURE_WATER;
import static org.eclipse.core.tests.resources.ResourceTestUtil.ensureExistsInWorkspace;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
*******************************************************************************/
package org.eclipse.core.tests.internal.builders;

import static org.eclipse.core.tests.resources.ResourceTestUtil.ensureExistsInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.transferStreams;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertThrows;

Expand Down Expand Up @@ -628,7 +632,7 @@ public void testCopyProject() throws CoreException {
// Create some resources
proj1.create(getMonitor());
proj1.open(getMonitor());
ensureDoesNotExistInWorkspace(proj2);
removeFromWorkspace(proj2);

// Create and set a build spec for project one
IProjectDescription desc = proj1.getDescription();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
******************************************************************************/
package org.eclipse.core.tests.internal.builders;

import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;

import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*******************************************************************************/
package org.eclipse.core.tests.internal.builders;

import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;

import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
*******************************************************************************/
package org.eclipse.core.tests.internal.builders;

import static org.eclipse.core.tests.resources.ResourceTestUtil.ensureExistsInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package org.eclipse.core.tests.internal.builders;

import static org.eclipse.core.tests.resources.ResourceTestPluginConstants.PI_RESOURCES_TESTS;
import static org.eclipse.core.tests.resources.ResourceTestUtil.ensureExistsInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;
import static org.eclipse.core.tests.resources.TestUtil.waitForCondition;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*******************************************************************************/
package org.eclipse.core.tests.internal.builders;

import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;

import java.util.List;
import org.eclipse.core.internal.resources.Workspace;
import org.eclipse.core.resources.ICommand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
*******************************************************************************/
package org.eclipse.core.tests.internal.builders;

import static org.eclipse.core.tests.resources.ResourceTestUtil.create;
import static org.eclipse.core.tests.resources.ResourceTestUtil.ensureExistsInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.is;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*******************************************************************************/
package org.eclipse.core.tests.internal.events;

import static org.eclipse.core.tests.resources.ResourceTestUtil.ensureExistsInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void testDeleteBlob() throws CoreException {

/* delete existing blob */
IFileStore target = root.getChild("target");
createFile(target, "bla bla bla");
createOrOverwriteFile(target, "bla bla bla");
uuid = store.addBlob(target, true);
assertTrue(store.fileFor(uuid).fetchInfo().exists());
store.deleteBlob(uuid);
Expand All @@ -90,7 +90,7 @@ public void testGetBlob() throws CoreException {
IFileStore target = root.getChild("target");
UniversalUniqueIdentifier uuid = null;
String content = "nothing important........tnatropmi gnihton";
createFile(target, content);
createOrOverwriteFile(target, content);
uuid = store.addBlob(target, true);
InputStream input = store.getBlob(uuid);
assertTrue(compareContent(getContents(content), input));
Expand All @@ -105,7 +105,7 @@ public void testSetBlob() throws CoreException {
IFileStore target = root.getChild("target");
UniversalUniqueIdentifier uuid = null;
String content = "nothing important........tnatropmi gnihton";
createFile(target, content);
createOrOverwriteFile(target, content);
uuid = store.addBlob(target, true);
InputStream input = store.getBlob(uuid);
assertTrue(compareContent(getContents(content), input));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*******************************************************************************/
package org.eclipse.core.tests.internal.localstore;

import static org.eclipse.core.tests.resources.ResourceTestUtil.ensureExistsInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.getWorkspace;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
Expand Down
Loading
Loading