aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Thun2011-02-09 09:24:47 (EST)
committerPhilipp Thun2011-02-14 03:45:42 (EST)
commit9af6a9766cb836f6fcf062aac565e3e0ffcedb6d (patch)
treef19be2485146b8b21065d9450782cb29826b31cf
parent093d3a92bf5a5d4c7819078d2196bc68366cafda (diff)
downloadegit-9af6a9766cb836f6fcf062aac565e3e0ffcedb6d.zip
egit-9af6a9766cb836f6fcf062aac565e3e0ffcedb6d.tar.gz
egit-9af6a9766cb836f6fcf062aac565e3e0ffcedb6d.tar.bz2
Add unit tests for decorationrefs/changes/70/2470/2
This change adds non-SWT unit tests to the org.eclipse.egit.ui.test project. The launch configuration for SWT tests has been renamed and an additional launch configuration for non-SWT tests has been created. Change-Id: Ib62c5efa24c12d4a6b562baf50b34793143bbf10 Signed-off-by: Philipp Thun <philipp.thun@sap.com>
-rw-r--r--org.eclipse.egit.ui.test/org.eclipse.egit.ui--All-Non-SWT-Tests.launch44
-rw-r--r--org.eclipse.egit.ui.test/org.eclipse.egit.ui--All-SWT-Tests.launch (renamed from org.eclipse.egit.ui.test/org.eclipse.egit.ui--All tests.launch)1
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/nonswt/AllNonSWTTests.java20
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/nonswt/decoration/DecoratableResourceHelperTest.java282
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResource.java22
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceHelper.java15
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitDecoratorJob.java2
7 files changed, 372 insertions, 14 deletions
diff --git a/org.eclipse.egit.ui.test/org.eclipse.egit.ui--All-Non-SWT-Tests.launch b/org.eclipse.egit.ui.test/org.eclipse.egit.ui--All-Non-SWT-Tests.launch
new file mode 100644
index 0000000..e5bc9dc
--- /dev/null
+++ b/org.eclipse.egit.ui.test/org.eclipse.egit.ui--All-Non-SWT-Tests.launch
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="org.eclipse.pde.ui.JunitLaunchConfig">
+<booleanAttribute key="askclear" value="false"/>
+<booleanAttribute key="automaticAdd" value="true"/>
+<booleanAttribute key="automaticValidate" value="false"/>
+<stringAttribute key="bootstrap" value=""/>
+<stringAttribute key="checked" value="[NONE]"/>
+<booleanAttribute key="clearConfig" value="true"/>
+<booleanAttribute key="clearws" value="true"/>
+<booleanAttribute key="clearwslog" value="false"/>
+<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/>
+<booleanAttribute key="default" value="true"/>
+<booleanAttribute key="includeOptional" value="true"/>
+<stringAttribute key="location" value="${workspace_loc}/../junit-workspace"/>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/nonswt/AllNonSWTTests.java"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="1"/>
+</listAttribute>
+<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
+<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
+<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
+<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
+</listAttribute>
+<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
+<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
+<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
+<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.egit.ui.test.nonswt.AllNonSWTTests"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.egit.ui.test"/>
+<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx512m&#13;&#10;-XX:MaxPermSize=256m"/>
+<stringAttribute key="pde.version" value="3.3"/>
+<stringAttribute key="product" value="org.eclipse.sdk.ide"/>
+<booleanAttribute key="run_in_ui_thread" value="true"/>
+<booleanAttribute key="show_selected_only" value="false"/>
+<booleanAttribute key="tracing" value="false"/>
+<booleanAttribute key="useCustomFeatures" value="false"/>
+<booleanAttribute key="useDefaultConfig" value="true"/>
+<booleanAttribute key="useDefaultConfigArea" value="false"/>
+<booleanAttribute key="useProduct" value="true"/>
+</launchConfiguration>
diff --git a/org.eclipse.egit.ui.test/org.eclipse.egit.ui--All tests.launch b/org.eclipse.egit.ui.test/org.eclipse.egit.ui--All-SWT-Tests.launch
index 0a6f68a..cb60341 100644
--- a/org.eclipse.egit.ui.test/org.eclipse.egit.ui--All tests.launch
+++ b/org.eclipse.egit.ui.test/org.eclipse.egit.ui--All-SWT-Tests.launch
@@ -33,6 +33,7 @@
<booleanAttribute key="run_in_ui_thread" value="true"/>
<booleanAttribute key="show_selected_only" value="false"/>
<booleanAttribute key="tracing" value="false"/>
+<booleanAttribute key="useCustomFeatures" value="false"/>
<booleanAttribute key="useDefaultConfig" value="true"/>
<booleanAttribute key="useDefaultConfigArea" value="false"/>
<booleanAttribute key="useProduct" value="true"/>
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/nonswt/AllNonSWTTests.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/nonswt/AllNonSWTTests.java
new file mode 100644
index 0000000..43de33c
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/nonswt/AllNonSWTTests.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (C) 2011, Philipp Thun <philipp.thun@sap.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.ui.test.nonswt;
+
+import org.eclipse.egit.ui.test.nonswt.decoration.DecoratableResourceHelperTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+@RunWith(Suite.class)
+@SuiteClasses({ DecoratableResourceHelperTest.class })
+public class AllNonSWTTests {
+ // Empty class
+}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/nonswt/decoration/DecoratableResourceHelperTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/nonswt/decoration/DecoratableResourceHelperTest.java
new file mode 100644
index 0000000..3d7d9fe
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/nonswt/decoration/DecoratableResourceHelperTest.java
@@ -0,0 +1,282 @@
+/*******************************************************************************
+ * Copyright (C) 2011, Philipp Thun <philipp.thun@sap.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.ui.test.nonswt.decoration;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.Collections;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.egit.core.GitProvider;
+import org.eclipse.egit.core.project.GitProjectData;
+import org.eclipse.egit.core.project.RepositoryMapping;
+import org.eclipse.egit.ui.internal.decorators.DecoratableResource;
+import org.eclipse.egit.ui.internal.decorators.DecoratableResourceHelper;
+import org.eclipse.egit.ui.internal.decorators.IDecoratableResource;
+import org.eclipse.egit.ui.internal.decorators.IDecoratableResource.Staged;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.MergeResult.MergeStatus;
+import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.storage.file.FileRepository;
+import org.eclipse.team.core.RepositoryProvider;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class DecoratableResourceHelperTest extends LocalDiskRepositoryTestCase {
+
+ private static final String TEST_PROJECT = "TestProject";
+
+ private static final String TEST_FILE = "TestFile";
+
+ private File gitDir;
+
+ private Repository repository;
+
+ private IProject project;
+
+ private Git git;
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+
+ gitDir = new File(root.getLocation().toFile(), Constants.DOT_GIT);
+
+ repository = new FileRepository(gitDir);
+ repository.create();
+
+ project = root.getProject(TEST_PROJECT);
+ project.create(null);
+ project.open(null);
+
+ RepositoryMapping mapping = new RepositoryMapping(project, gitDir);
+
+ GitProjectData projectData = new GitProjectData(project);
+ projectData.setRepositoryMappings(Collections.singleton(mapping));
+ projectData.store();
+
+ RepositoryProvider.map(project, GitProvider.class.getName());
+
+ git = new Git(repository);
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("Initial commit").call();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ // Reverse setup...
+
+ RepositoryProvider.unmap(project);
+
+ GitProjectData.delete(project);
+
+ project.delete(true, true, null);
+
+ repository.close();
+
+ recursiveDelete(gitDir);
+ }
+
+ @Test
+ public void testDecorationEmptyProject() throws Exception {
+ IDecoratableResource[] expectedDRs = new IDecoratableResource[] { new TestDecoratableResource(
+ project, true, false, false, false, Staged.NOT_STAGED) };
+
+ IDecoratableResource[] actualDRs = DecoratableResourceHelper
+ .createDecoratableResources(new IResource[] { project });
+
+ for (int i = 0; i < expectedDRs.length; i++)
+ assertTrue(expectedDRs[i].equals(actualDRs[i]));
+ }
+
+ @Test
+ public void testDecorationNewFile() throws Exception {
+ // Create new file
+ write(new File(project.getLocation().toFile(), TEST_FILE), "Something");
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ IResource file = project.findMember(TEST_FILE);
+
+ IDecoratableResource[] expectedDRs = new IDecoratableResource[] {
+ new TestDecoratableResource(project, true, false, false, false,
+ Staged.NOT_STAGED),
+ new TestDecoratableResource(file, false, false, false, false,
+ Staged.NOT_STAGED) };
+
+ IDecoratableResource[] actualDRs = DecoratableResourceHelper
+ .createDecoratableResources(new IResource[] { project, file });
+
+ for (int i = 0; i < expectedDRs.length; i++)
+ assertTrue(expectedDRs[i].equals(actualDRs[i]));
+ }
+
+ @Test
+ public void testDecorationAddedFile() throws Exception {
+ // Create new file
+ write(new File(project.getLocation().toFile(), TEST_FILE), "Something");
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ IResource file = project.findMember(TEST_FILE);
+ // Add file
+ git.add().addFilepattern(".").call();
+
+ IDecoratableResource[] expectedDRs = new IDecoratableResource[] {
+ new TestDecoratableResource(project, true, false, false, false,
+ Staged.MODIFIED),
+ new TestDecoratableResource(file, true, false, false, false,
+ Staged.ADDED) };
+
+ IDecoratableResource[] actualDRs = DecoratableResourceHelper
+ .createDecoratableResources(new IResource[] { project, file });
+
+ for (int i = 0; i < expectedDRs.length; i++)
+ assertTrue(expectedDRs[i].equals(actualDRs[i]));
+ }
+
+ @Test
+ public void testDecorationCommittedFile() throws Exception {
+ // Create new file
+ write(new File(project.getLocation().toFile(), TEST_FILE), "Something");
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ IResource file = project.findMember(TEST_FILE);
+ // Add and commit file
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("First commit").call();
+
+ IDecoratableResource[] expectedDRs = new IDecoratableResource[] {
+ new TestDecoratableResource(project, true, false, false, false,
+ Staged.NOT_STAGED),
+ new TestDecoratableResource(file, true, false, false, false,
+ Staged.NOT_STAGED) };
+
+ IDecoratableResource[] actualDRs = DecoratableResourceHelper
+ .createDecoratableResources(new IResource[] { project, file });
+
+ for (int i = 0; i < expectedDRs.length; i++)
+ assertTrue(expectedDRs[i].equals(actualDRs[i]));
+ }
+
+ @Test
+ public void testDecorationModifiedFile() throws Exception {
+ // Create new file
+ File f = new File(project.getLocation().toFile(), TEST_FILE);
+ write(f, "Something");
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ IResource file = project.findMember(TEST_FILE);
+ // Add and commit file
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("First commit").call();
+
+ // Change file content
+ write(f, "SomethingElse");
+
+ IDecoratableResource[] expectedDRs = new IDecoratableResource[] {
+ new TestDecoratableResource(project, true, false, true, false,
+ Staged.NOT_STAGED),
+ new TestDecoratableResource(file, true, false, true, false,
+ Staged.NOT_STAGED) };
+
+ IDecoratableResource[] actualDRs = DecoratableResourceHelper
+ .createDecoratableResources(new IResource[] { project, file });
+
+ for (int i = 0; i < expectedDRs.length; i++)
+ assertTrue(expectedDRs[i].equals(actualDRs[i]));
+ }
+
+ @Test
+ public void testDecorationConflictingFile() throws Exception {
+ // Create new file
+ File f = new File(project.getLocation().toFile(), TEST_FILE);
+ write(f, "Something");
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ IResource file = project.findMember(TEST_FILE);
+ // Add and commit file
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("Commit on master branch").call();
+
+ // Create and checkout new branch, change file content, add and commit
+ // file
+ git.checkout().setCreateBranch(true).setName("first_topic").call();
+ write(f, "SomethingElse");
+ git.add().addFilepattern(".").call();
+ RevCommit commitOnFirstTopicBranch = git.commit()
+ .setMessage("Commit on first topic branch").call();
+
+ // Create and checkout new branch (from master), change file content,
+ // add and commit file
+ git.checkout().setName("master").call();
+ git.checkout().setCreateBranch(true).setName("second_topic").call();
+ write(f, "SomethingDifferent");
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("Commit on second topic branch").call();
+
+ // Merge HEAD ('Commit on second topic branch') with 'Commit on first
+ // topic branch' to create a conflict
+ assertTrue(git.merge().include(commitOnFirstTopicBranch).call()
+ .getMergeStatus() == MergeStatus.CONFLICTING);
+
+ IDecoratableResource[] expectedDRs = new IDecoratableResource[] {
+ new TestDecoratableResource(project, true, false, true, true,
+ Staged.MODIFIED),
+ new TestDecoratableResource(file, true, false, true, true,
+ Staged.MODIFIED) };
+
+ IDecoratableResource[] actualDRs = DecoratableResourceHelper
+ .createDecoratableResources(new IResource[] { project, file });
+
+ for (int i = 0; i < expectedDRs.length; i++)
+ assertTrue(expectedDRs[i].equals(actualDRs[i]));
+ }
+}
+
+class TestDecoratableResource extends DecoratableResource {
+
+ public TestDecoratableResource(IResource resource, boolean tracked,
+ boolean ignored, boolean dirty, boolean conflicts, Staged staged) {
+ super(resource);
+ this.tracked = tracked;
+ this.ignored = ignored;
+ this.dirty = dirty;
+ this.conflicts = conflicts;
+ this.staged = staged;
+ }
+
+ public boolean equals(Object obj) {
+ if (!(obj instanceof IDecoratableResource))
+ return false;
+
+ IDecoratableResource decoratableResource = (IDecoratableResource) obj;
+ if (!(decoratableResource.getType() == getType()))
+ return false;
+ if (!decoratableResource.getName().equals(getName()))
+ return false;
+ if (!(decoratableResource.isTracked() == isTracked()))
+ return false;
+ if (!(decoratableResource.isIgnored() == isIgnored()))
+ return false;
+ if (!(decoratableResource.isDirty() == isDirty()))
+ return false;
+ if (!(decoratableResource.hasConflicts() == hasConflicts()))
+ return false;
+ if (!decoratableResource.staged().equals(staged()))
+ return false;
+
+ return true;
+ }
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResource.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResource.java
index 176964d..08bfabf 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResource.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResource.java
@@ -15,53 +15,53 @@ import org.eclipse.core.resources.IResource;
*
* @see IDecoratableResource
*/
-class DecoratableResource implements IDecoratableResource {
+public class DecoratableResource implements IDecoratableResource {
/**
* Resource to be decorated
*/
- IResource resource = null;
+ protected IResource resource = null;
/**
* Name of the repository of the resource
*/
- String repositoryName = null;
+ protected String repositoryName = null;
/**
* Current branch of the resource
*/
- String branch = null;
+ protected String branch = null;
/**
* Flag indicating whether or not the resource is tracked
*/
- boolean tracked = false;
+ protected boolean tracked = false;
/**
* Flag indicating whether or not the resource is ignored
*/
- boolean ignored = false;
+ protected boolean ignored = false;
/**
* Flag indicating whether or not the resource has changes that are not
* staged
*/
- boolean dirty = false;
+ protected boolean dirty = false;
/**
* Staged state of the resource
*/
- Staged staged = Staged.NOT_STAGED;
+ protected Staged staged = Staged.NOT_STAGED;
/**
* Flag indicating whether or not the resource has merge conflicts
*/
- boolean conflicts = false;
+ protected boolean conflicts = false;
/**
* Flag indicating whether or not the resource is assumed valid
*/
- boolean assumeValid = false;
+ protected boolean assumeValid = false;
/**
* Constructs a new decoratable resource
@@ -72,7 +72,7 @@ class DecoratableResource implements IDecoratableResource {
* @param resource
* resource to be decorated
*/
- DecoratableResource(IResource resource) {
+ protected DecoratableResource(IResource resource) {
this.resource = resource;
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceHelper.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceHelper.java
index 816def2..9a72f20 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceHelper.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceHelper.java
@@ -37,7 +37,7 @@ import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
*
* @see IDecoratableResource
*/
-class DecoratableResourceHelper {
+public class DecoratableResourceHelper {
static final int T_HEAD = 0;
@@ -47,8 +47,19 @@ class DecoratableResourceHelper {
private static final Map<Repository, DirCache> repoToDirCache = new WeakHashMap<Repository, DirCache>();
- static IDecoratableResource[] createDecoratableResources(
+ /**
+ * Creates a list of decoratable resources for the given list of resources
+ *
+ * @param resources
+ * the list of resources to be decorated
+ * @return the list of decoratable resources
+ * @throws IOException
+ */
+ public static IDecoratableResource[] createDecoratableResources(
final IResource[] resources) throws IOException {
+ if (resources == null)
+ return null;
+
// Use first (available) resource to get repository mapping
int i = 0;
while (resources[i] == null) {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitDecoratorJob.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitDecoratorJob.java
index a148842..5cb108e 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitDecoratorJob.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitDecoratorJob.java
@@ -38,7 +38,7 @@ public class GitDecoratorJob extends Job {
* @param gitDir
* the .git directory's full path used as unique identifier of a
* repository
- * @return GitDecoratorJob the job dedicated for the given repository
+ * @return the job dedicated for the given repository
*/
public static synchronized GitDecoratorJob getJobForRepository(
final String gitDir) {