Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspingel2009-12-08 03:47:39 +0000
committerspingel2009-12-08 03:47:39 +0000
commitf1f16a24f8fc9427d83327aae0d8f12ed73a35c9 (patch)
tree40ee58b5defece33b02be855ff6ede63d7756c62 /org.eclipse.mylyn.tasks.tests
parent983a4790b4c7a5f16f1e86cb0eb659395ed7b3de (diff)
downloadorg.eclipse.mylyn.tasks-f1f16a24f8fc9427d83327aae0d8f12ed73a35c9.tar.gz
org.eclipse.mylyn.tasks-f1f16a24f8fc9427d83327aae0d8f12ed73a35c9.tar.xz
org.eclipse.mylyn.tasks-f1f16a24f8fc9427d83327aae0d8f12ed73a35c9.zip
NEW - bug 296763: content assist pastes bug prefix twice
https://bugs.eclipse.org/bugs/show_bug.cgi?id=296763
Diffstat (limited to 'org.eclipse.mylyn.tasks.tests')
-rw-r--r--org.eclipse.mylyn.tasks.tests/.settings/.api_filters14
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java2
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/MockTextViewer.java45
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/TaskHyperlinkDetectorTest.java10
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/RepositoryCompletionProcessorTest.java124
5 files changed, 183 insertions, 12 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/.settings/.api_filters b/org.eclipse.mylyn.tasks.tests/.settings/.api_filters
index e90b8b192..5a385dac6 100644
--- a/org.eclipse.mylyn.tasks.tests/.settings/.api_filters
+++ b/org.eclipse.mylyn.tasks.tests/.settings/.api_filters
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.mylyn.tasks.tests" version="2">
- <resource path="src/org/eclipse/mylyn/tasks/tests/ui/editor/TaskUrlHyperlinkDetectorTest.java" type="org.eclipse.mylyn.tasks.tests.ui.editor.TaskUrlHyperlinkDetectorTest">
- <filter id="571519004">
+ <resource path="src/org/eclipse/mylyn/tasks/tests/ui/MockTextViewer.java" type="org.eclipse.mylyn.tasks.tests.ui.MockTextViewer">
+ <filter id="571473929">
<message_arguments>
- <message_argument value="org.eclipse.mylyn.tasks.tests.ui.editor.TaskUrlHyperlinkDetectorTest.detect(String, int, int)"/>
<message_argument value="TextViewer"/>
+ <message_argument value="MockTextViewer"/>
</message_arguments>
</filter>
</resource>
@@ -16,4 +16,12 @@
</message_arguments>
</filter>
</resource>
+ <resource path="src/org/eclipse/mylyn/tasks/tests/ui/editor/TaskUrlHyperlinkDetectorTest.java" type="org.eclipse.mylyn.tasks.tests.ui.editor.TaskUrlHyperlinkDetectorTest">
+ <filter id="571519004">
+ <message_arguments>
+ <message_argument value="org.eclipse.mylyn.tasks.tests.ui.editor.TaskUrlHyperlinkDetectorTest.detect(String, int, int)"/>
+ <message_argument value="TextViewer"/>
+ </message_arguments>
+ </filter>
+ </resource>
</component>
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java
index f292221c6..6201a8801 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java
@@ -26,6 +26,7 @@ import org.eclipse.mylyn.tasks.tests.ui.TaskListSynchronizationSchedulerTest;
import org.eclipse.mylyn.tasks.tests.ui.TaskRelationHyperlinkDetectorTest;
import org.eclipse.mylyn.tasks.tests.ui.editor.EditorUtilTest;
import org.eclipse.mylyn.tasks.tests.ui.editor.PlanningPartTest;
+import org.eclipse.mylyn.tasks.tests.ui.editor.RepositoryCompletionProcessorTest;
import org.eclipse.mylyn.tasks.tests.ui.editor.TaskEditorPartDescriptorTest;
import org.eclipse.mylyn.tasks.tests.ui.editor.TaskUrlHyperlinkDetectorTest;
@@ -96,6 +97,7 @@ public class AllTasksTests {
suite.addTestSuite(FileTaskAttachmentSourceTest.class);
suite.addTestSuite(TaskListSynchronizationSchedulerTest.class);
suite.addTestSuite(PlanningPartTest.class);
+ suite.addTestSuite(RepositoryCompletionProcessorTest.class);
// XXX long running tests, put back?
//suite.addTestSuite(TaskDataImportTest.class);
//suite.addTestSuite(QueryExportImportTest.class);
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/MockTextViewer.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/MockTextViewer.java
new file mode 100644
index 000000000..4b634c9d2
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/MockTextViewer.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Tasktop Technologies 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
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.tasks.tests.ui;
+
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TextViewer;
+
+/**
+ * @author Steffen Pingel
+ */
+public class MockTextViewer extends TextViewer {
+
+ private String text;
+
+ public MockTextViewer() {
+ }
+
+ public MockTextViewer(String text) {
+ this.text = text;
+ }
+
+ @Override
+ public IDocument getDocument() {
+ return new Document(text);
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/TaskHyperlinkDetectorTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/TaskHyperlinkDetectorTest.java
index 0666da543..74423c8a7 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/TaskHyperlinkDetectorTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/TaskHyperlinkDetectorTest.java
@@ -13,11 +13,8 @@ package org.eclipse.mylyn.tasks.tests.ui;
import junit.framework.TestCase;
-import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.mylyn.internal.tasks.ui.editors.TaskHyperlinkDetector;
import org.eclipse.mylyn.tasks.core.TaskRepository;
@@ -43,12 +40,7 @@ public class TaskHyperlinkDetectorTest extends TestCase {
protected IHyperlink[] detect(final String text, int start, int length) {
AbstractTaskHyperlinkDetector detector = createHyperlinkDetector();
- return detector.detectHyperlinks(new TextViewer() {
- @Override
- public IDocument getDocument() {
- return new Document(text);
- }
- }, new Region(start, length), true);
+ return detector.detectHyperlinks(new MockTextViewer(text), new Region(start, length), true);
}
protected AbstractTaskHyperlinkDetector createHyperlinkDetector() {
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/RepositoryCompletionProcessorTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/RepositoryCompletionProcessorTest.java
new file mode 100644
index 000000000..606ab82bf
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/RepositoryCompletionProcessorTest.java
@@ -0,0 +1,124 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Tasktop Technologies 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
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.tasks.tests.ui.editor;
+
+import junit.framework.TestCase;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.mylyn.internal.tasks.core.TaskTask;
+import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
+import org.eclipse.mylyn.internal.tasks.ui.editors.RepositoryCompletionProcessor;
+import org.eclipse.mylyn.internal.tasks.ui.editors.RepositoryCompletionProcessor.TaskCompletionProposal;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.tests.TaskTestUtil;
+import org.eclipse.mylyn.tasks.tests.ui.MockTextViewer;
+import org.eclipse.swt.graphics.Point;
+
+/**
+ * @author Steffen Pingel
+ */
+public class RepositoryCompletionProcessorTest extends TestCase {
+
+ private TaskRepository repository;
+
+ @Override
+ protected void setUp() throws Exception {
+ TaskTestUtil.resetTaskListAndRepositories();
+ repository = TaskTestUtil.createMockRepository();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ TaskTestUtil.resetTaskListAndRepositories();
+ }
+
+ public void testComputeCompletionProposals() {
+ TaskTask taskFoo = addTask("1", "foo");
+ TaskTask taskBar = addTask("2", "bar");
+
+ RepositoryCompletionProcessor processor = new RepositoryCompletionProcessor(repository);
+ ICompletionProposal[] proposals = processor.computeCompletionProposals(new MockTextViewer(""), 0);
+ assertEquals(2, proposals.length);
+ assertEquals(taskFoo, ((TaskCompletionProposal) proposals[0]).getTask());
+ assertEquals(taskBar, ((TaskCompletionProposal) proposals[1]).getTask());
+
+ proposals = processor.computeCompletionProposals(new MockTextViewer("abc"), 1);
+ assertEquals(0, proposals.length);
+
+ }
+
+ public void testComputeCompletionProposalsPrefix() {
+ TaskTask taskFoo = addTask("1", "foo");
+ TaskTask taskBar = addTask("2", "bar");
+
+ RepositoryCompletionProcessor processor = new RepositoryCompletionProcessor(repository);
+ MockTextViewer viewer = new MockTextViewer("task");
+ ICompletionProposal[] proposals = processor.computeCompletionProposals(viewer, 4);
+ assertEquals(2, proposals.length);
+ TaskCompletionProposal proposal = (TaskCompletionProposal) proposals[0];
+ assertEquals(taskFoo, proposal.getTask());
+ assertEquals(taskBar, ((TaskCompletionProposal) proposals[1]).getTask());
+ assertEquals("task 1", proposal.getReplacement());
+
+ IDocument doc = viewer.getDocument();
+ proposal.apply(doc);
+ assertEquals("task 1", doc.get());
+ assertEquals(new Point(6, 0), proposal.getSelection(doc));
+ }
+
+ public void testComputeCompletionProposalsPrefixSpace() {
+ TaskTask taskFoo = addTask("1", "foo");
+ TaskTask taskBar = addTask("2", "bar");
+
+ RepositoryCompletionProcessor processor = new RepositoryCompletionProcessor(repository);
+ MockTextViewer viewer = new MockTextViewer("task ");
+ ICompletionProposal[] proposals = processor.computeCompletionProposals(viewer, 5);
+ assertEquals(2, proposals.length);
+ TaskCompletionProposal proposal = (TaskCompletionProposal) proposals[0];
+ assertEquals(taskFoo, proposal.getTask());
+ assertEquals(taskBar, ((TaskCompletionProposal) proposals[1]).getTask());
+ assertEquals("task 1", proposal.getReplacement());
+
+ IDocument doc = viewer.getDocument();
+ proposal.apply(doc);
+ assertEquals("task 1", doc.get());
+ assertEquals(new Point(6, 0), proposal.getSelection(doc));
+ }
+
+ public void testComputeCompletionProposalsParenthesis() {
+ TaskTask taskFoo = addTask("1", "foo");
+ TaskTask taskBar = addTask("2", "bar");
+
+ RepositoryCompletionProcessor processor = new RepositoryCompletionProcessor(repository);
+ MockTextViewer viewer = new MockTextViewer("(task");
+ ICompletionProposal[] proposals = processor.computeCompletionProposals(viewer, 5);
+ assertEquals(2, proposals.length);
+ TaskCompletionProposal proposal = (TaskCompletionProposal) proposals[0];
+ assertEquals(taskFoo, proposal.getTask());
+ assertEquals(taskBar, ((TaskCompletionProposal) proposals[1]).getTask());
+ assertEquals("task 1", proposal.getReplacement());
+
+ IDocument doc = viewer.getDocument();
+ proposal.apply(doc);
+ assertEquals("(task 1", doc.get());
+ assertEquals(new Point(7, 0), proposal.getSelection(doc));
+ }
+
+ private TaskTask addTask(String taskId, String summary) {
+ TaskTask task = TaskTestUtil.createMockTask(taskId);
+ task.setSummary(summary);
+ TasksUiPlugin.getTaskList().addTask(task);
+ return task;
+ }
+
+}

Back to the top