Skip to main content
summaryrefslogtreecommitdiffstats
blob: 74af431aa971ee79f000965e99dea51100c0c7be (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
/*******************************************************************************
 * Copyright (c) 2014 The Eclipse Foundation and others.
 * 
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * https://www.eclipse.org/legal/epl-2.0
 * 
 * SPDX-License-Identifier: EPL-2.0
 *
 *     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