Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchris.poon2012-08-21 22:16:05 +0000
committerSam Davis2015-05-20 17:36:53 +0000
commite3d912eacc50ad636c8865d8fe6831a4564dd767 (patch)
tree5c262104669185ff681a3f038b8f5b9c7e0f3abe /org.eclipse.mylyn.tasks.tests
parent65b8a30a5f8c1e576f74187bff37b1d253abcd45 (diff)
downloadorg.eclipse.mylyn.tasks-e3d912eacc50ad636c8865d8fe6831a4564dd767.tar.gz
org.eclipse.mylyn.tasks-e3d912eacc50ad636c8865d8fe6831a4564dd767.tar.xz
org.eclipse.mylyn.tasks-e3d912eacc50ad636c8865d8fe6831a4564dd767.zip
334937: provide API for canceling a task switch
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=334937 Change-Id: I0962f312b692de78be778d8ecb5dd11f8efdc815 Signed-off-by: chris.poon <chris.poon@tasktop.com>
Diffstat (limited to 'org.eclipse.mylyn.tasks.tests')
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityManagerTest.java102
1 files changed, 96 insertions, 6 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityManagerTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityManagerTest.java
index 9dc0a2d61..f286c01cf 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityManagerTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityManagerTest.java
@@ -100,6 +100,18 @@ public class TaskActivityManagerTest extends TestCase {
private boolean hasPreDeactivated = false;
+ private int timesCalledCanDeactivate;
+
+ private final boolean canDeactivate;
+
+ public MockTaskActivationListener() {
+ this(true);
+ }
+
+ public MockTaskActivationListener(boolean canDeactivate) {
+ this.canDeactivate = canDeactivate;
+ }
+
public void reset() {
hasActivated = false;
hasPreActivated = false;
@@ -107,6 +119,7 @@ public class TaskActivityManagerTest extends TestCase {
hasDeactivated = false;
hasPreDeactivated = false;
+ timesCalledCanDeactivate = 0;
}
@Override
@@ -133,6 +146,16 @@ public class TaskActivityManagerTest extends TestCase {
hasDeactivated = true;
}
+ @Override
+ public boolean canDeactivateTask(ITask task) {
+ timesCalledCanDeactivate++;
+ return canDeactivate;
+ }
+
+ public void verifyCalledCanDeactivate(int times) {
+ assertEquals(times, timesCalledCanDeactivate);
+ }
+
}
private TaskActivityManager taskActivityManager;
@@ -141,6 +164,10 @@ public class TaskActivityManagerTest extends TestCase {
private TaskRepository repository;
+ private AbstractTask task1;
+
+ private AbstractTask task2;
+
@Override
protected void setUp() throws Exception {
taskActivityManager = TasksUiPlugin.getTaskActivityManager();
@@ -298,12 +325,7 @@ public class TaskActivityManagerTest extends TestCase {
}
public void testAllTasksDeactivation() {
- AbstractTask task1 = new LocalTask("task1", "description1");
- AbstractTask task2 = new LocalTask("task2", "description2");
- taskList.addTask(task1);
- taskList.addTask(task2);
- assertNull(taskActivityManager.getActiveTask());
-
+ initializeTasks();
taskActivityManager.activateTask(task2);
assertEquals(task2, taskActivityManager.getActiveTask());
@@ -311,4 +333,72 @@ public class TaskActivityManagerTest extends TestCase {
assertNull(taskActivityManager.getActiveTask());
}
+ public void testActivateNonActiveTaskCanDeactivate() {
+ initializeTasks();
+ assertActivateNonActiveTaskCanDeactivate(true, task2);
+ }
+
+ public void testActivateNonActiveTaskCannotDeactivate() {
+ initializeTasks();
+ assertActivateNonActiveTaskCanDeactivate(false, task1);
+ }
+
+ private void assertActivateNonActiveTaskCanDeactivate(final boolean canDeactivate, ITask expectedActiveTask) {
+ MockTaskActivationListener listener = new MockTaskActivationListener(canDeactivate);
+
+ try {
+ taskActivityManager.addActivationListener(listener);
+
+ taskActivityManager.activateTask(task1);
+ assertEquals(task1, taskActivityManager.getActiveTask());
+
+ taskActivityManager.activateTask(task2);
+ assertEquals(expectedActiveTask, taskActivityManager.getActiveTask());
+ listener.verifyCalledCanDeactivate(1);
+ } finally {
+ taskActivityManager.removeActivationListener(listener);
+ }
+ }
+
+ public void testDeactivateTaskCanDeactivate() {
+ initializeTasks();
+ assertDeactivateTaskCanDeactivate(true, null);
+ }
+
+ public void testDeactivateTaskCannotDeactivate() {
+ initializeTasks();
+ assertDeactivateTaskCanDeactivate(false, task1);
+ }
+
+ private void assertDeactivateTaskCanDeactivate(final boolean canDeactivate, ITask expectedActiveTask) {
+ MockTaskActivationListener listener = new MockTaskActivationListener(canDeactivate);
+
+ try {
+ taskActivityManager.addActivationListener(listener);
+
+ taskActivityManager.activateTask(task1);
+ assertEquals(task1, taskActivityManager.getActiveTask());
+
+ taskActivityManager.deactivateTask(task1);
+ assertEquals(expectedActiveTask, taskActivityManager.getActiveTask());
+ listener.verifyCalledCanDeactivate(1);
+ } finally {
+ taskActivityManager.removeActivationListener(listener);
+ }
+ }
+
+ public void testDeactivateTaskOnInactiveTask() {
+ initializeTasks();
+ taskActivityManager.deactivateTask(task1);
+ assertNull(taskActivityManager.getActiveTask());
+ }
+
+ private void initializeTasks() {
+ task1 = new LocalTask("task1", "description1");
+ task2 = new LocalTask("task2", "description2");
+ taskList.addTask(task1);
+ taskList.addTask(task2);
+ assertNull(taskActivityManager.getActiveTask());
+ }
+
} \ No newline at end of file

Back to the top