Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrelves2010-05-24 19:33:44 -0400
committerrelves2010-05-24 19:33:44 -0400
commitae7d66e3f5e2f5f622013d283e420a28bb0b994f (patch)
tree9b08cb7ca44e5bafbcabd02d979ed7788fbc4d80 /org.eclipse.mylyn.bugzilla.tests
parent810cc2c254fad8a4c7a3b2ab72af598c16c0c44b (diff)
downloadorg.eclipse.mylyn.tasks-ae7d66e3f5e2f5f622013d283e420a28bb0b994f.tar.gz
org.eclipse.mylyn.tasks-ae7d66e3f5e2f5f622013d283e420a28bb0b994f.tar.xz
org.eclipse.mylyn.tasks-ae7d66e3f5e2f5f622013d283e420a28bb0b994f.zip
NEW - bug 304910: [api] recognize comment#number link on bug editor without bug number too
https://bugs.eclipse.org/bugs/show_bug.cgi?id=304910
Diffstat (limited to 'org.eclipse.mylyn.bugzilla.tests')
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/ui/BugzillaTaskHyperlinkDetectorTest.java304
1 files changed, 235 insertions, 69 deletions
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/ui/BugzillaTaskHyperlinkDetectorTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/ui/BugzillaTaskHyperlinkDetectorTest.java
index 49a2c83dd..f28a29c62 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/ui/BugzillaTaskHyperlinkDetectorTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/ui/BugzillaTaskHyperlinkDetectorTest.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Tasktop Technologies - initial API and implementation
+ * Frank Becker - improvements
*******************************************************************************/
package org.eclipse.mylyn.bugzilla.tests.ui;
@@ -22,15 +23,18 @@ import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin;
import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.internal.tasks.ui.editors.TaskHyperlinkDetector;
+import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.ui.TaskHyperlink;
+import org.eclipse.mylyn.tasks.ui.TasksUi;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
/**
* @author Rob Elves
* @author Terry Hon
+ * @author Frank Becker
*/
public class BugzillaTaskHyperlinkDetectorTest extends TestCase {
@@ -44,73 +48,98 @@ public class BugzillaTaskHyperlinkDetectorTest extends TestCase {
private static final String ATTACHMENT_NEW = "Created attachment" + ATTACHMENT_NUMBER;
- private final String TASK_FORMAT_1 = "task#1";
+ private final String TASK_FORMAT_1 = "task#123";
- private final String TASK_FORMAT_2 = "task# 1";
+ private final String TASK_FORMAT_2 = "task# 123";
- private final String TASK_FORMAT_3 = "task1";
+ private final String TASK_FORMAT_3 = "task123";
- private final String TASK_FORMAT_4 = "task #1";
+ private final String TASK_FORMAT_4 = "task #123";
- private final String BUG_FORMAT_1 = "bug# 1";
+ private final String BUG_FORMAT_1 = "bug# 123";
- private final String BUG_FORMAT_2 = "bug # 1";
+ private final String BUG_FORMAT_2 = "bug # 123";
- private final String BUG_FORMAT_3 = "bug1";
+ private final String BUG_FORMAT_3 = "bug123";
- private final String BUG_FORMAT_4 = "bug #1";
+ private final String BUG_FORMAT_4 = "bug #123";
private final String BUG_FORMAT_1_2 = "bug# 2";
private final String TASK_FORMAT_1_COMMENT_1 = "task#123c#44556677";
- private final String TASK_FORMAT_2_COMMENT_1 = "task# 1c#44556677";
+ private final String TASK_FORMAT_2_COMMENT_1 = "task# 123c#44556677";
- private final String TASK_FORMAT_3_COMMENT_1 = "task1c#44556677";
+ private final String TASK_FORMAT_3_COMMENT_1 = "task123c#44556677";
- private final String TASK_FORMAT_4_COMMENT_1 = "task #1c#44556677";
+ private final String TASK_FORMAT_4_COMMENT_1 = "task #123c#44556677";
- private final String BUG_FORMAT_1_COMMENT_1 = "bug# 1c#44556677";
+ private final String BUG_FORMAT_1_COMMENT_1 = "bug# 123c#44556677";
- private final String BUG_FORMAT_2_COMMENT_1 = "bug # 1c#44556677";
+ private final String BUG_FORMAT_2_COMMENT_1 = "bug # 123c#44556677";
- private final String BUG_FORMAT_3_COMMENT_1 = "bug1c#44556677";
+ private final String BUG_FORMAT_3_COMMENT_1 = "bug123c#44556677";
- private final String BUG_FORMAT_4_COMMENT_1 = "bug #1c#44556677";
+ private final String BUG_FORMAT_4_COMMENT_1 = "bug #123c#44556677";
private final String TASK_FORMAT_1_COMMENT_2 = "task#123 comment #44556677";
- private final String TASK_FORMAT_2_COMMENT_2 = "task# 1 comment #44556677";
+ private final String TASK_FORMAT_2_COMMENT_2 = "task# 123 comment #44556677";
- private final String TASK_FORMAT_3_COMMENT_2 = "task1 comment #44556677";
+ private final String TASK_FORMAT_3_COMMENT_2 = "task123 comment #44556677";
- private final String TASK_FORMAT_4_COMMENT_2 = "task #1 comment #44556677";
+ private final String TASK_FORMAT_4_COMMENT_2 = "task #123 comment #44556677";
- private final String BUG_FORMAT_1_COMMENT_2 = "bug# 1 comment #44556677";
+ private final String BUG_FORMAT_1_COMMENT_2 = "bug# 123 comment #44556677";
- private final String BUG_FORMAT_2_COMMENT_2 = "bug # 1 comment #44556677";
+ private final String BUG_FORMAT_2_COMMENT_2 = "bug # 123 comment #44556677";
- private final String BUG_FORMAT_3_COMMENT_2 = "bug1 comment #44556677";
+ private final String BUG_FORMAT_3_COMMENT_2 = "bug123 comment #44556677";
- private final String BUG_FORMAT_4_COMMENT_2 = "bug #1 comment #44556677";
+ private final String BUG_FORMAT_4_COMMENT_2 = "bug #123 comment #44556677";
private final String TASK_FORMAT_1_COMMENT_3 = "task#123 comment#44556677";
- private final String TASK_FORMAT_2_COMMENT_3 = "task# 1 comment#44556677";
+ private final String TASK_FORMAT_2_COMMENT_3 = "task# 123 comment#44556677";
- private final String TASK_FORMAT_3_COMMENT_3 = "task1 comment#44556677";
+ private final String TASK_FORMAT_3_COMMENT_3 = "task123 comment#44556677";
- private final String TASK_FORMAT_4_COMMENT_3 = "task #1 comment#44556677";
+ private final String TASK_FORMAT_4_COMMENT_3 = "task #123 comment#44556677";
- private final String BUG_FORMAT_1_COMMENT_3 = "bug# 1 comment#44556677";
+ private final String BUG_FORMAT_1_COMMENT_3 = "bug# 123 comment#44556677";
- private final String BUG_FORMAT_2_COMMENT_3 = "bug # 1 comment#44556677";
+ private final String BUG_FORMAT_2_COMMENT_3 = "bug # 123 comment#44556677";
- private final String BUG_FORMAT_3_COMMENT_3 = "bug1 comment#44556677";
+ private final String BUG_FORMAT_3_COMMENT_3 = "bug123 comment#44556677";
- private final String BUG_FORMAT_4_COMMENT_3 = "bug #1 comment#44556677";
+ private final String BUG_FORMAT_4_COMMENT_3 = "bug #123 comment#44556677";
+
+ private final String TASK_FORMAT_1_COMMENT_4 = "task#123 comment # 44556677";
+
+ private final String TASK_FORMAT_2_COMMENT_4 = "task# 123 comment # 44556677";
+
+ private final String TASK_FORMAT_3_COMMENT_4 = "task123 comment # 44556677";
+
+ private final String TASK_FORMAT_4_COMMENT_4 = "task #123 comment # 44556677";
+
+ private final String BUG_FORMAT_1_COMMENT_4 = "bug# 123 comment # 44556677";
+
+ private final String BUG_FORMAT_2_COMMENT_4 = "bug # 123 comment # 44556677";
+
+ private final String BUG_FORMAT_3_COMMENT_4 = "bug123 comment # 44556677";
+
+ private final String BUG_FORMAT_4_COMMENT_4 = "bug #123 comment # 44556677";
+
+ private final String COMMENT_1 = "comment#44556677";
+
+ private final String COMMENT_2 = "comment #44556677";
+
+ private final String COMMENT_3 = "comment # 44556677";
+
+ private final String COMMENT_4 = "comment# 44556677";
+
+ private final String COMMENT_5 = "comment 44556677";
- //private BugzillaTaskHyperlinkDetector detector = new BugzillaTaskHyperlinkDetector();
private TaskHyperlinkDetector detector;
private TaskRepository repository1;
@@ -119,16 +148,20 @@ public class BugzillaTaskHyperlinkDetectorTest extends TestCase {
private TextViewer viewer;
- private String[] formats;
-
private String[] commentFormats;
+ private String[] bugFormats;
+
+ private String[] bugCommentFormats;
+
private TaskRepositoryManager repositoryManager;
private Shell shell;
protected TaskRepository activeRepository;
+ protected ITask task;
+
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -137,11 +170,16 @@ public class BugzillaTaskHyperlinkDetectorTest extends TestCase {
repository1 = new TaskRepository(BugzillaCorePlugin.CONNECTOR_KIND, "repository_url1");
repository2 = new TaskRepository(BugzillaCorePlugin.CONNECTOR_KIND, "repository_url2");
-
+ task = TasksUi.getRepositoryModel().createTask(repository1, "123");
detector.setContext(new IAdaptable() {
@SuppressWarnings("rawtypes")
public Object getAdapter(Class adapter) {
- return (adapter == TaskRepository.class) ? activeRepository : null;
+ if (adapter == TaskRepository.class) {
+ return activeRepository;
+ } else if (adapter == ITask.class) {
+ return task;
+ }
+ return null;
}
});
setRepository(repository1);
@@ -152,15 +190,18 @@ public class BugzillaTaskHyperlinkDetectorTest extends TestCase {
repositoryManager = TasksUiPlugin.getRepositoryManager();
repositoryManager.clearRepositories(TasksUiPlugin.getDefault().getRepositoriesFilePath());
- formats = new String[] { TASK_FORMAT_1, TASK_FORMAT_2, TASK_FORMAT_3, TASK_FORMAT_4, BUG_FORMAT_1,
+ commentFormats = new String[] { COMMENT_1, COMMENT_2, COMMENT_3, COMMENT_4 };
+ bugFormats = new String[] { TASK_FORMAT_1, TASK_FORMAT_2, TASK_FORMAT_3, TASK_FORMAT_4, BUG_FORMAT_1,
BUG_FORMAT_2, BUG_FORMAT_3, BUG_FORMAT_4 };
- commentFormats = new String[] { TASK_FORMAT_1_COMMENT_1, TASK_FORMAT_2_COMMENT_1, TASK_FORMAT_3_COMMENT_1,
+ bugCommentFormats = new String[] { TASK_FORMAT_1_COMMENT_1, TASK_FORMAT_2_COMMENT_1, TASK_FORMAT_3_COMMENT_1,
TASK_FORMAT_4_COMMENT_1, BUG_FORMAT_1_COMMENT_1, BUG_FORMAT_2_COMMENT_1, BUG_FORMAT_3_COMMENT_1,
BUG_FORMAT_4_COMMENT_1, TASK_FORMAT_1_COMMENT_2, TASK_FORMAT_2_COMMENT_2, TASK_FORMAT_3_COMMENT_2,
TASK_FORMAT_4_COMMENT_2, BUG_FORMAT_1_COMMENT_2, BUG_FORMAT_2_COMMENT_2, BUG_FORMAT_3_COMMENT_2,
BUG_FORMAT_4_COMMENT_2, TASK_FORMAT_1_COMMENT_3, TASK_FORMAT_2_COMMENT_3, TASK_FORMAT_3_COMMENT_3,
TASK_FORMAT_4_COMMENT_3, BUG_FORMAT_1_COMMENT_3, BUG_FORMAT_2_COMMENT_3, BUG_FORMAT_3_COMMENT_3,
- BUG_FORMAT_4_COMMENT_3 };
+ BUG_FORMAT_4_COMMENT_3, TASK_FORMAT_1_COMMENT_4, TASK_FORMAT_2_COMMENT_4, TASK_FORMAT_3_COMMENT_4,
+ TASK_FORMAT_4_COMMENT_4, BUG_FORMAT_1_COMMENT_4, BUG_FORMAT_2_COMMENT_4, BUG_FORMAT_3_COMMENT_4,
+ BUG_FORMAT_4_COMMENT_4 };
}
private void setRepository(final TaskRepository repository) {
@@ -178,17 +219,35 @@ public class BugzillaTaskHyperlinkDetectorTest extends TestCase {
}
public void testBeginningWithSpecialChars() {
- for (String format : formats) {
+ for (String format : bugFormats) {
String testString = "First line\n:" + format + " is at the beginning";
viewer.setDocument(new Document(testString));
Region region = new Region(0, testString.length());
IHyperlink[] links = detector.detectHyperlinks(viewer, region, false);
assertNotNull(links);
assertEquals(1, links.length);
- assertEquals(testString.indexOf(format), links[0].getHyperlinkRegion().getOffset());
- Object comment = ((TaskHyperlink) links[0]).getSelection();
+ assertTrue(links[0] instanceof TaskHyperlink);
+ TaskHyperlink taskLink = (TaskHyperlink) links[0];
+ assertEquals("123", taskLink.getTaskId());
+ assertEquals(testString.indexOf(format), taskLink.getHyperlinkRegion().getOffset());
+ Object comment = taskLink.getSelection();
assertNull(comment);
}
+ for (String format : bugCommentFormats) {
+ String testString = "First line\n:" + format + " is at the beginning";
+ viewer.setDocument(new Document(testString));
+ Region region = new Region(0, testString.length());
+ IHyperlink[] links = detector.detectHyperlinks(viewer, region, false);
+ assertNotNull(links);
+ assertEquals(1, links.length);
+ assertTrue(links[0] instanceof TaskHyperlink);
+ TaskHyperlink taskLink = (TaskHyperlink) links[0];
+ assertEquals("123", taskLink.getTaskId());
+ assertEquals(testString.indexOf(format), taskLink.getHyperlinkRegion().getOffset());
+ Object comment = taskLink.getSelection();
+ assertNotNull(comment);
+ assertEquals(TaskAttribute.PREFIX_COMMENT + "44556677", comment);
+ }
for (String format : commentFormats) {
String testString = "First line\n:" + format + " is at the beginning";
viewer.setDocument(new Document(testString));
@@ -196,25 +255,46 @@ public class BugzillaTaskHyperlinkDetectorTest extends TestCase {
IHyperlink[] links = detector.detectHyperlinks(viewer, region, false);
assertNotNull(links);
assertEquals(1, links.length);
- assertEquals(testString.indexOf(format), links[0].getHyperlinkRegion().getOffset());
- Object comment = ((TaskHyperlink) links[0]).getSelection();
+ assertTrue(links[0] instanceof TaskHyperlink);
+ TaskHyperlink taskLink = (TaskHyperlink) links[0];
+ assertEquals("123", taskLink.getTaskId());
+ assertEquals(testString.indexOf(format), taskLink.getHyperlinkRegion().getOffset());
+ Object comment = taskLink.getSelection();
assertNotNull(comment);
assertEquals(TaskAttribute.PREFIX_COMMENT + "44556677", comment);
}
}
public void testBeginningOfSecondLine() {
- for (String format : formats) {
+ for (String format : bugFormats) {
String testString = "First line\n" + format + " is at the beginning";
viewer.setDocument(new Document(testString));
Region region = new Region(0, testString.length());
IHyperlink[] links = detector.detectHyperlinks(viewer, region, false);
assertNotNull(links);
assertEquals(1, links.length);
- assertEquals(testString.indexOf(format), links[0].getHyperlinkRegion().getOffset());
- Object comment = ((TaskHyperlink) links[0]).getSelection();
+ assertTrue(links[0] instanceof TaskHyperlink);
+ TaskHyperlink taskLink = (TaskHyperlink) links[0];
+ assertEquals("123", taskLink.getTaskId());
+ assertEquals(testString.indexOf(format), taskLink.getHyperlinkRegion().getOffset());
+ Object comment = taskLink.getSelection();
assertNull(comment);
}
+ for (String format : bugCommentFormats) {
+ String testString = "First line\n" + format + " is at the beginning";
+ viewer.setDocument(new Document(testString));
+ Region region = new Region(0, testString.length());
+ IHyperlink[] links = detector.detectHyperlinks(viewer, region, false);
+ assertNotNull(links);
+ assertEquals(1, links.length);
+ assertTrue(links[0] instanceof TaskHyperlink);
+ TaskHyperlink taskLink = (TaskHyperlink) links[0];
+ assertEquals("123", taskLink.getTaskId());
+ assertEquals(testString.indexOf(format), taskLink.getHyperlinkRegion().getOffset());
+ Object comment = taskLink.getSelection();
+ assertNotNull(comment);
+ assertEquals(TaskAttribute.PREFIX_COMMENT + "44556677", comment);
+ }
for (String format : commentFormats) {
String testString = "First line\n" + format + " is at the beginning";
viewer.setDocument(new Document(testString));
@@ -222,25 +302,46 @@ public class BugzillaTaskHyperlinkDetectorTest extends TestCase {
IHyperlink[] links = detector.detectHyperlinks(viewer, region, false);
assertNotNull(links);
assertEquals(1, links.length);
- assertEquals(testString.indexOf(format), links[0].getHyperlinkRegion().getOffset());
- Object comment = ((TaskHyperlink) links[0]).getSelection();
+ assertTrue(links[0] instanceof TaskHyperlink);
+ TaskHyperlink taskLink = (TaskHyperlink) links[0];
+ assertEquals("123", taskLink.getTaskId());
+ assertEquals(testString.indexOf(format), taskLink.getHyperlinkRegion().getOffset());
+ Object comment = taskLink.getSelection();
assertNotNull(comment);
assertEquals(TaskAttribute.PREFIX_COMMENT + "44556677", comment);
}
}
public void testBeginningOfSecondLineWithisWhitespace() {
- for (String format : formats) {
+ for (String format : bugFormats) {
String testString = "First line\n \t " + format + " is at the beginning";
viewer.setDocument(new Document(testString));
Region region = new Region(0, testString.length());
IHyperlink[] links = detector.detectHyperlinks(viewer, region, false);
assertNotNull(links);
assertEquals(1, links.length);
- assertEquals(testString.indexOf(format), links[0].getHyperlinkRegion().getOffset());
- Object comment = ((TaskHyperlink) links[0]).getSelection();
+ assertTrue(links[0] instanceof TaskHyperlink);
+ TaskHyperlink taskLink = (TaskHyperlink) links[0];
+ assertEquals("123", taskLink.getTaskId());
+ assertEquals(testString.indexOf(format), taskLink.getHyperlinkRegion().getOffset());
+ Object comment = taskLink.getSelection();
assertNull(comment);
}
+ for (String format : bugCommentFormats) {
+ String testString = "First line\n \t " + format + " is at the beginning";
+ viewer.setDocument(new Document(testString));
+ Region region = new Region(0, testString.length());
+ IHyperlink[] links = detector.detectHyperlinks(viewer, region, false);
+ assertNotNull(links);
+ assertEquals(1, links.length);
+ assertTrue(links[0] instanceof TaskHyperlink);
+ TaskHyperlink taskLink = (TaskHyperlink) links[0];
+ assertEquals("123", taskLink.getTaskId());
+ assertEquals(testString.indexOf(format), taskLink.getHyperlinkRegion().getOffset());
+ Object comment = taskLink.getSelection();
+ assertNotNull(comment);
+ assertEquals(TaskAttribute.PREFIX_COMMENT + "44556677", comment);
+ }
for (String format : commentFormats) {
String testString = "First line\n \t " + format + " is at the beginning";
viewer.setDocument(new Document(testString));
@@ -248,25 +349,46 @@ public class BugzillaTaskHyperlinkDetectorTest extends TestCase {
IHyperlink[] links = detector.detectHyperlinks(viewer, region, false);
assertNotNull(links);
assertEquals(1, links.length);
- assertEquals(testString.indexOf(format), links[0].getHyperlinkRegion().getOffset());
- Object comment = ((TaskHyperlink) links[0]).getSelection();
+ assertTrue(links[0] instanceof TaskHyperlink);
+ TaskHyperlink taskLink = (TaskHyperlink) links[0];
+ assertEquals("123", taskLink.getTaskId());
+ assertEquals(testString.indexOf(format), taskLink.getHyperlinkRegion().getOffset());
+ Object comment = taskLink.getSelection();
assertNotNull(comment);
assertEquals(TaskAttribute.PREFIX_COMMENT + "44556677", comment);
}
}
public void testBeginning() {
- for (String format : formats) {
+ for (String format : bugFormats) {
String testString = format + " is at the beginning";
viewer.setDocument(new Document(testString));
Region region = new Region(0, testString.length());
IHyperlink[] links = detector.detectHyperlinks(viewer, region, false);
assertNotNull(links);
assertEquals(1, links.length);
- assertEquals(testString.indexOf(format), links[0].getHyperlinkRegion().getOffset());
- Object comment = ((TaskHyperlink) links[0]).getSelection();
+ assertTrue(links[0] instanceof TaskHyperlink);
+ TaskHyperlink taskLink = (TaskHyperlink) links[0];
+ assertEquals("123", taskLink.getTaskId());
+ assertEquals(testString.indexOf(format), taskLink.getHyperlinkRegion().getOffset());
+ Object comment = taskLink.getSelection();
assertNull(comment);
}
+ for (String format : bugCommentFormats) {
+ String testString = format + " is at the beginning";
+ viewer.setDocument(new Document(testString));
+ Region region = new Region(0, testString.length());
+ IHyperlink[] links = detector.detectHyperlinks(viewer, region, false);
+ assertNotNull(links);
+ assertEquals(1, links.length);
+ assertTrue(links[0] instanceof TaskHyperlink);
+ TaskHyperlink taskLink = (TaskHyperlink) links[0];
+ assertEquals("123", taskLink.getTaskId());
+ assertEquals(testString.indexOf(format), taskLink.getHyperlinkRegion().getOffset());
+ Object comment = taskLink.getSelection();
+ assertNotNull(comment);
+ assertEquals(TaskAttribute.PREFIX_COMMENT + "44556677", comment);
+ }
for (String format : commentFormats) {
String testString = format + " is at the beginning";
viewer.setDocument(new Document(testString));
@@ -274,15 +396,18 @@ public class BugzillaTaskHyperlinkDetectorTest extends TestCase {
IHyperlink[] links = detector.detectHyperlinks(viewer, region, false);
assertNotNull(links);
assertEquals(1, links.length);
- assertEquals(testString.indexOf(format), links[0].getHyperlinkRegion().getOffset());
- Object comment = ((TaskHyperlink) links[0]).getSelection();
+ assertTrue(links[0] instanceof TaskHyperlink);
+ TaskHyperlink taskLink = (TaskHyperlink) links[0];
+ assertEquals("123", taskLink.getTaskId());
+ assertEquals(testString.indexOf(format), taskLink.getHyperlinkRegion().getOffset());
+ Object comment = taskLink.getSelection();
assertNotNull(comment);
assertEquals(TaskAttribute.PREFIX_COMMENT + "44556677", comment);
}
}
public void testEnd() {
- for (String format : formats) {
+ for (String format : bugFormats) {
String testString = "is ends with " + format;
viewer.setDocument(new Document(testString));
int i = testString.indexOf(format);
@@ -290,10 +415,29 @@ public class BugzillaTaskHyperlinkDetectorTest extends TestCase {
IHyperlink[] links = detector.detectHyperlinks(viewer, region, false);
assertNotNull(links);
assertEquals(1, links.length);
- assertEquals(i, links[0].getHyperlinkRegion().getOffset());
- Object comment = ((TaskHyperlink) links[0]).getSelection();
+ assertTrue(links[0] instanceof TaskHyperlink);
+ TaskHyperlink taskLink = (TaskHyperlink) links[0];
+ assertEquals("123", taskLink.getTaskId());
+ assertEquals(testString.indexOf(format), taskLink.getHyperlinkRegion().getOffset());
+ Object comment = taskLink.getSelection();
assertNull(comment);
}
+ for (String format : bugCommentFormats) {
+ String testString = "is ends with " + format;
+ viewer.setDocument(new Document(testString));
+ int i = testString.indexOf(format);
+ Region region = new Region(i, testString.length() - i);
+ IHyperlink[] links = detector.detectHyperlinks(viewer, region, false);
+ assertNotNull(links);
+ assertEquals(1, links.length);
+ assertTrue(links[0] instanceof TaskHyperlink);
+ TaskHyperlink taskLink = (TaskHyperlink) links[0];
+ assertEquals("123", taskLink.getTaskId());
+ assertEquals(testString.indexOf(format), taskLink.getHyperlinkRegion().getOffset());
+ Object comment = taskLink.getSelection();
+ assertNotNull(comment);
+ assertEquals(TaskAttribute.PREFIX_COMMENT + "44556677", comment);
+ }
for (String format : commentFormats) {
String testString = "is ends with " + format;
viewer.setDocument(new Document(testString));
@@ -301,15 +445,18 @@ public class BugzillaTaskHyperlinkDetectorTest extends TestCase {
IHyperlink[] links = detector.detectHyperlinks(viewer, region, false);
assertNotNull(links);
assertEquals(1, links.length);
- assertEquals(testString.indexOf(format), links[0].getHyperlinkRegion().getOffset());
- Object comment = ((TaskHyperlink) links[0]).getSelection();
+ assertTrue(links[0] instanceof TaskHyperlink);
+ TaskHyperlink taskLink = (TaskHyperlink) links[0];
+ assertEquals("123", taskLink.getTaskId());
+ assertEquals(testString.indexOf(format), taskLink.getHyperlinkRegion().getOffset());
+ Object comment = taskLink.getSelection();
assertNotNull(comment);
assertEquals(TaskAttribute.PREFIX_COMMENT + "44556677", comment);
}
}
public void testMiddle() {
- for (String format : formats) {
+ for (String format : bugFormats) {
String testString = "is a " + format + " in the middle";
viewer.setDocument(new Document(testString));
int i = testString.indexOf(format);
@@ -317,10 +464,28 @@ public class BugzillaTaskHyperlinkDetectorTest extends TestCase {
IHyperlink[] links = detector.detectHyperlinks(viewer, region, false);
assertNotNull(links);
assertEquals(1, links.length);
- assertEquals(testString.indexOf(format), links[0].getHyperlinkRegion().getOffset());
- Object comment = ((TaskHyperlink) links[0]).getSelection();
+ assertTrue(links[0] instanceof TaskHyperlink);
+ TaskHyperlink taskLink = (TaskHyperlink) links[0];
+ assertEquals("123", taskLink.getTaskId());
+ assertEquals(testString.indexOf(format), taskLink.getHyperlinkRegion().getOffset());
+ Object comment = taskLink.getSelection();
assertNull(comment);
}
+ for (String format : bugCommentFormats) {
+ String testString = "is a " + format + " in the middle";
+ viewer.setDocument(new Document(testString));
+ Region region = new Region(0, testString.length());
+ IHyperlink[] links = detector.detectHyperlinks(viewer, region, false);
+ assertNotNull(links);
+ assertEquals(1, links.length);
+ assertTrue(links[0] instanceof TaskHyperlink);
+ TaskHyperlink taskLink = (TaskHyperlink) links[0];
+ assertEquals("123", taskLink.getTaskId());
+ assertEquals(testString.indexOf(format), taskLink.getHyperlinkRegion().getOffset());
+ Object comment = taskLink.getSelection();
+ assertNotNull(comment);
+ assertEquals(TaskAttribute.PREFIX_COMMENT + "44556677", comment);
+ }
for (String format : commentFormats) {
String testString = "is a " + format + " in the middle";
viewer.setDocument(new Document(testString));
@@ -328,8 +493,11 @@ public class BugzillaTaskHyperlinkDetectorTest extends TestCase {
IHyperlink[] links = detector.detectHyperlinks(viewer, region, false);
assertNotNull(links);
assertEquals(1, links.length);
- assertEquals(testString.indexOf(format), links[0].getHyperlinkRegion().getOffset());
- Object comment = ((TaskHyperlink) links[0]).getSelection();
+ assertTrue(links[0] instanceof TaskHyperlink);
+ TaskHyperlink taskLink = (TaskHyperlink) links[0];
+ assertEquals("123", taskLink.getTaskId());
+ assertEquals(testString.indexOf(format), taskLink.getHyperlinkRegion().getOffset());
+ Object comment = taskLink.getSelection();
assertNotNull(comment);
assertEquals(TaskAttribute.PREFIX_COMMENT + "44556677", comment);
}
@@ -473,7 +641,6 @@ public class BugzillaTaskHyperlinkDetectorTest extends TestCase {
public void testAttachmentOld() {
String testString = ATTACHMENT_OLD;
viewer.setDocument(new Document(testString));
- int i = testString.indexOf(ATTACHMENT_NUMBER);
Region region = new Region(0, testString.length());
IHyperlink[] links = detector.detectHyperlinks(viewer, region, false);
assertNotNull(links);
@@ -484,7 +651,6 @@ public class BugzillaTaskHyperlinkDetectorTest extends TestCase {
public void testAttachmentNew() {
String testString = ATTACHMENT_NEW;
viewer.setDocument(new Document(testString));
- int i = testString.indexOf(ATTACHMENT_NUMBER);
Region region = new Region(0, testString.length());
IHyperlink[] links = detector.detectHyperlinks(viewer, region, false);
assertNotNull(links);

Back to the top