Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaxsun McCarthy Huggan2016-07-26 18:56:44 +0000
committerJaxsun McCarthy Huggan2016-08-17 21:05:58 +0000
commit9a4095c743725aa47d7a2ec6cc5ec50437a11291 (patch)
tree7816e10e3d58c6b9381bb44f0924f45d47055955 /org.eclipse.mylyn.tasks.tests
parent65e19007e3c45e45a542c7f253fa55ed59d7632f (diff)
downloadorg.eclipse.mylyn.tasks-9a4095c743725aa47d7a2ec6cc5ec50437a11291.tar.gz
org.eclipse.mylyn.tasks-9a4095c743725aa47d7a2ec6cc5ec50437a11291.tar.xz
org.eclipse.mylyn.tasks-9a4095c743725aa47d7a2ec6cc5ec50437a11291.zip
319889: TaskListInterestSorter uses configured sort criteria as backup
Change-Id: Iaabefc6ca4d928a8bb60beba3fedff96c06ddc88 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=319889
Diffstat (limited to 'org.eclipse.mylyn.tasks.tests')
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListInterestSorterTest.java153
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListSorterTest.java29
2 files changed, 153 insertions, 29 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListInterestSorterTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListInterestSorterTest.java
new file mode 100644
index 000000000..629bf4b1b
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListInterestSorterTest.java
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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.tasks.tests;
+
+import java.util.Date;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
+import org.eclipse.mylyn.internal.tasks.core.DateRange;
+import org.eclipse.mylyn.internal.tasks.core.LocalTask;
+import org.eclipse.mylyn.internal.tasks.core.TaskActivityUtil;
+import org.eclipse.mylyn.internal.tasks.ui.views.TaskListInterestSorter;
+import org.eclipse.swt.widgets.Control;
+
+import junit.framework.TestCase;
+
+public class TaskListInterestSorterTest extends TestCase {
+
+ private TaskListInterestSorter sorter;
+
+ private AbstractTask task1;
+
+ private AbstractTask task2;
+
+ public static class EmptyViewer extends Viewer {
+ public EmptyViewer() {
+ }
+
+ @Override
+ public Control getControl() {
+ return null;
+ }
+
+ @Override
+ public Object getInput() {
+ return null;
+ }
+
+ @Override
+ public ISelection getSelection() {
+ return null;
+ }
+
+ @Override
+ public void refresh() {
+ }
+
+ @Override
+ public void setInput(Object input) {
+ }
+
+ @Override
+ public void setSelection(ISelection selection, boolean reveal) {
+ }
+ }
+
+ public class FallbackSorter extends ViewerSorter {
+ @Override
+ public int compare(Viewer v, Object o1, Object o2) {
+ if (o1 == task1) {
+ return 1;
+ }
+ return -1;
+ }
+ }
+
+ @Override
+ public void setUp() {
+ sorter = new TaskListInterestSorter();
+ task1 = new LocalTask("1", "one");
+ task2 = new LocalTask("2", "two");
+ }
+
+ public void testSortDefault() {
+ assertEquals(0, sorter.compare(new EmptyViewer(), task1, task2));
+ assertEquals(0, sorter.compare(new EmptyViewer(), task2, task1));
+ }
+
+ public void testSortFallback() {
+ sorter.setconfiguredSorter(new FallbackSorter());
+
+ assertEquals(1, sorter.compare(new EmptyViewer(), task1, task2));
+ assertEquals(-1, sorter.compare(new EmptyViewer(), task2, task1));
+ }
+
+ public void testSortCompleted() {
+ Date now = new Date();
+
+ task1.setCompletionDate(now);
+
+ assertEquals(1, sorter.compare(new EmptyViewer(), task1, task2));
+ assertEquals(-1, sorter.compare(new EmptyViewer(), task2, task1));
+
+ task2.setCompletionDate(now);
+
+ assertEquals(0, sorter.compare(new EmptyViewer(), task1, task2));
+ assertEquals(0, sorter.compare(new EmptyViewer(), task2, task1));
+ }
+
+ public void testSortScheduled() {
+ DateRange today = TaskActivityUtil.getCurrentWeek().getToday();
+ DateRange tomorrow = TaskActivityUtil.getCurrentWeek().getToday().next();
+ DateRange yesterday = TaskActivityUtil.getCurrentWeek().getToday().previous();
+
+ task1.setScheduledForDate(today);
+
+ assertEquals(-1, sorter.compare(new EmptyViewer(), task1, task2));
+ assertEquals(1, sorter.compare(new EmptyViewer(), task2, task1));
+
+ task2.setScheduledForDate(tomorrow);
+
+ assertEquals(-1, sorter.compare(new EmptyViewer(), task1, task2));
+ assertEquals(1, sorter.compare(new EmptyViewer(), task2, task1));
+
+ task2.setScheduledForDate(yesterday);
+
+ assertEquals(0, sorter.compare(new EmptyViewer(), task1, task2));
+ assertEquals(0, sorter.compare(new EmptyViewer(), task2, task1));
+ }
+
+ public void testSortDue() {
+ DateRange today = TaskActivityUtil.getCurrentWeek().getToday();
+ DateRange tomorrow = TaskActivityUtil.getCurrentWeek().getToday().next();
+ DateRange yesterday = TaskActivityUtil.getCurrentWeek().getToday().previous();
+
+ task1.setDueDate(new Date(today.getStartDate().getTimeInMillis()));
+
+ assertEquals(-1, sorter.compare(new EmptyViewer(), task1, task2));
+ assertEquals(1, sorter.compare(new EmptyViewer(), task2, task1));
+
+ task2.setDueDate(new Date(tomorrow.getStartDate().getTimeInMillis()));
+
+ assertEquals(-1, sorter.compare(new EmptyViewer(), task1, task2));
+ assertEquals(1, sorter.compare(new EmptyViewer(), task2, task1));
+
+ task2.setDueDate(new Date(yesterday.getStartDate().getTimeInMillis()));
+
+ assertEquals(0, sorter.compare(new EmptyViewer(), task1, task2));
+ assertEquals(0, sorter.compare(new EmptyViewer(), task2, task1));
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListSorterTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListSorterTest.java
index 58dfa29e9..26d7ea6c8 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListSorterTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListSorterTest.java
@@ -14,26 +14,20 @@
package org.eclipse.mylyn.tasks.tests;
-import java.util.Calendar;
import java.util.Date;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
import org.eclipse.mylyn.internal.tasks.core.AbstractTaskContainer;
-import org.eclipse.mylyn.internal.tasks.core.DateRange;
import org.eclipse.mylyn.internal.tasks.core.LocalTask;
import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery;
-import org.eclipse.mylyn.internal.tasks.core.TaskActivityUtil;
import org.eclipse.mylyn.internal.tasks.core.TaskCategory;
import org.eclipse.mylyn.internal.tasks.core.TaskGroup;
import org.eclipse.mylyn.internal.tasks.core.UncategorizedTaskContainer;
import org.eclipse.mylyn.internal.tasks.core.UnmatchedTaskContainer;
import org.eclipse.mylyn.internal.tasks.core.UnsubmittedTaskContainer;
-import org.eclipse.mylyn.internal.tasks.core.WeekDateRange;
-import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.internal.tasks.ui.util.SortCriterion;
-import org.eclipse.mylyn.internal.tasks.ui.views.TaskListInterestSorter;
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListSorter;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
@@ -162,29 +156,6 @@ public class TaskListSorterTest extends TestCase {
}
}
- public void testScheduledTaskSorting() {
- final TaskListInterestSorter sorter = new TaskListInterestSorter();
- MockTask task1 = new MockTask("local", "MYLN:1", "1");
- MockTask task2 = new MockTask("local", "MYLN:2", "2");
-
- Calendar start1 = TaskActivityUtil.getCalendar();
- start1.add(Calendar.WEEK_OF_YEAR, -1);
- TaskActivityUtil.snapStartOfWorkWeek(start1);
- Calendar end1 = TaskActivityUtil.getCalendar();
- end1.setTimeInMillis(start1.getTimeInMillis());
- TaskActivityUtil.snapEndOfWeek(end1);
- WeekDateRange range1 = new WeekDateRange(start1, end1);
- TasksUiPlugin.getTaskActivityManager().setScheduledFor(task1, range1);
-
- Calendar start2 = TaskActivityUtil.getCalendar();
- start2.add(Calendar.HOUR_OF_DAY, -1);
- Calendar end2 = TaskActivityUtil.getCalendar();
- DateRange range2 = new DateRange(start2, end2);
- TasksUiPlugin.getTaskActivityManager().setScheduledFor(task2, range2);
-
- assertTrue(sorter.compare(new EmptyViewer(), task1, task2) < 0);
- }
-
public void testSummaryOrderSorting() {
MockTask[] tasks = new MockTask[6];
tasks[0] = new MockTask("local", "4", "c");

Back to the top