Skip to main content
summaryrefslogtreecommitdiffstats
blob: 861b917140c86c140cfd33dd2a686911dcc6d6e3 (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
/*******************************************************************************
 * Copyright (c) 2017 Tasktop Technologies 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
 *
 *     Tasktop Technologies - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.internal.gerrit.core.remote;

import static java.util.Collections.emptyList;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.mylyn.reviews.core.model.IChange;
import org.junit.Test;

import com.google.gerrit.common.data.ChangeInfo;
import com.google.gerrit.reviewdb.Change.Id;

@SuppressWarnings("restriction")
public class GerritReviewRemoteFactoryTest {
	@Test
	public void isDependenciesDifferent() throws Exception {
		GerritReviewRemoteFactory factory = new GerritReviewRemoteFactory(mock(GerritRemoteFactoryProvider.class));

		assertFalse(factory.isDependenciesDifferent(emptyList(), emptyList()));
		assertFalse(factory.isDependenciesDifferent(changes(1), changeInfos(1)));
		assertFalse(factory.isDependenciesDifferent(changes(1, 2, 3), changeInfos(3, 1, 2)));

		assertTrue(factory.isDependenciesDifferent(changes(1), emptyList()));
		assertTrue(factory.isDependenciesDifferent(emptyList(), changeInfos(1)));
		assertTrue(factory.isDependenciesDifferent(changes(1), changeInfos(2)));
		assertTrue(factory.isDependenciesDifferent(changes(1), changeInfos(2, 3)));
		assertTrue(factory.isDependenciesDifferent(changes(1, 2), changeInfos(2, 3)));
	}

	private static List<IChange> changes(int... ids) {
		List<IChange> result = new ArrayList<>(ids.length);
		for (int id : ids) {
			IChange change = mock(IChange.class);
			when(change.getId()).thenReturn(Integer.toString(id));
			result.add(change);
		}
		return result;
	}

	private static List<ChangeInfo> changeInfos(int... ids) {
		List<ChangeInfo> result = new ArrayList<>(ids.length);
		for (int id : ids) {
			ChangeInfo changeInfo = mock(ChangeInfo.class);
			when(changeInfo.getId()).thenReturn(new Id(id));
			result.add(changeInfo);
		}
		return result;
	}
}

Back to the top