diff options
author | Steffen Pingel | 2012-02-04 19:35:40 +0000 |
---|---|---|
committer | Steffen Pingel | 2012-02-04 19:35:40 +0000 |
commit | 276d685286a0e2847efa0e28c4a954a6365e1187 (patch) | |
tree | 790d579e3898a5321966c59004960ecb614efa73 /org.eclipse.mylyn.gerrit.ui.tests | |
parent | 803049f4e4deba8e81b98a258bafc894ddef80af (diff) | |
download | org.eclipse.mylyn.reviews-276d685286a0e2847efa0e28c4a954a6365e1187.tar.gz org.eclipse.mylyn.reviews-276d685286a0e2847efa0e28c4a954a6365e1187.tar.xz org.eclipse.mylyn.reviews-276d685286a0e2847efa0e28c4a954a6365e1187.zip |
add hyperlink detector that detects bug links
Bug: 356898
Change-Id: I40cbe9b6acac33c829c900304e9e9e71eb60d05a
Diffstat (limited to 'org.eclipse.mylyn.gerrit.ui.tests')
-rw-r--r-- | org.eclipse.mylyn.gerrit.ui.tests/src/org/eclipse/mylyn/internal/gerrit/ui/GerritCommentLinkDetectorTest.java | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.gerrit.ui.tests/src/org/eclipse/mylyn/internal/gerrit/ui/GerritCommentLinkDetectorTest.java b/org.eclipse.mylyn.gerrit.ui.tests/src/org/eclipse/mylyn/internal/gerrit/ui/GerritCommentLinkDetectorTest.java new file mode 100644 index 000000000..e842485cf --- /dev/null +++ b/org.eclipse.mylyn.gerrit.ui.tests/src/org/eclipse/mylyn/internal/gerrit/ui/GerritCommentLinkDetectorTest.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * Copyright (c) 2012 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.internal.gerrit.ui; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.jface.text.Region; +import org.eclipse.mylyn.commons.workbench.browser.UrlHyperlink; +import org.eclipse.mylyn.internal.gerrit.core.GerritConnector; +import org.eclipse.mylyn.internal.gerrit.core.client.compat.CommentLink; +import org.eclipse.mylyn.tasks.core.TaskRepository; +import org.junit.Test; + +/** + * @author Steffen Pingel + */ +public class GerritCommentLinkDetectorTest { + + TaskRepository repository = new TaskRepository(GerritConnector.CONNECTOR_KIND, "http://review.mylyn.org"); + + List<CommentLink> commentLinks = new ArrayList<CommentLink>(); + + private static CommentLink COMMENT_LINK_TASK = new CommentLink("([Tt]ask:\\s+)(\\d+)", + "$1<a href=\"http://tracker.mylyn.org/$2\">$2</a>"); + + private static CommentLink COMMENT_LINK_TASK_INVALID = new CommentLink("([Tt]ask:\\s+)(\\d+)", + "http://tracker.mylyn.org/$2"); + + private static CommentLink COMMENT_LINK_CHANGE = new CommentLink("(I[0-9a-f]{8,40})", + "<a href=\"#q,$1,n,z\">$&</a>"); + + private static CommentLink COMMENT_LINK_BUG = new CommentLink("(bug\\s+)(\\d+)", + "<a href=\"http://bugs.mylyn.org/show_bug.cgi?id=$2\">$&</a>"); + + @Test + public void testTaskPattern() { + commentLinks.add(COMMENT_LINK_TASK); + GerritCommentLinkDetector detector = new GerritCommentLinkDetector(repository, commentLinks); + UrlHyperlink expected = new UrlHyperlink(new Region(0, 9), "http://tracker.mylyn.org/123"); + assertEquals(String.valueOf(Collections.singletonList(expected)), + String.valueOf(detector.findHyperlinks("Task: 123", 0, 0))); + } + + @Test + public void testLinkChangeId() { + commentLinks.add(COMMENT_LINK_CHANGE); + GerritCommentLinkDetector detector = new GerritCommentLinkDetector(repository, commentLinks); + UrlHyperlink expected = new UrlHyperlink(new Region(0, 41), + "http://review.mylyn.org/#q,If1d90fa42e1e98f03a68fb59c2b5bedc3d371f0f,n,z"); + assertEquals(String.valueOf(Collections.singletonList(expected)), + String.valueOf(detector.findHyperlinks("If1d90fa42e1e98f03a68fb59c2b5bedc3d371f0f", 0, 0))); + } + + @Test + public void testTaskPatternInvalid() { + commentLinks.add(COMMENT_LINK_TASK_INVALID); + GerritCommentLinkDetector detector = new GerritCommentLinkDetector(repository, commentLinks); + UrlHyperlink expected = new UrlHyperlink(new Region(0, 9), "http://tracker.mylyn.org/123"); + assertEquals("null", String.valueOf(detector.findHyperlinks("Task: 123", 0, 0))); + } + + @Test + public void testTaskPatternTwice() { + commentLinks.add(COMMENT_LINK_TASK); + GerritCommentLinkDetector detector = new GerritCommentLinkDetector(repository, commentLinks); + UrlHyperlink expected1 = new UrlHyperlink(new Region(4, 9), "http://tracker.mylyn.org/123"); + UrlHyperlink expected2 = new UrlHyperlink(new Region(18, 7), "http://tracker.mylyn.org/4"); + assertEquals(String.valueOf(Arrays.asList(expected1, expected2)), + String.valueOf(detector.findHyperlinks("abc Task: 123 and Task: 4", -1, 0))); + } + + @Test + public void testTaskPatternNoMatch() { + commentLinks.add(COMMENT_LINK_TASK); + GerritCommentLinkDetector detector = new GerritCommentLinkDetector(repository, commentLinks); + assertEquals("null", String.valueOf(detector.findHyperlinks("Task 123", 0, 0))); + } + + @Test + public void testTaskPatternNoMatchBug() { + commentLinks.add(COMMENT_LINK_TASK); + GerritCommentLinkDetector detector = new GerritCommentLinkDetector(repository, commentLinks); + assertEquals("null", String.valueOf(detector.findHyperlinks("Bug 123", 0, 0))); + } + + @Test + public void testTaskBugPatternTwice() { + commentLinks.add(COMMENT_LINK_TASK); + commentLinks.add(COMMENT_LINK_BUG); + GerritCommentLinkDetector detector = new GerritCommentLinkDetector(repository, commentLinks); + UrlHyperlink expected1 = new UrlHyperlink(new Region(4, 9), "http://tracker.mylyn.org/123"); + UrlHyperlink expected2 = new UrlHyperlink(new Region(18, 5), "http://bugs.mylyn.org/show_bug.cgi?id=4"); + assertEquals(String.valueOf(Arrays.asList(expected1, expected2)), + String.valueOf(detector.findHyperlinks("abc Task: 123 and bug 4", -1, 0))); + } + + @Test + public void testNoPattern() { + GerritCommentLinkDetector detector = new GerritCommentLinkDetector(repository, (List<CommentLink>) null); + assertEquals("null", String.valueOf(detector.findHyperlinks("Bug 123", 0, 0))); + } + +} |