Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Muskalla2010-08-24 19:23:00 -0400
committerChris Aniszczyk2010-08-30 17:00:17 -0400
commitdf106a0d50304dda895fcb9538092d91cee769f8 (patch)
treec2e7427c4134d05f6bf5a2f43cb8a62776504ca0 /org.eclipse.egit.core.test
parent898dcebccec88f896e0265d70243e7f8adfbca8a (diff)
downloadegit-df106a0d50304dda895fcb9538092d91cee769f8.tar.gz
egit-df106a0d50304dda895fcb9538092d91cee769f8.tar.xz
egit-df106a0d50304dda895fcb9538092d91cee769f8.zip
Add tests for IgnoreOperation
In order to have a better test coverage before fixing and refactoring other changes, we need to ensure to have at least most of the features covered by tests. In addition, fixed minor bug to really use the scheduling rules we create. Change-Id: If63a9632b28aeb7d6ef585f889876ec42dac2c0c Signed-off-by: Benjamin Muskalla <bmuskalla@eclipsesource.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Diffstat (limited to 'org.eclipse.egit.core.test')
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestProject.java5
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestUtils.java12
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/IgnoreOperationTest.java119
3 files changed, 130 insertions, 6 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestProject.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestProject.java
index 0cd8f283b..50a96656c 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestProject.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestProject.java
@@ -203,6 +203,11 @@ public class TestProject {
// }, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
}
+ public String getFileContent(String filepath) throws Exception {
+ IFile file = project.getFile(filepath);
+ InputStream stream = file.getContents();
+ return testUtils.slurpAndClose(stream);
+ }
/**
* @return Returns the sourceFolder.
*/
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestUtils.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestUtils.java
index b2993fb83..8ff9eb80d 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestUtils.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestUtils.java
@@ -166,10 +166,10 @@ public class TestUtils {
*/
public IProject createProjectInLocalFileSystem(File parentFile,
String projectName) throws Exception {
- IProject firstProject = ResourcesPlugin.getWorkspace().getRoot()
+ IProject project = ResourcesPlugin.getWorkspace().getRoot()
.getProject(projectName);
- if (firstProject.exists()) {
- firstProject.delete(true, null);
+ if (project.exists()) {
+ project.delete(true, null);
}
File testFile = new File(parentFile, projectName);
if (testFile.exists())
@@ -178,8 +178,8 @@ public class TestUtils {
IProjectDescription desc = ResourcesPlugin.getWorkspace()
.newProjectDescription(projectName);
desc.setLocation(new Path(new File(parentFile, projectName).getPath()));
- firstProject.create(desc, null);
- firstProject.open(null);
- return firstProject;
+ project.create(desc, null);
+ project.open(null);
+ return project;
}
}
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/IgnoreOperationTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/IgnoreOperationTest.java
new file mode 100644
index 000000000..664335f0a
--- /dev/null
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/IgnoreOperationTest.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (C) 2010, Benjamin Muskalla <bmuskalla@eclipsesource.com>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.core.test.op;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.egit.core.op.IgnoreOperation;
+import org.eclipse.egit.core.test.GitTestCase;
+import org.eclipse.egit.core.test.TestRepository;
+import org.eclipse.jgit.lib.Constants;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class IgnoreOperationTest extends GitTestCase {
+
+ private TestRepository testRepository;
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ testRepository = new TestRepository(gitDir);
+ testRepository.connect(project.getProject());
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ testRepository.dispose();
+ super.tearDown();
+ }
+
+ @Test
+ public void testIgnoreFolder() throws Exception {
+ IFolder binFolder = project.getProject().getFolder("bin");
+ IgnoreOperation operation = new IgnoreOperation(
+ new IResource[] { binFolder });
+ operation.execute(new NullProgressMonitor());
+
+ String content = project.getFileContent(Constants.GITIGNORE_FILENAME);
+ assertEquals("/bin\n", content);
+ assertFalse(operation.isGitignoreOutsideWSChanged());
+ }
+
+ @Test
+ public void testIgnoreFileCancel() throws Exception {
+ IFolder binFolder = project.getProject().getFolder("bin");
+ IgnoreOperation operation = new IgnoreOperation(
+ new IResource[] { binFolder });
+ NullProgressMonitor monitor = new NullProgressMonitor();
+ monitor.setCanceled(true);
+ operation.execute(monitor);
+
+ assertFalse(project.getProject().getFile(Constants.GITIGNORE_FILENAME).exists());
+ }
+
+
+ @Test
+ public void testSchedulingRule() throws Exception {
+ IFolder binFolder = project.getProject().getFolder("bin");
+ IgnoreOperation operation = new IgnoreOperation(
+ new IResource[] { binFolder });
+ NullProgressMonitor monitor = new NullProgressMonitor();
+ operation.execute(monitor);
+
+ assertNotNull(operation.getSchedulingRule());
+ }
+
+ @Test
+ public void testIgnoreMultiFile() throws Exception {
+ project.createSourceFolder();
+ IFolder binFolder = project.getProject().getFolder("bin");
+ IFolder srcFolder = project.getProject().getFolder("src");
+ IgnoreOperation operation = new IgnoreOperation(
+ new IResource[] { binFolder });
+ operation.execute(new NullProgressMonitor());
+
+ String content = project.getFileContent(Constants.GITIGNORE_FILENAME);
+ assertEquals("/bin\n", content);
+
+ operation = new IgnoreOperation(
+ new IResource[] { srcFolder });
+ operation.execute(new NullProgressMonitor());
+
+ content = project.getFileContent(Constants.GITIGNORE_FILENAME);
+ assertEquals("/bin\n/src\n", content);
+ }
+
+ @Test
+ public void testIgnoreProject() throws Exception {
+ IgnoreOperation operation = new IgnoreOperation(
+ new IResource[] { project.getProject() });
+ operation.execute(new NullProgressMonitor());
+
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ File rootFile = root.getRawLocation().toFile();
+ File ignoreFile = new File(rootFile, Constants.GITIGNORE_FILENAME);
+ String content = testUtils.slurpAndClose(ignoreFile.toURL()
+ .openStream());
+ assertEquals("/" + project.getProject().getName() + "\n", content);
+ assertTrue(operation.isGitignoreOutsideWSChanged());
+ }
+
+}

Back to the top