Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.egit.ui.test/src/org')
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/CompareEditorTester.java4
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/JavaProjectTester.java229
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/StagingViewTester.java12
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/CompareUtilsTest.java41
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/selection/SelectionForViewsTest.java24
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/submodules/SubmoduleFolderTest.java21
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/history/HistoryViewTest.java19
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/JavaCompareTest.java106
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/MergeToolTest.java16
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/ShowBlameActionHandlerTest.java216
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewBranchHandlingTest.java3
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java17
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestBase.java19
13 files changed, 500 insertions, 227 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/CompareEditorTester.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/CompareEditorTester.java
index 687a8d09b..940bf9631 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/CompareEditorTester.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/CompareEditorTester.java
@@ -48,6 +48,10 @@ public class CompareEditorTester {
return getNonAncestorEditor(1);
}
+ public boolean isDirty() {
+ return editor.isDirty();
+ }
+
public void save() {
editor.save();
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/JavaProjectTester.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/JavaProjectTester.java
new file mode 100644
index 000000000..eb602c628
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/JavaProjectTester.java
@@ -0,0 +1,229 @@
+/*******************************************************************************
+ * Copyright (C) 2019, Thomas Wolf <thomas.wolf@paranor.ch>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************/
+package org.eclipse.egit.ui.common;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceDescription;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.egit.core.Activator;
+import org.eclipse.egit.core.internal.indexdiff.IndexDiffCache;
+import org.eclipse.egit.core.op.CommitOperation;
+import org.eclipse.egit.core.op.ConnectProviderOperation;
+import org.eclipse.egit.ui.test.TestUtil;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.jgit.lib.Repository;
+
+public class JavaProjectTester {
+
+ public static final String JAVA_PROJECT_NAME = "javatestProject";
+
+ public static final String SRC_FOLDER_NAME = "src";
+
+ public static final String BIN_FOLDER_NAME = "bin";
+
+ public static final String PACKAGE_NAME = "p";
+
+ public static final String JAVA_CLASS_NAME = "A";
+
+ public static final String JAVA_FILE_NAME = JAVA_CLASS_NAME + ".java";
+
+ public static final String JAVA_FILE_PATH = JAVA_PROJECT_NAME + '/'
+ + SRC_FOLDER_NAME + '/' + PACKAGE_NAME + '/' + JAVA_FILE_NAME;
+
+ public static final String INITIAL_FILE_CONTENT = "package " + PACKAGE_NAME
+ + ";\nclass " + JAVA_CLASS_NAME + " {\n\n}";
+
+ private static final int MAX_DELETE_RETRY = 5;
+
+ private static final int DELETE_RETRY_DELAY = 1000; // ms
+
+ private final LocalRepositoryTestCase testCase;
+
+ public JavaProjectTester(LocalRepositoryTestCase testCase) {
+ this.testCase = testCase;
+ }
+
+ public static boolean setAutobuild(boolean value) throws CoreException {
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IWorkspaceDescription desc = workspace.getDescription();
+ boolean isAutoBuilding = desc.isAutoBuilding();
+ if (isAutoBuilding != value) {
+ desc.setAutoBuilding(value);
+ workspace.setDescription(desc);
+ }
+ return isAutoBuilding;
+ }
+
+ public IJavaProject createJavaProjectAndCommitToRepository()
+ throws Exception {
+ Repository myRepository = testCase
+ .createLocalTestRepository(LocalRepositoryTestCase.REPO1);
+ File gitDir = myRepository.getDirectory();
+ IJavaProject jProject = createJavaProject(myRepository,
+ JAVA_PROJECT_NAME);
+ IProject project = jProject.getProject();
+ try {
+ new ConnectProviderOperation(project, gitDir).execute(null);
+ } catch (Exception e) {
+ Activator.logError("Failed to connect project to repository", e);
+ }
+ testCase.assertConnected(project);
+ // Check in at least the java file
+ IFolder folder = project.getFolder(SRC_FOLDER_NAME)
+ .getFolder(PACKAGE_NAME);
+ IFile file = folder.getFile(JAVA_FILE_NAME);
+
+ IFile[] commitables = new IFile[] { file };
+ ArrayList<IFile> untracked = new ArrayList<>();
+ untracked.addAll(Arrays.asList(commitables));
+ // commit to master
+ CommitOperation op = new CommitOperation(commitables, untracked,
+ TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Initial commit");
+ op.execute(null);
+
+ // Make sure cache entry is already listening for changes
+ IndexDiffCache cache = Activator.getDefault().getIndexDiffCache();
+ cache.getIndexDiffCacheEntry(Activator.getDefault().getRepositoryCache()
+ .lookupRepository(gitDir));
+ return jProject;
+ }
+
+ private IJavaProject createJavaProject(final Repository repository,
+ final String projectName) throws Exception {
+ final IJavaProject[] jProjectHolder = new IJavaProject[] { null };
+ IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
+ @Override
+ public void run(IProgressMonitor monitor) throws CoreException {
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IProject project = root.getProject(projectName);
+ if (project.exists()) {
+ project.delete(true, null);
+ TestUtil.waitForJobs(100, 5000);
+ }
+ IProjectDescription desc = ResourcesPlugin.getWorkspace()
+ .newProjectDescription(projectName);
+ desc.setLocation(
+ new Path(new File(repository.getWorkTree(), projectName)
+ .getPath()));
+ project.create(desc, null);
+ project.open(null);
+ TestUtil.waitForJobs(50, 5000);
+ // Create a "bin" folder
+ IFolder bin = project.getFolder(BIN_FOLDER_NAME);
+ if (!bin.exists()) {
+ bin.create(IResource.FORCE | IResource.DERIVED, true, null);
+ }
+ IPath outputLocation = bin.getFullPath();
+ // Create a "src" folder
+ IFolder src = project.getFolder(SRC_FOLDER_NAME);
+ if (!src.exists()) {
+ src.create(IResource.FORCE, true, null);
+ }
+ addNatureToProject(project, JavaCore.NATURE_ID);
+ // Set up the IJavaProject
+ IJavaProject jProject = JavaCore.create(project);
+ IPackageFragmentRoot srcContainer = jProject
+ .getPackageFragmentRoot(src);
+ IClasspathEntry srcEntry = JavaCore
+ .newSourceEntry(srcContainer.getPath());
+ // Create a JRE classpath entry using the default JRE
+ IClasspathEntry jreEntry = JavaRuntime
+ .getDefaultJREContainerEntry();
+ jProject.setRawClasspath(
+ new IClasspathEntry[] { srcEntry, jreEntry },
+ outputLocation, true, null);
+ // Create a package with a single test class
+ IPackageFragment javaPackage = srcContainer
+ .createPackageFragment(PACKAGE_NAME, true, null);
+ javaPackage
+ .createCompilationUnit(JAVA_FILE_NAME,
+ INITIAL_FILE_CONTENT, true, null);
+ jProjectHolder[0] = jProject;
+ }
+ };
+ ResourcesPlugin.getWorkspace().run(runnable, null);
+ return jProjectHolder[0];
+ }
+
+ private void addNatureToProject(IProject proj, String natureId)
+ throws CoreException {
+ IProjectDescription description = proj.getDescription();
+ String[] prevNatures = description.getNatureIds();
+ String[] newNatures = new String[prevNatures.length + 1];
+ System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
+ newNatures[prevNatures.length] = natureId;
+ description.setNatureIds(newNatures);
+ proj.setDescription(description, null);
+ }
+
+ public void removeJavaProject(IJavaProject javaProject)
+ throws CoreException {
+ if (javaProject == null) {
+ return;
+ }
+ final IProject project = javaProject.getProject();
+ IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
+ @Override
+ public void run(IProgressMonitor monitor) throws CoreException {
+ // Following code inspired by {@link
+ // org.eclipse.jdt.testplugin.JavaProjectHelper#delete(IResource)}.
+ // I don't like all this sleeping at all, but apparently it's
+ // needed because the Java indexer might still run and hold on
+ // to some resources.
+ for (int i = 0; i < MAX_DELETE_RETRY; i++) {
+ try {
+ project.delete(IResource.FORCE
+ | IResource.ALWAYS_DELETE_PROJECT_CONTENT,
+ null);
+ break;
+ } catch (CoreException e) {
+ if (i == MAX_DELETE_RETRY - 1) {
+ throw e;
+ }
+ try {
+ Activator.logInfo(
+ "Sleep before retrying to delete project "
+ + project.getLocationURI());
+ // Give other threads the time to close and release
+ // the resource.
+ Thread.sleep(DELETE_RETRY_DELAY);
+ } catch (InterruptedException e1) {
+ // Ignore and retry to delete
+ }
+ }
+ }
+
+ }
+ };
+ ResourcesPlugin.getWorkspace().run(runnable, null);
+ }
+
+}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/StagingViewTester.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/StagingViewTester.java
index 232f7c79a..9d2d2c9e8 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/StagingViewTester.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/StagingViewTester.java
@@ -74,6 +74,18 @@ public class StagingViewTester {
.setText(message);
}
+ public void compareWithIndex(String path) {
+ SWTBotTree unstagedTree = stagingView.bot().tree(0);
+
+ TestUtil.waitUntilTreeHasNodeContainsText(stagingView.bot(),
+ unstagedTree, path, 10000);
+
+ TestUtil.getNode(unstagedTree.getAllItems(), path).select();
+
+ ContextMenuHelper.clickContextMenuSync(unstagedTree,
+ UIText.StagingView_CompareWithIndexMenuLabel);
+ }
+
public void stageFile(String path) {
SWTBotTree unstagedTree = stagingView.bot().tree(0);
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/CompareUtilsTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/CompareUtilsTest.java
index 83308efcd..c53580120 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/CompareUtilsTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/CompareUtilsTest.java
@@ -12,6 +12,8 @@ package org.eclipse.egit.ui.internal;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
import java.io.File;
import java.io.IOException;
@@ -22,6 +24,7 @@ import java.nio.charset.StandardCharsets;
import org.eclipse.compare.ITypedElement;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.egit.core.Activator;
import org.eclipse.egit.core.op.CommitOperation;
@@ -33,9 +36,14 @@ import org.eclipse.jgit.api.ResetCommand.ResetType;
import org.eclipse.jgit.attributes.FilterCommand;
import org.eclipse.jgit.attributes.FilterCommandFactory;
import org.eclipse.jgit.attributes.FilterCommandRegistry;
+import org.eclipse.jgit.dircache.DirCache;
+import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
+import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
import org.eclipse.jgit.util.IO;
import org.junit.Before;
import org.junit.Test;
@@ -95,6 +103,39 @@ public class CompareUtilsTest extends LocalRepositoryTestCase {
}
@Test
+ public void testIndexEditExecutable() throws Exception {
+ assumeTrue(repository.getFS().supportsExecute());
+ IFile testFile = touch("a");
+ File rawFile = new File(testFile.getLocation().toOSString());
+ repository.getFS().setExecute(rawFile, true);
+ testFile.refreshLocal(IResource.DEPTH_ZERO, null);
+ stage(testFile);
+ assertEquals("Executable bit should be set", FileMode.EXECUTABLE_FILE,
+ getIndexEntryMode(FILE1_PATH));
+ ITypedElement element = CompareUtils.getIndexTypedElement(testFile);
+ assert (element instanceof EditableRevision);
+ EditableRevision revision = (EditableRevision) element;
+ try (InputStream in = revision.getContents()) {
+ assertEquals("a", get(in));
+ }
+ revision.setContent("xx".getBytes(StandardCharsets.UTF_8));
+ // Get the index entry again and check the executable bit
+ assertEquals("Executable bit should be set", FileMode.EXECUTABLE_FILE,
+ getIndexEntryMode(FILE1_PATH));
+ }
+
+ private FileMode getIndexEntryMode(String path) throws Exception {
+ DirCache dc = repository.readDirCache();
+ try (TreeWalk w = new TreeWalk(repository)) {
+ w.addTree(new DirCacheIterator(dc));
+ w.setFilter(PathFilterGroup.createFromStrings(path));
+ w.setRecursive(true);
+ assertTrue(path + " not in index", w.next());
+ return w.getFileMode();
+ }
+ }
+
+ @Test
public void testIndexEditWithAttributes() throws Exception {
IFile testFile = touch("a");
stage(testFile);
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/selection/SelectionForViewsTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/selection/SelectionForViewsTest.java
index 28e605dd7..83351a919 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/selection/SelectionForViewsTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/selection/SelectionForViewsTest.java
@@ -20,16 +20,19 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
+import org.eclipse.core.commands.State;
import org.eclipse.core.runtime.Adapters;
import org.eclipse.egit.core.RepositoryUtil;
import org.eclipse.egit.core.op.CloneOperation;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.JobFamilies;
+import org.eclipse.egit.ui.internal.CommonUtils;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.rebase.RebaseInteractiveView;
import org.eclipse.egit.ui.internal.reflog.ReflogView;
import org.eclipse.egit.ui.internal.repository.RepositoriesView;
import org.eclipse.egit.ui.internal.repository.tree.RepositoryNode;
+import org.eclipse.egit.ui.internal.repository.tree.command.ToggleLinkWithSelectionCommand;
import org.eclipse.egit.ui.internal.staging.StagingView;
import org.eclipse.egit.ui.test.TestUtil;
import org.eclipse.egit.ui.view.repositories.GitRepositoriesViewTestBase;
@@ -49,6 +52,8 @@ import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.team.internal.ui.history.GenericHistoryView;
import org.eclipse.team.ui.history.IHistoryView;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.RegistryToggleState;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
@@ -78,6 +83,10 @@ public class SelectionForViewsTest extends GitRepositoriesViewTestBase {
private SWTBotView repoView;
+ private State linkWithSelectionState;
+
+ private Boolean initialLinkingWithSelection;
+
@Before
public void before() throws Exception {
localRepositoryDir = createProjectAndCommitToRepository();
@@ -92,14 +101,19 @@ public class SelectionForViewsTest extends GitRepositoriesViewTestBase {
repoUtil.addConfiguredRepository(localRepositoryDir);
repoUtil.addConfiguredRepository(clonedRepositoryDir);
repoUtil.addConfiguredRepository(remoteRepositoryDir); // it's bare
+ ICommandService srv = CommonUtils.getService(PlatformUI.getWorkbench(),
+ ICommandService.class);
+ linkWithSelectionState = srv
+ .getCommand(ToggleLinkWithSelectionCommand.ID)
+ .getState(RegistryToggleState.STATE_ID);
+ initialLinkingWithSelection = (Boolean) linkWithSelectionState
+ .getValue();
+ linkWithSelectionState.setValue(Boolean.TRUE);
stagingView = TestUtil.showView(StagingView.VIEW_ID);
reflogView = TestUtil.showView(ReflogView.VIEW_ID);
rebaseInteractiveView = TestUtil
.showView(RebaseInteractiveView.VIEW_ID);
repoView = TestUtil.showView(RepositoriesView.VIEW_ID);
- RepositoriesView repos = (RepositoriesView) repoView.getViewReference()
- .getView(false);
- repos.setReactOnSelection(true);
historyView = TestUtil.showHistoryView();
IHistoryView history = (IHistoryView) historyView.getViewReference()
.getView(false);
@@ -122,9 +136,7 @@ public class SelectionForViewsTest extends GitRepositoriesViewTestBase {
@After
public void after() {
- RepositoriesView repos = (RepositoriesView) repoView.getViewReference()
- .getView(false);
- repos.setReactOnSelection(false);
+ linkWithSelectionState.setValue(initialLinkingWithSelection);
IHistoryView history = (IHistoryView) historyView.getViewReference()
.getView(false);
((GenericHistoryView) history).setLinkingEnabled(false);
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/submodules/SubmoduleFolderTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/submodules/SubmoduleFolderTest.java
index 14b4c3309..bf7e051cd 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/submodules/SubmoduleFolderTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/submodules/SubmoduleFolderTest.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.Collections;
+import org.eclipse.core.commands.State;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
@@ -40,10 +41,12 @@ import org.eclipse.egit.core.project.GitProjectData;
import org.eclipse.egit.core.project.RepositoryMapping;
import org.eclipse.egit.core.test.TestRepository;
import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
+import org.eclipse.egit.ui.internal.CommonUtils;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.clone.ProjectRecord;
import org.eclipse.egit.ui.internal.clone.ProjectUtils;
import org.eclipse.egit.ui.internal.repository.RepositoriesView;
+import org.eclipse.egit.ui.internal.repository.tree.command.ToggleLinkWithSelectionCommand;
import org.eclipse.egit.ui.internal.resources.IResourceState;
import org.eclipse.egit.ui.internal.resources.ResourceStateFactory;
import org.eclipse.egit.ui.test.ContextMenuHelper;
@@ -62,6 +65,9 @@ import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.RegistryToggleState;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.junit.After;
@@ -78,8 +84,6 @@ public class SubmoduleFolderTest extends LocalRepositoryTestCase {
private static final String CHILDPROJECT = "ChildProject";
- private static final TestUtil UTIL = new TestUtil();
-
private Repository parentRepository;
private Repository childRepository;
@@ -260,11 +264,14 @@ public class SubmoduleFolderTest extends LocalRepositoryTestCase {
@Test
public void testRepoViewFollowSelection() throws Exception {
+ ICommandService srv = CommonUtils.getService(PlatformUI.getWorkbench(),
+ ICommandService.class);
+ State commandState = srv.getCommand(ToggleLinkWithSelectionCommand.ID)
+ .getState(RegistryToggleState.STATE_ID);
+ Boolean followsSelection = (Boolean) commandState.getValue();
+ commandState.setValue(Boolean.TRUE);
SWTBotView view = TestUtil.showView(RepositoriesView.VIEW_ID);
TestUtil.joinJobs(REPO_VIEW_REFRESH);
- view.toolbarButton(
- UTIL.getPluginLocalizedValue("LinkWithSelectionCommand"))
- .click();
try {
SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
SWTBotTreeItem node = TestUtil.navigateTo(projectExplorerTree,
@@ -299,9 +306,7 @@ public class SubmoduleFolderTest extends LocalRepositoryTestCase {
parentFound[0]);
} finally {
// Reset "follow selection"
- view.toolbarButton(
- UTIL.getPluginLocalizedValue("LinkWithSelectionCommand"))
- .click();
+ commandState.setValue(followsSelection);
}
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/history/HistoryViewTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/history/HistoryViewTest.java
index 994286b55..58db11f58 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/history/HistoryViewTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/history/HistoryViewTest.java
@@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.egit.ui.test.history;
+import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withRegex;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@@ -29,6 +30,7 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Adapters;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.egit.core.RepositoryUtil;
+import org.eclipse.egit.gitflow.op.InitOperation;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.JobFamilies;
import org.eclipse.egit.ui.internal.UIText;
@@ -43,6 +45,7 @@ import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
@@ -493,6 +496,22 @@ public class HistoryViewTest extends GitRepositoriesViewTestBase {
}
@Test
+ public void testStartGitflowReleaseEnabled() throws Exception {
+ Repository repository = lookupRepository(repoFile);
+ new InitOperation(repository).execute(null);
+
+ final SWTBotTable table = getHistoryViewTable(PROJ1);
+ table.getTableItem(1).select();
+
+ String itemLabelRegex = NLS.bind(org.eclipse.egit.gitflow.ui.internal.
+ UIText.DynamicHistoryMenu_startGitflowReleaseFrom, ".*");
+ SWTBotMenu startReleaseMenu = table.contextMenu().menu(withRegex(itemLabelRegex),
+ true, 0);
+
+ assertTrue(startReleaseMenu.isEnabled());
+ }
+
+ @Test
@Ignore
public void testRebaseAlreadyUpToDate() throws Exception {
Repository repo = lookupRepository(repoFile);
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/JavaCompareTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/JavaCompareTest.java
new file mode 100644
index 000000000..17bca46f0
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/JavaCompareTest.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (C) 2019, Thomas Wolf <thomas.wolf@paranor.ch>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************/
+package org.eclipse.egit.ui.test.team.actions;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UncheckedIOException;
+import java.nio.charset.StandardCharsets;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.egit.core.JobFamilies;
+import org.eclipse.egit.ui.common.CompareEditorTester;
+import org.eclipse.egit.ui.common.JavaProjectTester;
+import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
+import org.eclipse.egit.ui.common.StagingViewTester;
+import org.eclipse.egit.ui.test.TestUtil;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class JavaCompareTest extends LocalRepositoryTestCase {
+
+ private static boolean initialAutobuild;
+
+ private IJavaProject javaProject = null;
+
+ private JavaProjectTester javaTestHelper;
+
+ @BeforeClass
+ public static void setupAutobuildOff() throws CoreException {
+ // Switch off autobuild -- we don't need it, and a build job might
+ // interfere with our removing the Java project at the end.
+ initialAutobuild = JavaProjectTester.setAutobuild(false);
+ }
+
+ @AfterClass
+ public static void teardownAutobuildReset() throws CoreException {
+ JavaProjectTester.setAutobuild(initialAutobuild);
+ }
+
+ @Before
+ public void setup() throws Exception {
+ javaTestHelper = new JavaProjectTester(this);
+ javaProject = javaTestHelper.createJavaProjectAndCommitToRepository();
+ }
+
+ @After
+ public void teardown() throws CoreException {
+ javaTestHelper.removeJavaProject(javaProject);
+ }
+
+ @Test
+ public void testJavaCompareWithIndex() throws Exception {
+ IProject project = javaProject.getProject();
+ IFile file = project.getFolder(JavaProjectTester.SRC_FOLDER_NAME)
+ .getFolder(JavaProjectTester.PACKAGE_NAME)
+ .getFile(JavaProjectTester.JAVA_FILE_NAME);
+ String newContent = JavaProjectTester.INITIAL_FILE_CONTENT
+ + "\n// Comment\n";
+ ResourcesPlugin.getWorkspace().run(monitor -> {
+ try (InputStream s = new ByteArrayInputStream(
+ newContent.getBytes(StandardCharsets.UTF_8))) {
+ file.setContents(s, IResource.FORCE, monitor);
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }, file, IResource.NONE, null);
+ TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
+ // Select the project to ensure the staging view does have a repo.
+ SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
+ getProjectItem(projectExplorerTree, project.getName()).select();
+ StagingViewTester stagingViewTester = StagingViewTester
+ .openStagingView();
+ stagingViewTester.compareWithIndex(JavaProjectTester.JAVA_FILE_PATH);
+ CompareEditorTester editor = CompareEditorTester
+ .forTitleContaining(JavaProjectTester.JAVA_FILE_NAME);
+ String actualContent = editor.getLeftEditor().getText();
+ boolean isDirty = editor.isDirty();
+ if (isDirty) {
+ editor.save();
+ }
+ editor.close();
+ assertEquals(newContent, actualContent);
+ assertFalse(isDirty);
+ }
+}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/MergeToolTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/MergeToolTest.java
index 55a1cb612..35f2a3487 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/MergeToolTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/MergeToolTest.java
@@ -22,6 +22,7 @@ import org.eclipse.egit.core.Activator;
import org.eclipse.egit.core.JobFamilies;
import org.eclipse.egit.core.internal.indexdiff.IndexDiffCache;
import org.eclipse.egit.core.op.MergeOperation;
+import org.eclipse.egit.ui.UIPreferences;
import org.eclipse.egit.ui.common.CompareEditorTester;
import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
import org.eclipse.egit.ui.test.ContextMenuHelper;
@@ -32,6 +33,7 @@ import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -42,16 +44,28 @@ public class MergeToolTest extends LocalRepositoryTestCase {
private TestRepository testRepository;
+ private int mergeMode;
+
@Before
public void setUp() throws Exception {
File repositoryFile = createProjectAndCommitToRepository();
Repository repository = lookupRepository(repositoryFile);
- testRepository = new TestRepository<Repository>(repository);
+ testRepository = new TestRepository<>(repository);
+ mergeMode = org.eclipse.egit.ui.Activator.getDefault()
+ .getPreferenceStore().getInt(UIPreferences.MERGE_MODE);
+ }
+
+ @After
+ public void resetMergeMode() throws Exception {
+ org.eclipse.egit.ui.Activator.getDefault().getPreferenceStore()
+ .setValue(UIPreferences.MERGE_MODE, mergeMode);
}
@Test
public void useHeadOptionShouldCauseFileToNotHaveConflictMarkers()
throws Exception {
+ org.eclipse.egit.ui.Activator.getDefault().getPreferenceStore()
+ .setValue(UIPreferences.MERGE_MODE, 2);
IPath path = new Path(PROJ1).append("folder/test.txt");
testRepository.branch("stable").commit().add(path.toString(), "stable")
.create();
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/ShowBlameActionHandlerTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/ShowBlameActionHandlerTest.java
index 1844ae4a9..a80fe57c0 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/ShowBlameActionHandlerTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/ShowBlameActionHandlerTest.java
@@ -16,42 +16,19 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.IWorkspaceDescription;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.IWorkspaceRunnable;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.egit.core.Activator;
-import org.eclipse.egit.core.internal.indexdiff.IndexDiffCache;
-import org.eclipse.egit.core.op.CommitOperation;
-import org.eclipse.egit.core.op.ConnectProviderOperation;
+import org.eclipse.egit.ui.common.JavaProjectTester;
import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
import org.eclipse.egit.ui.internal.actions.ShowBlameActionHandler;
-import org.eclipse.egit.ui.test.TestUtil;
-import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.IPackageFragment;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jgit.lib.Repository;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -73,54 +50,42 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class ShowBlameActionHandlerTest extends LocalRepositoryTestCase {
- private static final String JAVA_PROJECT_NAME = "javatestProject";
-
- private static final String SRC_FOLDER_NAME = "src";
-
- private static final String BIN_FOLDER_NAME = "bin";
-
- private static final String PACKAGE_NAME = "p";
-
- private static final String JAVA_CLASS_NAME = "A";
-
- private static final String JAVA_FILE_NAME = JAVA_CLASS_NAME + ".java";
-
- private static final int MAX_DELETE_RETRY = 5;
-
- private static final int DELETE_RETRY_DELAY = 1000; // ms
-
private static boolean initialAutobuild;
private IJavaProject javaProject = null;
+ private JavaProjectTester javaTestHelper;
+
@BeforeClass
public static void setupAutobuildOff() throws CoreException {
// Switch off autobuild -- we don't need it, and a build job might
// interfere with our removing the Java project at the end.
- initialAutobuild = setAutobuild(false);
+ initialAutobuild = JavaProjectTester.setAutobuild(false);
}
@AfterClass
public static void teardownAutobuildReset() throws CoreException {
- setAutobuild(initialAutobuild);
+ JavaProjectTester.setAutobuild(initialAutobuild);
}
@Before
public void setup() throws Exception {
- javaProject = createJavaProjectAndCommitToRepository();
+ javaTestHelper = new JavaProjectTester(this);
+ javaProject = javaTestHelper.createJavaProjectAndCommitToRepository();
}
@After
public void teardown() throws CoreException {
- removeJavaProject();
+ javaTestHelper.removeJavaProject(javaProject);
}
@Test
public void testShowAnnotationsFromProjectExplorer() throws Exception {
IProject project = javaProject.getProject();
// Find the file
- IFile file = project.getFolder(SRC_FOLDER_NAME).getFolder(PACKAGE_NAME)
- .getFile(JAVA_FILE_NAME);
+ IFile file = project.getFolder(JavaProjectTester.SRC_FOLDER_NAME)
+ .getFolder(JavaProjectTester.PACKAGE_NAME)
+ .getFile(JavaProjectTester.JAVA_FILE_NAME);
assertBlameEnabled(file, true);
// Now repeat the same with the ICompilationUnit.
IJavaElement element = JavaCore.create(file, javaProject);
@@ -128,7 +93,8 @@ public class ShowBlameActionHandlerTest extends LocalRepositoryTestCase {
element instanceof ICompilationUnit);
assertBlameEnabled(element, true);
// And with IType...
- IType type = javaProject.findType(PACKAGE_NAME, JAVA_CLASS_NAME);
+ IType type = javaProject.findType(JavaProjectTester.PACKAGE_NAME,
+ JavaProjectTester.JAVA_CLASS_NAME);
assertBlameEnabled(type, true);
// ... and finally with something that doesn't adapt to IResource:
assertBlameEnabled(this, false);
@@ -146,160 +112,4 @@ public class ShowBlameActionHandlerTest extends LocalRepositoryTestCase {
blame.isEnabled());
}
- // Java stuff below
-
- private static boolean setAutobuild(boolean value) throws CoreException {
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- IWorkspaceDescription desc = workspace.getDescription();
- boolean isAutoBuilding = desc.isAutoBuilding();
- if (isAutoBuilding != value) {
- desc.setAutoBuilding(value);
- workspace.setDescription(desc);
- }
- return isAutoBuilding;
- }
-
- private IJavaProject createJavaProjectAndCommitToRepository()
- throws Exception {
- Repository myRepository = createLocalTestRepository(REPO1);
- File gitDir = myRepository.getDirectory();
- IJavaProject jProject = createJavaProject(myRepository,
- JAVA_PROJECT_NAME);
- IProject project = jProject.getProject();
- try {
- new ConnectProviderOperation(project, gitDir).execute(null);
- } catch (Exception e) {
- Activator.logError("Failed to connect project to repository", e);
- }
- assertConnected(project);
- // Check in at least the java file
- IFolder folder = project.getFolder(SRC_FOLDER_NAME)
- .getFolder(PACKAGE_NAME);
- IFile file = folder.getFile(JAVA_FILE_NAME);
-
- IFile[] commitables = new IFile[] { file };
- ArrayList<IFile> untracked = new ArrayList<IFile>();
- untracked.addAll(Arrays.asList(commitables));
- // commit to master
- CommitOperation op = new CommitOperation(commitables, untracked,
- TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Initial commit");
- op.execute(null);
-
- // Make sure cache entry is already listening for changes
- IndexDiffCache cache = Activator.getDefault().getIndexDiffCache();
- cache.getIndexDiffCacheEntry(lookupRepository(gitDir));
- return jProject;
- }
-
- private IJavaProject createJavaProject(final Repository repository,
- final String projectName) throws Exception {
- final IJavaProject[] jProjectHolder = new IJavaProject[] { null };
- IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
- @Override
- public void run(IProgressMonitor monitor) throws CoreException {
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- IProject project = root.getProject(projectName);
- if (project.exists()) {
- project.delete(true, null);
- TestUtil.waitForJobs(100, 5000);
- }
- IProjectDescription desc = ResourcesPlugin.getWorkspace()
- .newProjectDescription(projectName);
- desc.setLocation(
- new Path(new File(repository.getWorkTree(), projectName)
- .getPath()));
- project.create(desc, null);
- project.open(null);
- TestUtil.waitForJobs(50, 5000);
- // Create a "bin" folder
- IFolder bin = project.getFolder(BIN_FOLDER_NAME);
- if (!bin.exists()) {
- bin.create(IResource.FORCE | IResource.DERIVED, true, null);
- }
- IPath outputLocation = bin.getFullPath();
- // Create a "src" folder
- IFolder src = project.getFolder(SRC_FOLDER_NAME);
- if (!src.exists()) {
- src.create(IResource.FORCE, true, null);
- }
- addNatureToProject(project, JavaCore.NATURE_ID);
- // Set up the IJavaProject
- IJavaProject jProject = JavaCore.create(project);
- IPackageFragmentRoot srcContainer = jProject
- .getPackageFragmentRoot(src);
- IClasspathEntry srcEntry = JavaCore
- .newSourceEntry(srcContainer.getPath());
- // Create a JRE classpath entry using the default JRE
- IClasspathEntry jreEntry = JavaRuntime
- .getDefaultJREContainerEntry();
- jProject.setRawClasspath(
- new IClasspathEntry[] { srcEntry, jreEntry },
- outputLocation, true, null);
- // Create a package with a single test class
- IPackageFragment javaPackage = srcContainer
- .createPackageFragment(PACKAGE_NAME, true, null);
- javaPackage
- .createCompilationUnit(JAVA_FILE_NAME,
- "package " + PACKAGE_NAME + ";\nclass "
- + JAVA_CLASS_NAME + " {\n\n}",
- true, null);
- jProjectHolder[0] = jProject;
- }
- };
- ResourcesPlugin.getWorkspace().run(runnable, null);
- return jProjectHolder[0];
- }
-
- private void addNatureToProject(IProject proj, String natureId)
- throws CoreException {
- IProjectDescription description = proj.getDescription();
- String[] prevNatures = description.getNatureIds();
- String[] newNatures = new String[prevNatures.length + 1];
- System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
- newNatures[prevNatures.length] = natureId;
- description.setNatureIds(newNatures);
- proj.setDescription(description, null);
- }
-
- private void removeJavaProject() throws CoreException {
- if (javaProject == null) {
- return;
- }
- final IProject project = javaProject.getProject();
- IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
- @Override
- public void run(IProgressMonitor monitor) throws CoreException {
- // Following code inspired by {@link
- // org.eclipse.jdt.testplugin.JavaProjectHelper#delete(IResource)}.
- // I don't like all this sleeping at all, but apparently it's
- // needed because the Java indexer might still run and hold on
- // to some resources.
- for (int i = 0; i < MAX_DELETE_RETRY; i++) {
- try {
- project.delete(
- IResource.FORCE
- | IResource.ALWAYS_DELETE_PROJECT_CONTENT,
- null);
- break;
- } catch (CoreException e) {
- if (i == MAX_DELETE_RETRY - 1) {
- throw e;
- }
- try {
- Activator.logInfo(
- "Sleep before retrying to delete project "
- + project.getLocationURI());
- // Give other threads the time to close and release
- // the resource.
- Thread.sleep(DELETE_RETRY_DELAY);
- } catch (InterruptedException e1) {
- // Ignore and retry to delete
- }
- }
- }
-
- }
- };
- ResourcesPlugin.getWorkspace().run(runnable, null);
- }
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewBranchHandlingTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewBranchHandlingTest.java
index 7fb833101..27c32d70b 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewBranchHandlingTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewBranchHandlingTest.java
@@ -62,6 +62,7 @@ import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.RegistryToggleState;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -378,7 +379,7 @@ public class GitRepositoriesViewBranchHandlingTest extends
ICommandService srv = CommonUtils.getService(PlatformUI.getWorkbench(),
ICommandService.class);
State commandState = srv.getCommand(ToggleBranchHierarchyCommand.ID)
- .getState(ToggleBranchHierarchyCommand.TOGGLE_STATE);
+ .getState(RegistryToggleState.STATE_ID);
Boolean isHierarchical = (Boolean) commandState.getValue();
commandState.setValue(Boolean.TRUE);
try {
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java
index 15dcbe6ca..1a62755ae 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java
@@ -65,6 +65,7 @@ import org.eclipse.ui.internal.dialogs.WorkbenchWizardElement;
import org.eclipse.ui.internal.wizards.AbstractExtensionWizardRegistry;
import org.eclipse.ui.wizards.IWizardCategory;
import org.eclipse.ui.wizards.IWizardDescriptor;
+import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -90,14 +91,22 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
private File repositoryFile;
+ private boolean initialLinkingState;
+
@Before
- public void beforeClass() throws Exception {
+ public void prepare() throws Exception {
setVerboseBranchMode(false);
+ initialLinkingState = setLinkWithSelection(false);
repositoryFile = createProjectAndCommitToRepository();
Activator.getDefault().getRepositoryUtil()
.addConfiguredRepository(repositoryFile);
}
+ @After
+ public void resetLinkingState() {
+ setLinkWithSelection(initialLinkingState);
+ }
+
/**
* First level should have 5 children
*
@@ -527,9 +536,6 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
// the selection should be project
assertTrue(tree.selection().get(0, 0).equals(PROJ1));
-
- // deactivate the link with selection
- toggleLinkWithSelection();
}
/**
@@ -869,7 +875,8 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
private void toggleLinkWithSelection() throws Exception {
getOrOpenView().toolbarButton(
- myUtil.getPluginLocalizedValue("LinkWithSelectionCommand"))
+ myUtil.getPluginLocalizedValue(
+ "RepoViewLinkWithSelection.tooltip"))
.click();
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestBase.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestBase.java
index 030550874..4865f8bae 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestBase.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestBase.java
@@ -35,6 +35,7 @@ import org.eclipse.egit.ui.internal.CommonUtils;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.repository.RepositoriesView;
import org.eclipse.egit.ui.internal.repository.tree.command.ToggleBranchCommitCommand;
+import org.eclipse.egit.ui.internal.repository.tree.command.ToggleLinkWithSelectionCommand;
import org.eclipse.egit.ui.test.TestUtil;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
@@ -45,6 +46,7 @@ import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.RegistryToggleState;
import org.junit.After;
import org.junit.Before;
@@ -106,12 +108,23 @@ public abstract class GitRepositoriesViewTestBase extends
protected static void setVerboseBranchMode(boolean state) {
ICommandService srv = CommonUtils.getService(PlatformUI.getWorkbench(),
ICommandService.class);
- State verboseBranchModeState = srv.getCommand(
- ToggleBranchCommitCommand.ID).getState(
- ToggleBranchCommitCommand.TOGGLE_STATE);
+ State verboseBranchModeState = srv
+ .getCommand(ToggleBranchCommitCommand.ID)
+ .getState(RegistryToggleState.STATE_ID);
verboseBranchModeState.setValue(Boolean.valueOf(state));
}
+ protected static boolean setLinkWithSelection(boolean state) {
+ ICommandService srv = CommonUtils.getService(PlatformUI.getWorkbench(),
+ ICommandService.class);
+ State linkingState = srv.getCommand(ToggleLinkWithSelectionCommand.ID)
+ .getState(RegistryToggleState.STATE_ID);
+ boolean previousState = ((Boolean) linkingState.getValue())
+ .booleanValue();
+ linkingState.setValue(Boolean.valueOf(state));
+ return previousState;
+ }
+
protected SWTBotView getOrOpenView() throws Exception {
SWTBotView view = TestUtil.showView(RepositoriesView.VIEW_ID);
TestUtil.joinJobs(JobFamilies.REPO_VIEW_REFRESH);

Back to the top