Просмотр исходного кода

Some refactorings in test cases.

tomqc86@googlemail.com 13 лет назад
Родитель
Сommit
ddf023be52

+ 39 - 0
test-plugins/org.yakindu.sct.refactoring.tests/src/org/yakindu/sct/refactoring/refactor/RefactoringTest.java

@@ -0,0 +1,39 @@
+package org.yakindu.sct.refactoring.refactor;
+
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.eclipse.xtext.EcoreUtil2;
+import org.eclipse.xtext.parser.IParser;
+import org.yakindu.sct.model.sgraph.SpecificationElement;
+import org.yakindu.sct.model.sgraph.Statechart;
+import org.yakindu.sct.model.stext.resource.impl.StextResource;
+import org.yakindu.sct.refactoring.refactor.util.SctEqualityHelper;
+import org.yakindu.sct.test.models.RefactoringTestModels;
+
+import com.google.inject.Inject;
+
+public class RefactoringTest {
+
+	@Inject
+	protected IParser parser;
+	
+	@Inject
+	protected RefactoringTestModels models;
+
+	protected void compareStatecharts(Statechart initial, Statechart expected) {
+		SctEqualityHelper equalityHelper = new SctEqualityHelper();
+		if (!equalityHelper.equals(initial, expected)) {
+			Assert.fail("Equality check on statecharts failed!");
+		}
+	}
+
+	protected void parseAllSpecifications(Statechart sct) {
+		List<SpecificationElement> allSpecElements = EcoreUtil2.getAllContentsOfType(sct, SpecificationElement.class);
+		for (SpecificationElement specificationElement : allSpecElements) {
+			((StextResource)sct.eResource()).parseSpecificationElement(specificationElement);
+		}
+	}
+
+}

+ 3 - 35
test-plugins/org.yakindu.sct.refactoring.tests/src/org/yakindu/sct/refactoring/refactor/RenameRefactoringTest.java

@@ -14,32 +14,22 @@ import static org.junit.Assert.fail;
 import static org.yakindu.sct.test.models.RefactoringTestModels.INITIAL_STATECHART;
 import static org.yakindu.sct.test.models.RefactoringTestModels.RENAMING;
 
-import java.util.List;
 
-import junit.framework.Assert;
 
 import org.eclipse.emf.common.util.EList;
-import org.eclipse.xtext.EcoreUtil2;
 import org.eclipse.xtext.junit4.InjectWith;
 import org.eclipse.xtext.junit4.XtextRunner;
-import org.eclipse.xtext.parser.IParser;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.yakindu.sct.model.sgraph.Event;
 import org.yakindu.sct.model.sgraph.Scope;
-import org.yakindu.sct.model.sgraph.SpecificationElement;
 import org.yakindu.sct.model.sgraph.Statechart;
 import org.yakindu.sct.model.sgraph.Variable;
 import org.yakindu.sct.model.sgraph.resource.AbstractSCTResource;
-import org.yakindu.sct.model.stext.resource.impl.StextResource;
 import org.yakindu.sct.model.stext.stext.InterfaceScope;
 import org.yakindu.sct.refactoring.refactor.impl.RenameRefactoring;
-import org.yakindu.sct.refactoring.refactor.util.SctEqualityHelper;
-import org.yakindu.sct.refactoring.refactor.util.TestHelper;
-import org.yakindu.sct.refactoring.refactor.util.TestInjectorProvider;
-import org.yakindu.sct.test.models.RefactoringTestModels;
+import org.yakindu.sct.test.models.TestModelInjectorProvider;
 
-import com.google.inject.Inject;
 
 /**
  * Tests for {@link RenameRefactoring}.
@@ -48,23 +38,8 @@ import com.google.inject.Inject;
  * 
  */
 @RunWith(XtextRunner.class)
-@InjectWith(TestInjectorProvider.class)
-public class RenameRefactoringTest {
-
-	@Inject
-	protected IParser parser;
-
-	@Inject
-	protected RefactoringTestModels models;
-
-	protected TestHelper helper = new TestHelper();
-
-	protected void compareStatecharts(Statechart initial, Statechart expected) {
-		SctEqualityHelper equalityHelper = new SctEqualityHelper();
-		if (!equalityHelper.equals(initial, expected)) {
-			Assert.fail("Equality check on statecharts failed!");
-		}
-	}
+@InjectWith(TestModelInjectorProvider.class)
+public class RenameRefactoringTest extends RefactoringTest {
 
 	@Test
 	public void testRenameVariable() {
@@ -166,12 +141,5 @@ public class RenameRefactoringTest {
 	public void testNoRenamingIntoExistingName() {
 		fail("Not yet implemented.");
 	}
-	
-	private void parseAllSpecifications(Statechart sct) {
-		List<SpecificationElement> allSpecElements = EcoreUtil2.getAllContentsOfType(sct, SpecificationElement.class);
-		for (SpecificationElement specificationElement : allSpecElements) {
-			((StextResource)sct.eResource()).parseSpecificationElement(specificationElement);
-		}
-	}
 
 }

+ 14 - 34
test-plugins/org.yakindu.sct.refactoring.tests/src/org/yakindu/sct/refactoring/refactor/StateBasedRefactoringTest.java

@@ -17,19 +17,11 @@ import junit.framework.Assert;
 import org.eclipse.xtext.EcoreUtil2;
 import org.eclipse.xtext.junit4.InjectWith;
 import org.eclipse.xtext.junit4.XtextRunner;
-import org.eclipse.xtext.parser.IParser;
 import org.junit.runner.RunWith;
-import org.yakindu.sct.model.sgraph.SpecificationElement;
 import org.yakindu.sct.model.sgraph.State;
 import org.yakindu.sct.model.sgraph.Statechart;
 import org.yakindu.sct.model.sgraph.resource.AbstractSCTResource;
-import org.yakindu.sct.model.stext.resource.impl.StextResource;
-import org.yakindu.sct.refactoring.refactor.util.SctEqualityHelper;
-import org.yakindu.sct.refactoring.refactor.util.TestHelper;
-import org.yakindu.sct.refactoring.refactor.util.TestInjectorProvider;
-import org.yakindu.sct.test.models.RefactoringTestModels;
-
-import com.google.inject.Inject;
+import org.yakindu.sct.test.models.TestModelInjectorProvider;
 
 /**
  * Base test class for state based refactorings.
@@ -38,30 +30,15 @@ import com.google.inject.Inject;
  * 
  */
 @RunWith(XtextRunner.class)
-@InjectWith(TestInjectorProvider.class)
-public abstract class StateBasedRefactoringTest {
-
-	@Inject
-	protected IParser parser;
-
-	@Inject
-	protected RefactoringTestModels models;
-
-	protected TestHelper helper = new TestHelper();
-
-	protected void compareStatecharts(Statechart initial, Statechart expected) {
-		SctEqualityHelper equalityHelper = new SctEqualityHelper();
-		if (!equalityHelper.equals(initial, expected)) {
-			Assert.fail("Equality check on statecharts failed!");
-		}
-	}
+@InjectWith(TestModelInjectorProvider.class)
+public abstract class StateBasedRefactoringTest extends RefactoringTest {
 
 	protected void testRefactoringOnState(String pathToInitialSct,
 			String pathToExpectedSct, String stateName) {
 		Statechart initial = models
 				.loadStatechartFromResource(pathToInitialSct);
 
-		State state = helper.getStateByName(initial, stateName);
+		State state = getStateByName(initial, stateName);
 
 		AbstractRefactoring<?> refactoring = getRefactoring(state);
 		((AbstractSCTResource) initial.eResource()).setSerializerEnabled(true);
@@ -82,7 +59,7 @@ public abstract class StateBasedRefactoringTest {
 		Statechart initial = models
 				.loadStatechartFromResource(pathToInitialSct);
 
-		State state = helper.getStateByName(initial, stateName);
+		State state = getStateByName(initial, stateName);
 
 		AbstractRefactoring<?> refactoring = getRefactoring(state);
 		if (expectedResult) {
@@ -93,12 +70,15 @@ public abstract class StateBasedRefactoringTest {
 		}
 	}
 
-	private void parseAllSpecifications(Statechart sct) {
-		List<SpecificationElement> allSpecElements = EcoreUtil2.getAllContentsOfType(sct, SpecificationElement.class);
-		for (SpecificationElement specificationElement : allSpecElements) {
-			((StextResource)sct.eResource()).parseSpecificationElement(specificationElement);
+	protected abstract AbstractRefactoring<?> getRefactoring(State state);
+	
+	protected State getStateByName(Statechart statechart, String name) {
+		List<State> allStates = EcoreUtil2.getAllContentsOfType(statechart, State.class);
+		for (State state : allStates) {
+			if (state.getName().equals(name)) {
+				return state;
+			}
 		}
+		return null;
 	}
-
-	protected abstract AbstractRefactoring<?> getRefactoring(State state);
 }

+ 5 - 5
test-plugins/org.yakindu.sct.refactoring.tests/src/org/yakindu/sct/refactoring/refactor/UnfoldEntryActionsRefactoringTest.java

@@ -31,10 +31,10 @@ public class UnfoldEntryActionsRefactoringTest extends
 	@Test
 	public void testUnfoldEntryActions() {
 
-		testRefactoringOnState(UNFOLD_ENTRY_ACTIONS
-				+ INITIAL_STATECHART,
-				UNFOLD_ENTRY_ACTIONS
-						+ EXPECTED_STATECHART, "B");
+		testRefactoringOnState(
+				UNFOLD_ENTRY_ACTIONS + INITIAL_STATECHART,
+				UNFOLD_ENTRY_ACTIONS + EXPECTED_STATECHART,
+				"B");
 	}
 	
 	@Test
@@ -65,7 +65,7 @@ public class UnfoldEntryActionsRefactoringTest extends
 	}
 
 	@Override
-	protected AbstractRefactoring<?> getRefactoring(State state) {
+	protected AbstractRefactoring<State> getRefactoring(State state) {
 		UnfoldEntryActionsRefactoring unfoldEntryActionsRefactoring = new UnfoldEntryActionsRefactoring();
 		unfoldEntryActionsRefactoring.setContextObjects(Lists.newArrayList(state));
 		return unfoldEntryActionsRefactoring;

+ 8 - 1
test-plugins/org.yakindu.sct.refactoring.tests/src/org/yakindu/sct/refactoring/refactor/util/SctEqualityHelper.java

@@ -7,6 +7,13 @@ import org.eclipse.emf.ecore.util.EcoreUtil.EqualityHelper;
 import org.eclipse.emf.ecore.util.FeatureMap;
 import org.eclipse.emf.ecore.util.FeatureMapUtil;
 
+/**
+ * Modified {@link EqualityHelper} for test cases to ignore whitespaces in string comparisons and
+ * resolve proxy elements when necessary.
+ * 
+ * @author thomas kutz - Initial contribution and API
+ *
+ */
 public class SctEqualityHelper extends EqualityHelper{
 
 	@Override
@@ -62,6 +69,6 @@ public class SctEqualityHelper extends EqualityHelper{
 	}
 
 	private String removeWhitespaces(String input) {
-		return input.replaceAll(" ", "");
+		return input.replaceAll("\\s", "");
 	}
 }

+ 0 - 34
test-plugins/org.yakindu.sct.refactoring.tests/src/org/yakindu/sct/refactoring/refactor/util/TestHelper.java

@@ -1,34 +0,0 @@
-/**
- * Copyright (c) 2013 committers of YAKINDU 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:
- * 	committers of YAKINDU - initial API and implementation
- * 
- */
-package org.yakindu.sct.refactoring.refactor.util;
-
-import java.util.List;
-
-import org.eclipse.xtext.EcoreUtil2;
-import org.yakindu.sct.model.sgraph.State;
-import org.yakindu.sct.model.sgraph.Statechart;
-/**
- * 
- * @author thomas kutz - Initial contribution and API
- * 
- */
-public class TestHelper {
-
-	public State getStateByName(Statechart statechart, String name) {
-		List<State> allStates = EcoreUtil2.getAllContentsOfType(statechart, State.class);
-		for (State state : allStates) {
-			if (state.getName().equals(name)) {
-				return state;
-			}
-		}
-		return null;
-	}
-}

+ 0 - 32
test-plugins/org.yakindu.sct.refactoring.tests/src/org/yakindu/sct/refactoring/refactor/util/TestInjectorProvider.java

@@ -1,32 +0,0 @@
-/**
- * Copyright (c) 2013 committers of YAKINDU 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:
- * 	committers of YAKINDU - initial API and implementation
- * 
- */
-package org.yakindu.sct.refactoring.refactor.util;
-
-import org.eclipse.xtext.junit4.IInjectorProvider;
-import org.yakindu.sct.model.sexec.transformation.SequencerModule;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-/**
- * 
- * @author thomas kutz - Initial contribution and API
- * 
- */
-//TODO COpied
-public class TestInjectorProvider implements IInjectorProvider{
-
-	@Override
-	public Injector getInjector() {
-		// use own runtime module here if required
-		return Guice.createInjector(new SequencerModule());
-	}
-
-}