From de8d415884aca6bec93b8d4ba1fc7c7b955e3e36 Mon Sep 17 00:00:00 2001 From: spingel Date: Wed, 21 Nov 2007 21:17:43 +0000 Subject: NEW - bug 169426: create a new bug from a comment https://bugs.eclipse.org/bugs/show_bug.cgi?id=169426 --- .../tests/NewTaskFromSelectionActionTest.java | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/NewTaskFromSelectionActionTest.java (limited to 'org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/NewTaskFromSelectionActionTest.java') diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/NewTaskFromSelectionActionTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/NewTaskFromSelectionActionTest.java new file mode 100644 index 000000000..0e95f155e --- /dev/null +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/NewTaskFromSelectionActionTest.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Mylyn project committers 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.mylyn.tasks.tests; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import junit.framework.TestCase; + +import org.eclipse.jface.text.TextSelection; +import org.eclipse.mylyn.internal.tasks.ui.actions.NewTaskFromSelectionAction; +import org.eclipse.mylyn.internal.tasks.ui.editors.RepositoryTaskSelection; +import org.eclipse.mylyn.tasks.core.AbstractAttributeFactory; +import org.eclipse.mylyn.tasks.core.TaskComment; + +/** + * @author Frank Becker + * @author Steffen Pingel + */ +public class NewTaskFromSelectionActionTest extends TestCase { + + public void testNoSelection() throws Exception { + NewTaskFromSelectionAction action = new NewTaskFromSelectionAction(); + assertNull(action.getTaskSelection()); + action.run(); + action.selectionChanged(null); + assertNull(action.getTaskSelection()); + } + + public void testComment() throws Exception { + StubAttributeFactory targetFactory = new StubAttributeFactory(); + TaskComment comment = new TaskComment(targetFactory, 1); + + NewTaskFromSelectionAction action = new NewTaskFromSelectionAction(); + action.selectionChanged(new RepositoryTaskSelection("id", "server", "kind", "", comment, "summary")); + assertNotNull(action.getTaskSelection()); + } + + public void testText() throws Exception { + NewTaskFromSelectionAction action = new NewTaskFromSelectionAction(); + action.selectionChanged(new TextSelection(0, 0) { + @Override + public String getText() { + return "text"; + } + }); + assertNotNull(action.getTaskSelection()); + + action.selectionChanged(new TextSelection(0, 0)); + assertNull(action.getTaskSelection()); + } + + private class StubAttributeFactory extends AbstractAttributeFactory { + + private static final long serialVersionUID = 1L; + + private Map attributeMap = new HashMap(); + + @Override + public Date getDateForAttributeType(String attributeKey, String dateString) { + // ignore + return null; + } + + @Override + public String getName(String key) { + // ignore + return null; + } + + @Override + public boolean isHidden(String key) { + // ignore + return false; + } + + @Override + public boolean isReadOnly(String key) { + // ignore + return false; + } + + @Override + public String mapCommonAttributeKey(String key) { + String mappedKey = attributeMap.get(key); + return (mappedKey != null) ? mappedKey : key; + } + + } +} -- cgit v1.2.3