Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Rademacher2017-05-22 02:52:05 -0400
committerMatthias Sohn2017-06-25 18:09:35 -0400
commitec811c09c1b533717a6f4fa790585c9a63479a9b (patch)
tree1072a8ac0e1d4d6ed96cd055367adfc99988de03 /org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test
parentba2cc369e1c6d3063ca944328848508472f895ca (diff)
downloadegit-ec811c09c1b533717a6f4fa790585c9a63479a9b.tar.gz
egit-ec811c09c1b533717a6f4fa790585c9a63479a9b.tar.xz
egit-ec811c09c1b533717a6f4fa790585c9a63479a9b.zip
Add ICommitMessageProvider2 for caret positioning in commit messages
The caret in the CommitMessageComponent is placed according to the value of getDesiredCaretPosition() of the first implementation of ICommitMessageProvider2 that provides caret position. In case there are multiple implementations available that provide a defined caret position the second and subsequent positions are ignored. Commit messages are not trimmed anymore to ensure consistency between a provided message and the provided caret position. Includes unit and UI tests. CQ: 13790 Bug: 516867 Change-Id: I1b0ffd33ef37196d53077d09774672c2b033835f Signed-off-by: Stefan Rademacher <stefan.rademacher@tk.de> Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test')
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/AbstractStagingViewTestCase.java69
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/CommitMessageProvidersTest.java123
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/StagingViewTest.java55
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/TestCommitMessageProviderExtensionFactory.java68
4 files changed, 261 insertions, 54 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/AbstractStagingViewTestCase.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/AbstractStagingViewTestCase.java
new file mode 100644
index 000000000..519951d75
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/AbstractStagingViewTestCase.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (C) 2017 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 v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.ui.test.stagview;
+
+import java.io.File;
+
+import org.eclipse.egit.core.JobFamilies;
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
+import org.eclipse.egit.ui.internal.repository.RepositoriesView;
+import org.eclipse.egit.ui.internal.staging.StagingView;
+import org.eclipse.egit.ui.test.TestUtil;
+import org.eclipse.egit.ui.view.repositories.GitRepositoriesViewTestUtils;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.junit.After;
+import org.junit.Before;
+
+public abstract class AbstractStagingViewTestCase
+ extends LocalRepositoryTestCase {
+
+ protected static final GitRepositoriesViewTestUtils repoViewUtil = new GitRepositoriesViewTestUtils();
+
+ protected File repositoryFile;
+
+ protected Repository repository;
+
+ @Before
+ public void before() throws Exception {
+ repositoryFile = createProjectAndCommitToRepository();
+ repository = lookupRepository(repositoryFile);
+ TestUtil.configureTestCommitterAsUser(repository);
+ Activator.getDefault().getRepositoryUtil()
+ .addConfiguredRepository(repositoryFile);
+
+ selectRepositoryNode();
+ }
+
+ @After
+ public void after() {
+ TestUtil.hideView(RepositoriesView.VIEW_ID);
+ TestUtil.hideView(StagingView.VIEW_ID);
+ Activator.getDefault().getRepositoryUtil().removeDir(repositoryFile);
+ }
+
+ protected void setContent(String content) throws Exception {
+ setTestFileContent(content);
+ TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
+ }
+
+ protected void selectRepositoryNode() throws Exception {
+ SWTBotView repositoriesView = TestUtil
+ .showView(RepositoriesView.VIEW_ID);
+ SWTBotTree tree = repositoriesView.bot().tree();
+
+ SWTBotTreeItem repoNode = repoViewUtil.getRootItem(tree,
+ repositoryFile);
+ repoNode.select();
+ }
+
+}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/CommitMessageProvidersTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/CommitMessageProvidersTest.java
new file mode 100644
index 000000000..6f7760b6a
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/CommitMessageProvidersTest.java
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * Copyright (C) 2017, Stefan Rademacher <stefan.rademacher@tk.de> and others.
+ *
+ * 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.stagview;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.egit.ui.CommitMessageWithCaretPosition;
+import org.eclipse.egit.ui.ICommitMessageProvider;
+import org.eclipse.egit.ui.ICommitMessageProvider2;
+import org.eclipse.egit.ui.common.StagingViewTester;
+import org.junit.After;
+import org.junit.Test;
+
+public class CommitMessageProvidersTest extends AbstractStagingViewTestCase {
+
+ @After
+ public void resetCommitMessageProvider() {
+ TestCommitMessageProviderExtensionFactory.INSTANCE.reset();
+ }
+
+ private void assertPosition(int actualPosition, String message) {
+ // Convention: expected position in message is marked by "><"
+ int expectedPosition = message.indexOf("><") + 1;
+ assertEquals("Position mismatch", expectedPosition, actualPosition);
+ }
+
+ @Test
+ public void testCaretPosition() throws Exception {
+ setContent("I have changed this");
+ TestCommitMessageProviderExtensionFactory.INSTANCE
+ .setCommitMessageProviders(new TestCommitMessageProvider(
+ "Caret test\n\nCaret is supposed to be there: ",
+ "\n\nThis is a commit message from testCaretPosition"));
+ StagingViewTester stagingViewTester = StagingViewTester
+ .openStagingView();
+
+ stagingViewTester.stageFile(FILE1_PATH);
+
+ assertPosition(stagingViewTester.getCaretPosition(),
+ stagingViewTester.getCommitMessage());
+ }
+
+ @Test
+ public void testCaretPositionUndefined() throws Exception {
+ setContent("I have changed this");
+ TestCommitMessageProviderExtensionFactory.INSTANCE
+ .setCommitMessageProviders(new ICommitMessageProvider() {
+
+ @Override
+ public String getMessage(IResource[] resources) {
+ return "Commit msg from testCaretPositionUndefined";
+ }
+
+ });
+ StagingViewTester stagingViewTester = StagingViewTester
+ .openStagingView();
+
+ stagingViewTester.stageFile(FILE1_PATH);
+
+ assertPosition(stagingViewTester.getCaretPosition(),
+ stagingViewTester.getCommitMessage());
+ }
+
+ @Test
+ public void testTwoProvidersFromSameExtension() throws Exception {
+ setContent("I have changed this");
+ TestCommitMessageProvider provider1 = new TestCommitMessageProvider(
+ "Caret test\n\nCaret is supposed to be there: ",
+ "\n\nThis is a commit message from testTwoProvidersFromSameExtension");
+
+ TestCommitMessageProvider provider2 = new TestCommitMessageProvider(
+ "Another commit message. \n\nCaret is NOT supposed to be there: ",
+ "\n\nThis is a commit message from testTwoProvidersFromSameExtension");
+ TestCommitMessageProviderExtensionFactory.INSTANCE
+ .setCommitMessageProviders(provider1, provider2);
+
+ StagingViewTester stagingViewTester = StagingViewTester
+ .openStagingView();
+
+ stagingViewTester.stageFile(FILE1_PATH);
+
+ assertPosition(stagingViewTester.getCaretPosition(),
+ stagingViewTester.getCommitMessage());
+
+ assertEquals(
+ provider1.getMessage(null) + "\n\n"
+ + provider2.getMessage(null),
+ stagingViewTester.getCommitMessage());
+ }
+
+ private static class TestCommitMessageProvider
+ implements ICommitMessageProvider2 {
+
+ private String message;
+
+ private int pos;
+
+ public TestCommitMessageProvider(String prefix, String suffix) {
+ message = prefix + "><" + suffix;
+ pos = prefix.length() + 1;
+ }
+
+ @Override
+ public String getMessage(IResource[] resources) {
+ return message;
+ }
+
+ @Override
+ public CommitMessageWithCaretPosition getCommitMessageWithPosition(
+ IResource[] resources) {
+ return new CommitMessageWithCaretPosition(message, pos);
+ }
+
+ }
+
+}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/StagingViewTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/StagingViewTest.java
index 7047e0b8e..5e3905a3f 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/StagingViewTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/StagingViewTest.java
@@ -14,54 +14,16 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import java.io.File;
-
-import org.eclipse.egit.core.JobFamilies;
-import org.eclipse.egit.ui.Activator;
-import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
import org.eclipse.egit.ui.common.StagingViewTester;
-import org.eclipse.egit.ui.internal.repository.RepositoriesView;
-import org.eclipse.egit.ui.internal.staging.StagingView;
import org.eclipse.egit.ui.test.CommitMessageUtil;
import org.eclipse.egit.ui.test.TestUtil;
-import org.eclipse.egit.ui.view.repositories.GitRepositoriesViewTestUtils;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
-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;
-public class StagingViewTest extends LocalRepositoryTestCase {
-
- private static final GitRepositoriesViewTestUtils repoViewUtil = new GitRepositoriesViewTestUtils();
-
- private File repositoryFile;
-
- private Repository repository;
-
- @Before
- public void before() throws Exception {
- repositoryFile = createProjectAndCommitToRepository();
- repository = lookupRepository(repositoryFile);
- TestUtil.configureTestCommitterAsUser(repository);
- Activator.getDefault().getRepositoryUtil()
- .addConfiguredRepository(repositoryFile);
-
- selectRepositoryNode();
- }
-
- @After
- public void after() {
- TestUtil.hideView(RepositoriesView.VIEW_ID);
- TestUtil.hideView(StagingView.VIEW_ID);
- Activator.getDefault().getRepositoryUtil().removeDir(repositoryFile);
- }
+public class StagingViewTest extends AbstractStagingViewTestCase {
@Test
public void testCommitSingleFile() throws Exception {
@@ -154,19 +116,4 @@ public class StagingViewTest extends LocalRepositoryTestCase {
assertTrue(commitMessage.indexOf("Signed-off-by") > 0);
stagingViewTester.commit();
}
-
- private void setContent(String content) throws Exception {
- setTestFileContent(content);
- TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
- }
-
- private void selectRepositoryNode() throws Exception {
- SWTBotView repositoriesView = TestUtil
- .showView(RepositoriesView.VIEW_ID);
- SWTBotTree tree = repositoriesView.bot().tree();
-
- SWTBotTreeItem repoNode = repoViewUtil
- .getRootItem(tree, repositoryFile);
- repoNode.select();
- }
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/TestCommitMessageProviderExtensionFactory.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/TestCommitMessageProviderExtensionFactory.java
new file mode 100644
index 000000000..ada383f12
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/TestCommitMessageProviderExtensionFactory.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (C) 2017 Thomas Wolf <thomas.wolf@paranor.ch> and others
+ *
+ * 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.stagview;
+
+import java.util.LinkedList;
+import java.util.Queue;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IExecutableExtensionFactory;
+import org.eclipse.egit.ui.ICommitMessageProvider;
+
+public class TestCommitMessageProviderExtensionFactory
+ implements IExecutableExtensionFactory {
+
+ // Indirection needed since the extension point may create new factory
+ // instances.
+ protected static final TestCommitMessageProviderFactory INSTANCE = new TestCommitMessageProviderFactory();
+
+ @Override
+ public Object create() throws CoreException {
+ return INSTANCE.create();
+ }
+
+ static class TestCommitMessageProviderFactory
+ implements IExecutableExtensionFactory {
+
+ private Queue<ICommitMessageProvider> providers = new LinkedList<>();
+
+ private final ICommitMessageProvider emptyProvider = new ICommitMessageProvider() {
+ @Override
+ public String getMessage(IResource[] resources) {
+ return "";
+ }
+ };
+
+ @Override
+ public Object create() throws CoreException {
+ if (!providers.isEmpty()) {
+ ICommitMessageProvider p = providers.poll();
+ if (p != null) {
+ return p;
+ }
+ }
+ return emptyProvider;
+ }
+
+ public void reset() { // To be called in @After
+ providers.clear();
+ }
+
+ public void setCommitMessageProviders(
+ ICommitMessageProvider... newProviders) {
+ providers.clear();
+ for (ICommitMessageProvider p : newProviders) {
+ providers.add(p);
+ }
+ }
+
+ }
+
+}

Back to the top