Skip to content
Merged
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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.waitForBuild;
import static org.eclipse.core.tests.resources.ResourceTestUtil.waitForEncodingRelatedJobs;
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 static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
Expand All @@ -41,28 +41,24 @@
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.runtime.CoreException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(WorkspaceResetExtension.class)
public class HiddenResourceTest {

@Rule
public TestName testName = new TestName();

@Rule
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();

@Test
public void testRefreshLocal() throws Exception {
public void testRefreshLocal(TestInfo testInfo) throws Exception {
IWorkspaceRoot root = getWorkspace().getRoot();
IProject project = root.getProject(createUniqueString());
IFolder folder = project.getFolder("folder");
IFile file = project.getFile("file.txt");
IFile subFile = folder.getFile("subfile.txt");
IResource[] resources = new IResource[] {project, folder, file, subFile};
createInWorkspace(resources);
waitForEncodingRelatedJobs(testName.getMethodName());
waitForEncodingRelatedJobs(testInfo.getDisplayName());

ResourceDeltaVerifier listener = new ResourceDeltaVerifier();
listener.addExpectedChange(subFile, IResourceDelta.CHANGED, IResourceDelta.CONTENT);
Expand All @@ -71,7 +67,7 @@ public void testRefreshLocal() throws Exception {
setHidden(folder, true, IResource.DEPTH_ZERO);
ensureOutOfSync(subFile);
project.refreshLocal(IResource.DEPTH_INFINITE, createTestMonitor());
assertTrue(listener.getMessage(), listener.isDeltaValid());
assertTrue(listener.isDeltaValid(), listener.getMessage());
} finally {
removeResourceChangeListener(listener);
}
Expand All @@ -91,24 +87,24 @@ public void testFindMember() throws CoreException {
createInWorkspace(resources);

// no hidden resources
assertEquals("1.0", project, root.findMember(project.getFullPath()));
assertEquals("1.1", folder, root.findMember(folder.getFullPath()));
assertEquals("1.2", file, root.findMember(file.getFullPath()));
assertEquals("1.3", subFile, root.findMember(subFile.getFullPath()));
assertEquals(project, root.findMember(project.getFullPath()));
assertEquals(folder, root.findMember(folder.getFullPath()));
assertEquals(file, root.findMember(file.getFullPath()));
assertEquals(subFile, root.findMember(subFile.getFullPath()));

// the folder is hidden
setHidden(folder, true, IResource.DEPTH_ZERO);
assertEquals("2.1", project, root.findMember(project.getFullPath()));
assertEquals("2.2", folder, root.findMember(folder.getFullPath()));
assertEquals("2.3", file, root.findMember(file.getFullPath()));
assertEquals("2.4", subFile, root.findMember(subFile.getFullPath()));
assertEquals(project, root.findMember(project.getFullPath()));
assertEquals(folder, root.findMember(folder.getFullPath()));
assertEquals(file, root.findMember(file.getFullPath()));
assertEquals(subFile, root.findMember(subFile.getFullPath()));

// all are hidden
setHidden(project, true, IResource.DEPTH_INFINITE);
assertEquals("3.1", project, root.findMember(project.getFullPath()));
assertEquals("3.2", folder, root.findMember(folder.getFullPath()));
assertEquals("3.3", file, root.findMember(file.getFullPath()));
assertEquals("3.4", subFile, root.findMember(subFile.getFullPath()));
assertEquals(project, root.findMember(project.getFullPath()));
assertEquals(folder, root.findMember(folder.getFullPath()));
assertEquals(file, root.findMember(file.getFullPath()));
assertEquals(subFile, root.findMember(subFile.getFullPath()));
}

/**
Expand Down Expand Up @@ -219,20 +215,20 @@ public void testAccept() throws CoreException {
visitor.addExpected(resources);
visitor.addExpected(description);
project.accept(visitor);
assertTrue(visitor.getMessage(), visitor.isValid());
assertTrue(visitor.isValid(), visitor.getMessage());

visitor.reset();
visitor.addExpected(resources);
visitor.addExpected(description);
project.accept(visitor, IResource.DEPTH_INFINITE, IResource.NONE);
assertTrue(visitor.getMessage(), visitor.isValid());
assertTrue(visitor.isValid(), visitor.getMessage());

visitor.reset();
visitor.addExpected(resources);
visitor.addExpected(description);
project.accept(visitor, IResource.DEPTH_INFINITE, IContainer.INCLUDE_HIDDEN);

assertTrue(visitor.getMessage(), visitor.isValid());
assertTrue(visitor.isValid(), visitor.getMessage());

// set the folder to be hidden. It and its children should
// be ignored by the visitor
Expand All @@ -244,7 +240,7 @@ public void testAccept() throws CoreException {
visitor.addExpected(settings);
visitor.addExpected(prefs);
project.accept(visitor);
assertTrue(visitor.getMessage(), visitor.isValid());
assertTrue(visitor.isValid(), visitor.getMessage());

visitor.reset();
visitor.addExpected(project);
Expand All @@ -253,27 +249,27 @@ public void testAccept() throws CoreException {
visitor.addExpected(settings);
visitor.addExpected(prefs);
project.accept(visitor, IResource.DEPTH_INFINITE, IResource.NONE);
assertTrue(visitor.getMessage(), visitor.isValid());
assertTrue(visitor.isValid(), visitor.getMessage());
// should see all resources if we include the flag
visitor.reset();
visitor.addExpected(resources);
visitor.addExpected(description);
project.accept(visitor, IResource.DEPTH_INFINITE, IContainer.INCLUDE_HIDDEN);
assertTrue(visitor.getMessage(), visitor.isValid());
assertTrue(visitor.isValid(), visitor.getMessage());
// should NOT visit the folder and its members if we call accept on it directly
visitor.reset();
folder.accept(visitor);
assertTrue(visitor.getMessage(), visitor.isValid());
assertTrue(visitor.isValid(), visitor.getMessage());

visitor.reset();
folder.accept(visitor, IResource.DEPTH_INFINITE, IResource.NONE);
assertTrue(visitor.getMessage(), visitor.isValid());
assertTrue(visitor.isValid(), visitor.getMessage());

visitor.reset();
visitor.addExpected(folder);
visitor.addExpected(subFile);
folder.accept(visitor, IResource.DEPTH_INFINITE, IContainer.INCLUDE_HIDDEN);
assertTrue(visitor.getMessage(), visitor.isValid());
assertTrue(visitor.isValid(), visitor.getMessage());
}

@Test
Expand Down Expand Up @@ -444,7 +440,7 @@ public void testDelete() throws CoreException {
}

@Test
public void testDeltas() throws CoreException {
public void testDeltas(TestInfo testInfo) throws CoreException {
IWorkspaceRoot root = getWorkspace().getRoot();
final IProject project = root.getProject(createUniqueString());
final IFolder folder = project.getFolder("folder");
Expand All @@ -463,10 +459,10 @@ public void testDeltas() throws CoreException {
addResourceChangeListener(listener);
getWorkspace().run(body, createTestMonitor());
waitForBuild();
waitForEncodingRelatedJobs(testName.getMethodName());
waitForEncodingRelatedJobs(testInfo.getDisplayName());
// FIXME sometimes fails with "Verifier has not yet been given a resource
// delta":
assertTrue(listener.getMessage(), listener.isDeltaValid());
assertTrue(listener.isDeltaValid(), listener.getMessage());
removeFromWorkspace(resources);
} finally {
removeResourceChangeListener(listener);
Expand All @@ -485,7 +481,7 @@ public void testDeltas() throws CoreException {
getWorkspace().run(body, createTestMonitor());
// FIXME sometimes fails with "Verifier has not yet been given a resource
// delta":
assertTrue(listener.getMessage(), listener.isDeltaValid());
assertTrue(listener.isDeltaValid(), listener.getMessage());
removeFromWorkspace(resources);
} finally {
removeResourceChangeListener(listener);
Expand All @@ -504,7 +500,7 @@ public void testDeltas() throws CoreException {
getWorkspace().run(body, createTestMonitor());
// FIXME sometimes fails with "Verifier has not yet been given a resource
// delta":
assertTrue("3.1." + listener.getMessage(), listener.isDeltaValid());
assertTrue(listener.isDeltaValid(), listener.getMessage());
removeFromWorkspace(resources);
} finally {
removeResourceChangeListener(listener);
Expand Down Expand Up @@ -579,7 +575,7 @@ public void testSetGet() throws CoreException {
// initial values should be false
for (IResource resource2 : resources) {
IResource resource = resource2;
assertTrue("1.0: " + resource.getFullPath(), !resource.isHidden());
assertFalse(resource.isHidden(), resource.getFullPath().toString());
}

// now set the values
Expand All @@ -594,10 +590,10 @@ public void testSetGet() throws CoreException {
case IResource.PROJECT :
case IResource.FOLDER :
case IResource.FILE :
assertTrue("3.0: " + resource.getFullPath(), resource.isHidden());
assertTrue(resource.isHidden(), resource.getFullPath().toString());
break;
case IResource.ROOT :
assertFalse("3.1: " + resource.getFullPath(), resource.isHidden());
assertFalse(resource.isHidden(), resource.getFullPath().toString());
break;
}
}
Expand All @@ -610,7 +606,7 @@ public void testSetGet() throws CoreException {
// values should be false again
for (IResource resource2 : resources) {
IResource resource = resource2;
assertFalse("5.0: " + resource.getFullPath(), resource.isHidden());
assertFalse(resource.isHidden(), resource.getFullPath().toString());
}
}

Expand Down Expand Up @@ -649,7 +645,7 @@ protected void assertHidden(IResource root, final boolean value, int depth)
if (resource.getType() == IResource.PROJECT || resource.getType() == IResource.FILE || resource.getType() == IResource.FOLDER) {
expected = value;
}
assertEquals(resource.getFullPath() + "", expected, resource.isHidden());
assertEquals(expected, resource.isHidden(), resource.getFullPath().toString());
return true;
};
root.accept(visitor, depth, IContainer.INCLUDE_HIDDEN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
import static org.eclipse.core.tests.resources.ResourceTestUtil.ensureOutOfSync;
import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromFileSystem;
import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromWorkspace;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -73,15 +73,14 @@
import org.eclipse.core.runtime.Platform.OS;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.tests.harness.FussyProgressMonitor;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(WorkspaceResetExtension.class)
public class IFileTest {

@Rule
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();

//name of files according to sync category
public static final String DOES_NOT_EXIST = "DoesNotExistFile";

Expand Down Expand Up @@ -311,7 +310,7 @@ public void refreshFiles() throws CoreException, IOException {
}
}

@Before
@BeforeEach
public void setUp() throws Exception {
generateInterestingFiles();
}
Expand Down Expand Up @@ -561,7 +560,7 @@ public void testWrite() throws CoreException {
AtomicInteger changeCount = new AtomicInteger();
ResourcesPlugin.getWorkspace().addResourceChangeListener(event -> changeCount.incrementAndGet());
derived.write(("updateOrCreate" + i).getBytes(), false, setDerived, keepHistory, monitor);
assertEquals("not atomic", 1, changeCount.get());
assertEquals(1, changeCount.get(), "not atomic");
monitor.assertUsedUp();
if (deleteBefore) {
assertEquals(setDerived, derived.isDerived());
Expand All @@ -576,7 +575,7 @@ public void testWrite() throws CoreException {
derived.write(("update" + i).getBytes(), false, false, keepHistory, null);
boolean oldDerived2 = derived.isDerived();
assertEquals(oldDerived2, derived.isDerived());
assertEquals("not atomic", 1, changeCount.get());
assertEquals(1, changeCount.get(), "not atomic");
IFileState[] history2 = derived.getHistory(null);
assertEquals((keepHistory && !oldDerived2) ? 1 : 0, history2.length - history1.length);
}
Expand Down Expand Up @@ -682,14 +681,14 @@ public void testWriteRule() throws CoreException {
resource.write(("create").getBytes(), false, false, false, null);
}, workspace.getRuleFactory().createRule(resource), IWorkspace.AVOID_UPDATE, null);
assertTrue(resource.exists());
assertEquals("not atomic", 1, changeCount.get());
assertEquals(1, changeCount.get(), "not atomic");
// test that modifyRule can be used for IFile.write() if the file already exits:
changeCount.set(0);
workspace.run(pm -> {
resource.write(("replace").getBytes(), false, false, false, null);
}, workspace.getRuleFactory().modifyRule(resource), IWorkspace.AVOID_UPDATE, null);
assertTrue(resource.exists());
assertEquals("not atomic", 1, changeCount.get());
assertEquals(1, changeCount.get(), "not atomic");
}

@Test
Expand Down Expand Up @@ -1084,10 +1083,10 @@ public void testInvalidFileNames() throws CoreException {
for (String name : names) {
monitor.prepare();
IFile file = project.getFile(IPath.fromPortableString(name));
assertTrue("1.0 " + name, !file.exists());
assertFalse(file.exists(), name);
assertThrows(CoreException.class, () -> file.create(createRandomContentsStream(), true, monitor));
monitor.sanityCheck();
assertTrue("1.2 " + name, !file.exists());
assertFalse(file.exists(), name);
}

//do some tests with valid names that are *almost* invalid
Expand All @@ -1100,11 +1099,11 @@ public void testInvalidFileNames() throws CoreException {
}
for (String name : names) {
IFile file = project.getFile(name);
assertFalse(name + " shouldn't exist", file.exists());
assertFalse(file.exists(), name + " shouldn't exist");
monitor.prepare();
file.create(createRandomContentsStream(), true, monitor);
monitor.assertUsedUp();
assertTrue(name + " should exist", file.exists());
assertTrue(file.exists(), name + " should exist");
}
}

Expand Down Expand Up @@ -1243,7 +1242,7 @@ public void testReadAll() throws IOException, CoreException {
target.setContents(content, true, false, monitor);
monitor.assertUsedUp();
byte[] allBytes = target.readAllBytes();
assertArrayEquals(target.getName(), content, allBytes);
assertArrayEquals(content, allBytes, target.getName());
char[] allChars = target.readAllChars();
String readString = target.readString();
String expected;
Expand All @@ -1254,8 +1253,8 @@ public void testReadAll() throws IOException, CoreException {
// ".txt" files autodetect charset by BOM if present
expected = testString;
}
assertArrayEquals(target.getName(), expected.toCharArray(), allChars);
assertEquals(target.getName(), expected, readString);
assertArrayEquals(expected.toCharArray(), allChars, target.getName());
assertEquals(expected, readString, target.getName());
}
}
}
Expand Down
Loading
Loading