Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Dmitriev2014-08-14 15:40:04 +0000
committerSam Davis2014-08-21 00:01:55 +0000
commit9b0546b401b13763b27f9a0d1c34cf326414618b (patch)
tree8b362df3166185ca5dc370e00e1b33015fa2cc58 /org.eclipse.mylyn.gerrit.core.tests
parent6bdfd9b9060c406b804b809114b66084b3e6e0d9 (diff)
downloadorg.eclipse.mylyn.reviews-9b0546b401b13763b27f9a0d1c34cf326414618b.tar.gz
org.eclipse.mylyn.reviews-9b0546b401b13763b27f9a0d1c34cf326414618b.tar.xz
org.eclipse.mylyn.reviews-9b0546b401b13763b27f9a0d1c34cf326414618b.zip
430926: Sort projects list alphabetically when importing from Gerrit
Order of the projects list returned by GerritClient#getVisibleProjects is more or less undetermined. The order of projects is one of the entries in the intermediate HashMap used to parse Gerrit server response. With this change projects list returned by GerritClient#getVisibleProjects is explicitly sorted by project name. Ordering is ascending, case insensitive with nulls last. This change will indirectly make projects list alphabetically sorted on the project selection page of the "Projects from Git" wizard with Gerrit as the source repository. Bug: 430926 Change-Id: Ia1e5aa3fe833013cdd4446eae8e42ce758b5c2f5 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=430926 Signed-off-by: Vadim Dmitriev <dmgloss@mail.ru>
Diffstat (limited to 'org.eclipse.mylyn.gerrit.core.tests')
-rw-r--r--org.eclipse.mylyn.gerrit.core.tests/src/org/eclipse/mylyn/internal/gerrit/core/client/ProjectByNameComparatorTest.java52
1 files changed, 52 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.gerrit.core.tests/src/org/eclipse/mylyn/internal/gerrit/core/client/ProjectByNameComparatorTest.java b/org.eclipse.mylyn.gerrit.core.tests/src/org/eclipse/mylyn/internal/gerrit/core/client/ProjectByNameComparatorTest.java
new file mode 100644
index 000000000..bcf393109
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.core.tests/src/org/eclipse/mylyn/internal/gerrit/core/client/ProjectByNameComparatorTest.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2014 The Eclipse Foundation 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:
+ * Vadim Dmitriev - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.gerrit.core.client;
+
+import java.util.Arrays;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.google.gerrit.reviewdb.Project;
+import com.google.gerrit.reviewdb.Project.NameKey;
+
+/**
+ * @author Vadim Dmitriev
+ */
+public class ProjectByNameComparatorTest {
+
+ @Test
+ public void testCompare() {
+ String[] initialOrder = new String[] { "a", null, "bf", "Ba", "de", "f", "1" };
+ String[] expectedOrder = new String[] { "1", "a", "Ba", "bf", "de", "f", null };
+
+ Project[] projects = fromNames(initialOrder);
+ Arrays.sort(projects, new ProjectByNameComparator());
+ Assert.assertArrayEquals(expectedOrder, fromProjects(projects));
+ }
+
+ private static Project[] fromNames(String... names) {
+ Project[] projects = new Project[names.length];
+ for (int i = 0; i < names.length; i++) {
+ projects[i] = new Project(new NameKey(names[i]));
+ }
+ return projects;
+ }
+
+ private static String[] fromProjects(Project... projects) {
+ String[] names = new String[projects.length];
+ for (int i = 0; i < projects.length; i++) {
+ names[i] = projects[i].getName();
+ }
+ return names;
+ }
+}

Back to the top