Skip to main content
summaryrefslogtreecommitdiffstats
blob: b6de06e917a0226b920aea50b599711c2a0d9763 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*******************************************************************************
 * Copyright (c) 2004, 2009 Frank Becker 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:
 *     Frank Becker - initial API and implementation
 *     Tasktop Technologies - improvements
 *******************************************************************************/

package org.eclipse.mylyn.tasks.tests;

import junit.framework.TestCase;

import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.mylyn.internal.tasks.core.TaskComment;
import org.eclipse.mylyn.internal.tasks.ui.actions.NewTaskFromSelectionAction;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
import org.eclipse.mylyn.tasks.tests.connector.MockTask;

/**
 * @author Frank Becker
 * @author Steffen Pingel
 */
public class NewTaskFromSelectionActionTest extends TestCase {

	// FIXME causes display of modal dialog
//	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 {
		TaskRepository taskRepository = new TaskRepository(MockRepositoryConnector.CONNECTOR_KIND,
				MockRepositoryConnector.REPOSITORY_URL);
		TaskData taskData = new TaskData(new TaskAttributeMapper(taskRepository), "kind", "http://url", "1");
		TaskComment comment = new TaskComment(taskRepository, new MockTask("1"), taskData.getRoot().createAttribute(
				"id"));

		NewTaskFromSelectionAction action = new NewTaskFromSelectionAction();
		action.selectionChanged(new StructuredSelection(comment));
		assertNotNull(action.getTaskMapping());
	}

	public void testText() throws Exception {
		NewTaskFromSelectionAction action = new NewTaskFromSelectionAction();
		action.selectionChanged(new TextSelection(0, 0) {
			@Override
			public String getText() {
				return "text";
			}
		});
		assertNotNull(action.getTaskMapping());

		action.selectionChanged(new TextSelection(0, 0));
		assertNull(action.getTaskMapping());
	}

}

Back to the top