Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaxsun McCarthy Huggan2016-06-15 22:32:14 +0000
committerGerrit Code Review @ Eclipse.org2016-08-17 00:09:19 +0000
commit10d73213c4d6b5318b0606db516014fbc8de7dd0 (patch)
tree1fe577adbef1419caa893f804e4e00d5f51e30c7 /org.eclipse.mylyn.tasks.ui.tests
parentf4f9a57fc83f397ab4b7c4704cd8e69003e94a6e (diff)
downloadorg.eclipse.mylyn.tasks-10d73213c4d6b5318b0606db516014fbc8de7dd0.tar.gz
org.eclipse.mylyn.tasks-10d73213c4d6b5318b0606db516014fbc8de7dd0.tar.xz
org.eclipse.mylyn.tasks-10d73213c4d6b5318b0606db516014fbc8de7dd0.zip
319889: Support sorting of scheduled presentation
The TaskComparator now maintains a list of sort criteria per presentation. The criteria will always be configured for the active presentation. The migration of old sorting mementos was removed. Change-Id: I5d9b594e4efda7b35ccdca2b19fb824a6590d5f1 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=319889
Diffstat (limited to 'org.eclipse.mylyn.tasks.ui.tests')
-rw-r--r--org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparatorTest.java76
1 files changed, 66 insertions, 10 deletions
diff --git a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparatorTest.java b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparatorTest.java
index eaa65c5a0..29f559327 100644
--- a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparatorTest.java
+++ b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskComparatorTest.java
@@ -15,12 +15,26 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.eclipse.mylyn.internal.tasks.core.TaskTask;
+import org.eclipse.mylyn.internal.tasks.ui.CategorizedPresentation;
+import org.eclipse.mylyn.internal.tasks.ui.ScheduledPresentation;
+import org.eclipse.mylyn.internal.tasks.ui.util.SortCriterion.SortKey;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.XMLMemento;
+import org.junit.Before;
import org.junit.Test;
+@SuppressWarnings("restriction")
public class TaskComparatorTest {
+ private TaskComparator taskComparator;
+
+ @Before
+ public void setup() {
+ taskComparator = new TaskComparator();
+ }
+
@Test
public void compareRank() {
assertCompare(taskWithRank("5"), taskWithRank("7"));
@@ -34,23 +48,65 @@ public class TaskComparatorTest {
assertCompare(taskWithRank("dsfhgS"), taskWithRank("dsfhgsd"));
assertCompare(taskWithRank("dsfhgs"), taskWithRank("dsfhgsd"));
- assertEquals(0, compare(taskWithRank("5"), taskWithRank("5")));
- assertEquals(0, compare(taskWithRank("17.1"), taskWithRank("17.1")));
- assertEquals(0, compare(taskWithRank("dsfhgs"), taskWithRank("dsfhgs")));
- assertEquals(0, compare(taskWithRank("ds#fHgs"), taskWithRank("ds#fHgs")));
+ assertEquals(0, taskComparator.compare(taskWithRank("5"), taskWithRank("5")));
+ assertEquals(0, taskComparator.compare(taskWithRank("17.1"), taskWithRank("17.1")));
+ assertEquals(0, taskComparator.compare(taskWithRank("dsfhgs"), taskWithRank("dsfhgs")));
+ assertEquals(0, taskComparator.compare(taskWithRank("ds#fHgs"), taskWithRank("ds#fHgs")));
}
- private void assertCompare(ITask task1, ITask task2) {
- assertTrue(compare(task1, task2) < 0);
- assertTrue(compare(task2, task1) > 0);
+ @Test
+ public void readLegacyMemento() {
+ XMLMemento memento = XMLMemento.createWriteRoot("sorter");
+ IMemento child1 = memento.createChild("sort0");
+ IMemento child2 = memento.createChild("sort1");
+ SortCriterion criterion1 = new SortCriterion(SortKey.PRIORITY, SortCriterion.ASCENDING);
+ SortCriterion criterion2 = new SortCriterion(SortKey.TASK_ID, SortCriterion.DESCENDING);
+ criterion1.saveState(child1);
+ criterion2.saveState(child2);
+ taskComparator.restoreState(memento);
+ assertCriterionEquals(criterion1, taskComparator.getSortCriterion(0));
+ assertCriterionEquals(criterion2, taskComparator.getSortCriterion(1));
}
- private int compare(ITask task1, ITask task2) {
- return new TaskComparator().compare(task1, task2);
+ @Test
+ public void readPerspectiveMemento() {
+ XMLMemento memento = XMLMemento.createWriteRoot("sorter");
+ IMemento categorized1 = memento.createChild("sortorg.eclipse.mylyn.tasks.ui.categorized0");
+ IMemento categorized2 = memento.createChild("sortorg.eclipse.mylyn.tasks.ui.categorized1");
+ IMemento scheduled1 = memento.createChild("sortorg.eclipse.mylyn.tasks.ui.scheduled0");
+ IMemento scheduled2 = memento.createChild("sortorg.eclipse.mylyn.tasks.ui.scheduled1");
+ SortCriterion criterion1c = new SortCriterion(SortKey.PRIORITY, SortCriterion.ASCENDING);
+ SortCriterion criterion2c = new SortCriterion(SortKey.TASK_ID, SortCriterion.DESCENDING);
+ SortCriterion criterion1s = new SortCriterion(SortKey.DUE_DATE, SortCriterion.ASCENDING);
+ SortCriterion criterion2s = new SortCriterion(SortKey.SCHEDULED_DATE, SortCriterion.DESCENDING);
+ criterion1c.saveState(categorized1);
+ criterion2c.saveState(categorized2);
+ criterion1s.saveState(scheduled1);
+ criterion2s.saveState(scheduled2);
+
+ taskComparator.restoreState(memento);
+
+ assertCriterionEquals(criterion1c, taskComparator.getSortCriterion(0));
+ assertCriterionEquals(criterion2c, taskComparator.getSortCriterion(1));
+ taskComparator.presentationChanged(new ScheduledPresentation());
+ assertCriterionEquals(criterion1s, taskComparator.getSortCriterion(0));
+ assertCriterionEquals(criterion2s, taskComparator.getSortCriterion(1));
+ taskComparator.presentationChanged(new CategorizedPresentation());
+ assertCriterionEquals(criterion1c, taskComparator.getSortCriterion(0));
+ assertCriterionEquals(criterion2c, taskComparator.getSortCriterion(1));
+ }
+
+ private void assertCriterionEquals(SortCriterion expected, SortCriterion actual) {
+ assertEquals(expected.getDirection(), actual.getDirection());
+ assertEquals(expected.getKey(), actual.getKey());
+ }
+
+ private void assertCompare(ITask task1, ITask task2) {
+ assertTrue(taskComparator.compare(task1, task2) < 0);
+ assertTrue(taskComparator.compare(task2, task1) > 0);
}
private ITask taskWithRank(String rank) {
- @SuppressWarnings("restriction")
ITask task = new TaskTask("kind", "http://mock", "1");
task.setPriority("");
task.setAttribute(TaskAttribute.RANK, rank);

Back to the top