Skip to main content
summaryrefslogtreecommitdiffstats
blob: c939488dcbbc7b575ac36cd7a0ae2de6e2eca4fe (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
/*******************************************************************************
 * Copyright (c) 2016 Obeo 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:
 *     Obeo - initial API and implementation
 *     Philip Langer - support more flexible parameters of test methods
 *******************************************************************************/
package org.eclipse.emf.compare.ide.ui.tests.git.framework.internal;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;

import java.util.Collection;
import java.util.List;

import org.eclipse.emf.compare.ide.ui.tests.framework.AbstractCompareStatement;
import org.eclipse.emf.compare.ide.ui.tests.framework.ResolutionStrategyID;
import org.eclipse.jgit.api.MergeResult;
import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.lib.Repository;
import org.junit.runners.model.FrameworkMethod;

public abstract class AbstractGitStatement extends AbstractCompareStatement {

	public AbstractGitStatement(Object testObject, FrameworkMethod test,
			ResolutionStrategyID resolutionStrategy, Class<?>[] disabledMatchEngineFactory,
			Class<?> diffEngine, Class<?> eqEngine, Class<?> reqEngine, Class<?> conflictDetector,
			Class<?>[] disabledPostProcessors) {
		super(testObject, test, resolutionStrategy, disabledMatchEngineFactory, diffEngine, eqEngine,
				reqEngine, conflictDetector, disabledPostProcessors);
	}

	protected Object[] createParameters(Class<?>[] paramTypes, GitTestSupport gitTestsSupport)
			throws Throwable {
		final Builder<Object> builder = ImmutableList.builder();
		for (Class<?> paramType : paramTypes) {
			if (paramType.equals(GitTestSupport.class)) {
				builder.add(gitTestsSupport);
			} else if (paramType.equals(MergeResult.class)) {
				builder.add(gitTestsSupport.getMergeResult());
			} else if (isCollectionCompatible(paramType)) {
				builder.add(gitTestsSupport.getProjects());
			} else if (paramType.equals(Repository.class)) {
				builder.add(gitTestsSupport.getRepository());
			} else if (paramType.equals(Status.class)) {
				builder.add(gitTestsSupport.getStatus());
			} else {
				throw new IllegalArgumentException(
						"Unsupported parameter type " + paramType.getCanonicalName()); //$NON-NLS-1$
			}
		}
		return builder.build().toArray();
	}

	private boolean isCollectionCompatible(Class<?> paramType) {
		return paramType.equals(Collection.class) || paramType.equals(List.class)
				|| paramType.equals(Iterable.class);
	}

}

Back to the top