Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Sheng Chen <[email protected]>
  • Loading branch information
jdneo committed Oct 14, 2019
1 parent 52ca212 commit 879f82a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
package org.eclipse.jdt.ls.core.internal;

import static org.eclipse.core.resources.IResource.DEPTH_ONE;
import static org.eclipse.core.resources.IResource.DEPTH_ZERO;

import java.io.File;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.commons.io.FileUtils;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
Expand Down Expand Up @@ -229,4 +230,22 @@ public void testIsFolder() throws Exception {
assertNotNull(JDTUtils.findFile(uriFile.toString()));
assertNotNull(JDTUtils.findFolder(uriFolder.toString()));
}

@Test
public void testGetFileOrFolder() throws Exception {
// For: https://github.com/eclipse/eclipse.jdt.ls/issues/1137
IProject project = WorkspaceHelper.getProject(ProjectsManager.DEFAULT_PROJECT_NAME);

File parentFolder = new File(project.getLocation().toString(), "/src/org/eclipse");
IResource parent = JDTUtils.getFileOrFolder(parentFolder.toURI().toString());
assertTrue(parent instanceof IFolder);
final int originalMemberNum = ((IFolder) parent).members().length;

File newPackage = new File(project.getLocation().toString(), "/src/org/eclipse/testGetFileOrFolder");
newPackage.mkdirs();

IResource resource = JDTUtils.getFileOrFolder(newPackage.toURI().toString());
assertTrue(resource instanceof IFolder);
assertEquals("The parent package should be aware of the newly created child package", ((IFolder) parent).members().length, originalMemberNum + 1);
}
}

0 comments on commit 879f82a

Please sign in to comment.