Skip to main content
summaryrefslogtreecommitdiffstats
blob: 306f325dbe4570cc51cc55f0266bf37cca61f624 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*******************************************************************************
 * Copyright (c) 2004, 2013 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 junit.framework.TestCase;

import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.mylyn.internal.tasks.core.IRepositoryConstants;
import org.eclipse.mylyn.internal.tasks.core.LocalRepositoryConnector;
import org.eclipse.mylyn.internal.tasks.ui.views.TaskRepositoriesSorter;
import org.eclipse.mylyn.tasks.core.TaskRepository;

/**
 * @author Mik Kersten
 */
public class TaskRepositorySorterTest extends TestCase {

	private final static ViewerComparator sorter = new TaskRepositoriesSorter();

	public void testConnectorKindSorting() {
		TaskRepository t1 = new TaskRepository("t1", "http://a");
		TaskRepository t2 = new TaskRepository("t2", "http://a");
		TaskRepository t3 = new TaskRepository("t3", "http://a");

		// connector kind no longer affects sorting order
		assertTrue(sorter.compare(null, t1, t2) == 0);
		assertTrue(sorter.compare(null, t2, t3) == 0);
		assertTrue(sorter.compare(null, t3, t1) == 0);
	}

	public void testCategorySorting() {
		TaskRepository t1 = new TaskRepository("t1", "http://a");
		t1.setCategory(IRepositoryConstants.CATEGORY_OTHER);
		TaskRepository t2 = new TaskRepository("t2", "http://a");
		t2.setCategory(IRepositoryConstants.CATEGORY_OTHER);
		TaskRepository t3 = new TaskRepository("t3", "http://a");
		t3.setCategory(TaskRepository.CATEGORY_TASKS);

		// TaskRepositoriesSorter is not aware of categories, see TaskRepositoryViewSorterTest
		assertTrue(sorter.compare(null, t1, t2) == 0);
		assertTrue(sorter.compare(null, t2, t3) == 0);
		assertTrue(sorter.compare(null, t3, t1) == 0);
	}

	public void testUrlSorting() {
		TaskRepository t1 = new TaskRepository("t", "http://a");
		TaskRepository t2 = new TaskRepository("t", "http://b");
		TaskRepository t3 = new TaskRepository("t", "http://c");

		assertTrue(sorter.compare(null, t1, t2) < 0);
		assertTrue(sorter.compare(null, t2, t3) < 0);
		assertTrue(sorter.compare(null, t3, t1) > 0);
	}

	public void testUrlSortingWithEmptyLabels() {
		TaskRepository t1 = new TaskRepository("t", "http://a");
		t1.setProperty(IRepositoryConstants.PROPERTY_LABEL, "");
		TaskRepository t2 = new TaskRepository("t", "http://b");
		t2.setProperty(IRepositoryConstants.PROPERTY_LABEL, "");
		TaskRepository t3 = new TaskRepository("t", "http://c");
		t3.setProperty(IRepositoryConstants.PROPERTY_LABEL, "");

		assertTrue(sorter.compare(null, t1, t2) < 0);
		assertTrue(sorter.compare(null, t2, t3) < 0);
		assertTrue(sorter.compare(null, t3, t1) > 0);
	}

	public void testLabelSorting() {
		TaskRepository t1 = new TaskRepository("kind", "http://a");
		t1.setProperty(IRepositoryConstants.PROPERTY_LABEL, "a");
		TaskRepository t2 = new TaskRepository("kind", "http://a");
		t2.setProperty(IRepositoryConstants.PROPERTY_LABEL, "b");
		TaskRepository t3 = new TaskRepository("kind", "http://a");
		t3.setProperty(IRepositoryConstants.PROPERTY_LABEL, "c");

		assertTrue(sorter.compare(null, t1, t2) < 0);
		assertTrue(sorter.compare(null, t3, t1) > 0);
	}

	public void testLabelVsNoLabel() {
		TaskRepository t1 = new TaskRepository("kind", "http://a");
		t1.setProperty(IRepositoryConstants.PROPERTY_LABEL, "a");
		TaskRepository t2 = new TaskRepository("kind", "http://a");

		assertTrue(sorter.compare(null, t1, t2) < 0);
	}

	public void testLocalAlwaysFirst() {
		TaskRepository t1 = new TaskRepository("kind", "http://a");
		TaskRepository t2 = new TaskRepository("kind", "http://a");
		t2.setProperty(IRepositoryConstants.PROPERTY_LABEL, LocalRepositoryConnector.REPOSITORY_LABEL);

		assertTrue(sorter.compare(null, t1, t2) > 0);
	}

	public void testCaseInsensitiveOrdering() {
		TaskRepository t1 = new TaskRepository("kind", "http://a");
		t1.setProperty(IRepositoryConstants.PROPERTY_LABEL, "B");
		TaskRepository t2 = new TaskRepository("kind", "http://a");
		t2.setProperty(IRepositoryConstants.PROPERTY_LABEL, "a");

		assertTrue(sorter.compare(null, t1, t2) > 0);
	}

	public void testNullRepositoryUrl() {
		TaskRepository t1 = new TaskRepository("kind", "http://a");
		t1.setProperty(IRepositoryConstants.PROPERTY_URL, null);
		TaskRepository t2 = new TaskRepository("kind", "http://a");

		assertTrue(sorter.compare(null, t1, t2) > 0);
	}

}

Back to the top