Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix unstable DecoratableResourceAdapterTest

It failed in https://hudson.eclipse.org/sandbox/job/egit.gerrit/4256/
because it was using the workspace root as a repository, which can be
pretty unstable due to config files being added/removed.

Convert to a LocalRepositoryTestCase to fix this.

Change-Id: Ic2d0b861f9f069cabb9b0890d1e6c5a92ac67d1c
  • Loading branch information...
commit a49e82d425994bf44248ab5fc7c262ff89c81ae1 1 parent 739a416
Robin Stocker robinst authored
78 org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceAdapterTest.java
View
@@ -3,6 +3,7 @@
* Copyright (C) 2011, Dariusz Luksza <dariusz@luksza.org>
* Copyright (C) 2011, Christian Halstrick <christian.halstrick@sap.com>
* Copyright (C) 2011, Jens Baumgart <jens.baumgart@sap.com>
+ * Copyright (C) 2013, Robin Stocker <robin@nibor.org>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -11,45 +12,34 @@
*******************************************************************************/
package org.eclipse.egit.ui.internal.decorators;
+import static org.eclipse.jgit.junit.JGitTestUtil.write;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import java.io.ByteArrayInputStream;
import java.io.File;
-import java.util.Collections;
-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.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.egit.core.Activator;
-import org.eclipse.egit.core.GitProvider;
import org.eclipse.egit.core.JobFamilies;
import org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry;
import org.eclipse.egit.core.internal.indexdiff.IndexDiffData;
-import org.eclipse.egit.core.project.GitProjectData;
-import org.eclipse.egit.core.project.RepositoryMapping;
+import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
import org.eclipse.egit.ui.internal.decorators.IDecoratableResource.Staged;
import org.eclipse.egit.ui.test.TestUtil;
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.jgit.util.FileUtils;
-import org.eclipse.team.core.RepositoryProvider;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-public class DecoratableResourceAdapterTest extends LocalDiskRepositoryTestCase {
-
- private static final String TEST_PROJECT = "TestProject";
+public class DecoratableResourceAdapterTest extends LocalRepositoryTestCase {
private static final String TEST_FILE = "TestFile";
@@ -63,8 +53,6 @@
private File gitDir;
- private Repository repository;
-
private IProject project;
private Git git;
@@ -73,42 +61,13 @@
@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();
- repository.close();
- repository = Activator.getDefault().getRepositoryCache()
- .lookupRepository(gitDir);
-
- project = root.getProject(TEST_PROJECT);
- project.create(null);
- project.open(null);
-
- project.getFolder(TEST_FOLDER2).create(true, true, null);
- IFile testFile2 = project.getFile(TEST_FILE2);
- testFile2.create(new ByteArrayInputStream("content".getBytes()), true,
- null);
-
- RepositoryMapping mapping = new RepositoryMapping(project, gitDir);
-
- GitProjectData projectData = new GitProjectData(project);
- projectData.setRepositoryMappings(Collections.singleton(mapping));
- projectData.store();
- GitProjectData.add(project, projectData);
-
- RepositoryProvider.map(project, GitProvider.class.getName());
-
- git = new Git(repository);
- git.add().addFilepattern(".").call();
- git.commit().setMessage("Initial commit").call();
+ gitDir = createProjectAndCommitToRepository();
+ project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1);
+ FileRepository repo = lookupRepository(gitDir);
+ git = new Git(repo);
indexDiffCacheEntry = Activator.getDefault().getIndexDiffCache()
- .getIndexDiffCacheEntry(repository);
+ .getIndexDiffCacheEntry(repo);
waitForIndexDiffUpdate(false);
}
@@ -121,21 +80,10 @@ private void waitForIndexDiffUpdate(final boolean refreshCache)
@After
public void tearDown() throws Exception {
- super.tearDown();
-
- // Reverse setup...
-
- RepositoryProvider.unmap(project);
-
- GitProjectData.delete(project);
-
- project.delete(true, true, null);
-
- repository.close();
-
- Activator.getDefault().getRepositoryCache().clear();
-
- recursiveDelete(gitDir);
+ deleteAllProjects();
+ shutDownRepositories();
+ FileUtils.delete(gitDir.getParentFile(), FileUtils.RECURSIVE
+ | FileUtils.RETRY);
}
@Test
Please sign in to comment.
Something went wrong with that request. Please try again.