Skip to main content
summaryrefslogtreecommitdiffstats
blob: 98c3858af2e1879f13491ef87a85687957b30414 (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
123
124
125
/*******************************************************************************
 * Copyright (c) 2016 Obeo.
 * 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
 *******************************************************************************/
package org.eclipse.emf.compare.ide.ui.tests.git.framework.internal;

import com.google.common.collect.Lists;

import java.util.List;

import org.eclipse.emf.compare.ide.ui.tests.framework.AbstractCompareTestCaseJUnitBlock;
import org.eclipse.emf.compare.ide.ui.tests.framework.EMFCompareTestConfiguration;
import org.eclipse.emf.compare.ide.ui.tests.framework.ResolutionStrategyID;
import org.eclipse.emf.compare.ide.ui.tests.git.framework.GitMergeStrategyID;
import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitCherryPick;
import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitCompare;
import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitInput;
import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitMerge;
import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitRebase;
import org.eclipse.emf.compare.ide.ui.tests.git.framework.annotations.GitTest;
import org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.statements.GitCherryPickStatement;
import org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.statements.GitCompareStatement;
import org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.statements.GitMergeStatement;
import org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.statements.GitRebaseStatement;
import org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.statements.GitTestStatement;
import org.junit.Assert;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;

/**
 * EMFCompare specific {@link BlockJUnit4ClassRunner} used for Git comparisons.
 * 
 * @author <a href="mailto:mathieu.cartaud@obeo.fr">Mathieu Cartaud</a>
 */
public class GitTestCaseJUnitBlock extends AbstractCompareTestCaseJUnitBlock {

	/** The merge strategy to use for the test. */
	private GitMergeStrategyID mergeStrategy;

	/**
	 * Constructor for the classic (no Git) comparison statement.
	 * 
	 * @param klass
	 *            The test class
	 * @param resolutionStrategy
	 *            The resolution strategy used for this test
	 * @param configuration
	 *            EMFCompare configurations for this test
	 * @param mergeStrategy
	 *            The merge strategy to use for this test.
	 * @throws InitializationError
	 *             If something went wrong during test initialization
	 */
	public GitTestCaseJUnitBlock(Class<?> klass, ResolutionStrategyID resolutionStrategy,
			EMFCompareTestConfiguration configuration, GitMergeStrategyID mergeStrategy)
			throws InitializationError {
		super(klass, resolutionStrategy, configuration);
		this.mergeStrategy = mergeStrategy;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.junit.runners.BlockJUnit4ClassRunner#computeTestMethods()
	 */
	@Override
	protected List<FrameworkMethod> computeTestMethods() {
		final List<FrameworkMethod> allMethods = Lists
				.newArrayList(getTestClass().getAnnotatedMethods(GitCompare.class));
		allMethods.addAll(getTestClass().getAnnotatedMethods(GitMerge.class));
		allMethods.addAll(getTestClass().getAnnotatedMethods(GitCherryPick.class));
		allMethods.addAll(getTestClass().getAnnotatedMethods(GitRebase.class));
		allMethods.addAll(getTestClass().getAnnotatedMethods(GitTest.class));
		return allMethods;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.junit.runners.BlockJUnit4ClassRunner#methodBlock(org.junit.runners.model.FrameworkMethod)
	 */
	@Override
	protected Statement methodBlock(FrameworkMethod method) {
		Object testObject = null;
		try {
			testObject = createTest();
			// CHECKSTYLE:OFF JUnit createTest() method throws an Exception
		} catch (Exception e) {
			// CHECKSTYLE:ON
			Assert.fail(e.getMessage());
		}

		GitInput input = method.getAnnotation(GitInput.class);

		Statement result = null;
		if (input != null) {
			if (method.getAnnotation(GitCompare.class) != null) {
				result = new GitCompareStatement(testObject, method, resolutionStrategy, configuration,
						input.value());
			} else if (method.getAnnotation(GitMerge.class) != null) {
				result = new GitMergeStatement(testObject, method, resolutionStrategy, configuration,
						mergeStrategy, input.value());
			} else if (method.getAnnotation(GitCherryPick.class) != null) {
				result = new GitCherryPickStatement(testObject, method, resolutionStrategy, configuration,
						mergeStrategy, input.value());
			} else if (method.getAnnotation(GitRebase.class) != null) {
				result = new GitRebaseStatement(testObject, method, resolutionStrategy, configuration,
						mergeStrategy, input.value());
			} else if (method.getAnnotation(GitTest.class) != null) {
				result = new GitTestStatement(testObject, method, resolutionStrategy, configuration,
						input.value());
			}
		}
		return result;
	}

}

Back to the top