Преглед изворни кода

Some refactorings in test classes.

tomqc86@googlemail.com пре 12 година
родитељ
комит
02dd53a119

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

@@ -13,6 +13,11 @@ package org.yakindu.sct.refactoring.refactor;
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 import org.junit.runners.Suite.SuiteClasses;
+import org.yakindu.sct.refactoring.refactor.impl.FoldIncomingActionsRefactoringTest;
+import org.yakindu.sct.refactoring.refactor.impl.FoldOutgoingActionsRefactoringTest;
+import org.yakindu.sct.refactoring.refactor.impl.RenameRefactoringTest;
+import org.yakindu.sct.refactoring.refactor.impl.UnfoldEntryActionsRefactoringTest;
+import org.yakindu.sct.refactoring.refactor.impl.UnfoldExitActionsRefactoringTest;
 
 /**
  * 

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

@@ -1,14 +1,9 @@
 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.refactoring.test.models.RefactoringTestModels;
 
@@ -28,12 +23,4 @@ public class RefactoringTest {
 			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);
-		}
-	}
-
 }

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

@@ -41,16 +41,15 @@ public abstract class StateBasedRefactoringTest extends RefactoringTest {
 		State state = getStateByName(initial, stateName);
 
 		AbstractRefactoring<?> refactoring = getRefactoring(state);
-		((AbstractSCTResource) initial.eResource()).setSerializerEnabled(true);
+		AbstractSCTResource initialRes = (AbstractSCTResource) initial.eResource();
+		initialRes.setSerializerEnabled(true);
 		refactoring.internalExecute();
-		((AbstractSCTResource) initial.eResource()).setSerializerEnabled(false);
+		initialRes.setSerializerEnabled(false);
+		initialRes.linkSpecificationElements();
 
 		Statechart expected = models
 				.loadStatechartFromResource(pathToExpectedSct);
 		
-		parseAllSpecifications(initial);
-		parseAllSpecifications(expected);
-		
 		compareStatecharts(initial, expected);
 	}
 	

+ 3 - 1
test-plugins/org.yakindu.sct.refactoring.tests/src/org/yakindu/sct/refactoring/refactor/FoldIncomingActionsRefactoringTest.java

@@ -8,7 +8,7 @@
  * 	committers of YAKINDU - initial API and implementation
  * 
  */
-package org.yakindu.sct.refactoring.refactor;
+package org.yakindu.sct.refactoring.refactor.impl;
 
 import static org.yakindu.sct.refactoring.test.models.RefactoringTestModels.EXPECTED_STATECHART;
 import static org.yakindu.sct.refactoring.test.models.RefactoringTestModels.FOLD_INCOMING_ACTIONS;
@@ -16,6 +16,8 @@ import static org.yakindu.sct.refactoring.test.models.RefactoringTestModels.INIT
 
 import org.junit.Test;
 import org.yakindu.sct.model.sgraph.State;
+import org.yakindu.sct.refactoring.refactor.AbstractRefactoring;
+import org.yakindu.sct.refactoring.refactor.StateBasedRefactoringTest;
 import org.yakindu.sct.refactoring.refactor.impl.FoldIncomingActionsRefactoring;
 
 import com.google.common.collect.Lists;

+ 3 - 1
test-plugins/org.yakindu.sct.refactoring.tests/src/org/yakindu/sct/refactoring/refactor/FoldOutgoingActionsRefactoringTest.java

@@ -8,7 +8,7 @@
  * 	committers of YAKINDU - initial API and implementation
  * 
  */
-package org.yakindu.sct.refactoring.refactor;
+package org.yakindu.sct.refactoring.refactor.impl;
 
 import static org.yakindu.sct.refactoring.test.models.RefactoringTestModels.EXPECTED_STATECHART;
 import static org.yakindu.sct.refactoring.test.models.RefactoringTestModels.FOLD_OUTGOING_ACTIONS;
@@ -16,6 +16,8 @@ import static org.yakindu.sct.refactoring.test.models.RefactoringTestModels.INIT
 
 import org.junit.Test;
 import org.yakindu.sct.model.sgraph.State;
+import org.yakindu.sct.refactoring.refactor.AbstractRefactoring;
+import org.yakindu.sct.refactoring.refactor.StateBasedRefactoringTest;
 import org.yakindu.sct.refactoring.refactor.impl.FoldOutgoingActionsRefactoring;
 
 import com.google.common.collect.Lists;

+ 31 - 45
test-plugins/org.yakindu.sct.refactoring.tests/src/org/yakindu/sct/refactoring/refactor/RenameRefactoringTest.java

@@ -8,29 +8,30 @@
  * 	committers of YAKINDU - initial API and implementation
  * 
  */
-package org.yakindu.sct.refactoring.refactor;
+package org.yakindu.sct.refactoring.refactor.impl;
 
 import static org.junit.Assert.fail;
 import static org.yakindu.sct.refactoring.test.models.RefactoringTestModels.INITIAL_STATECHART;
 import static org.yakindu.sct.refactoring.test.models.RefactoringTestModels.RENAMING;
 
-
-
 import org.eclipse.emf.common.util.EList;
 import org.eclipse.xtext.junit4.InjectWith;
 import org.eclipse.xtext.junit4.XtextRunner;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.yakindu.base.base.NamedElement;
 import org.yakindu.sct.model.sgraph.Event;
 import org.yakindu.sct.model.sgraph.Scope;
 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.stext.InterfaceScope;
-import org.yakindu.sct.refactoring.refactor.impl.RenameRefactoring;
+import org.yakindu.sct.refactoring.refactor.RefactoringTest;
 import org.yakindu.sct.test.models.TestModelInjectorProvider;
 
+import com.google.common.collect.Lists;
+
 
 /**
  * Tests for {@link RenameRefactoring}.
@@ -44,9 +45,9 @@ public class RenameRefactoringTest extends RefactoringTest {
 
 	@Test
 	public void testRenameVariable() {
+
 		Statechart initial = models.loadStatechartFromResource(RENAMING
 				+ INITIAL_STATECHART);
-
 		// get element to rename
 		Variable someVariable = null;
 		EList<Scope> scopes = initial.getScopes();
@@ -56,21 +57,10 @@ public class RenameRefactoringTest extends RefactoringTest {
 				someVariable = iScope.getVariables().get(0);
 			}
 		}
-
-		AbstractRefactoring<?> refactoring = new RenameRefactoring(
-				someVariable, "someNewVariableName");
-
-		((AbstractSCTResource) initial.eResource()).setSerializerEnabled(true);
-		refactoring.internalExecute();
-		((AbstractSCTResource) initial.eResource()).setSerializerEnabled(false);
-
 		Statechart expected = models.loadStatechartFromResource(RENAMING
 				+ "AfterRenamingVariable.sct");
 
-		parseAllSpecifications(initial);
-		parseAllSpecifications(expected);
-		
-		compareStatecharts(initial, expected);
+		testRenaming(initial, expected, someVariable, "someNewVariableName");
 	}
 
 	@Test
@@ -78,6 +68,9 @@ public class RenameRefactoringTest extends RefactoringTest {
 		Statechart initial = models.loadStatechartFromResource(RENAMING
 				+ INITIAL_STATECHART);
 
+		Statechart expected = models.loadStatechartFromResource(RENAMING
+				+ "AfterRenamingEvent.sct");
+
 		// get element to rename
 		Event someEvent1 = null;
 		EList<Scope> scopes = initial.getScopes();
@@ -91,21 +84,8 @@ public class RenameRefactoringTest extends RefactoringTest {
 				}
 			}
 		}
-
-		AbstractRefactoring<?> refactoring = new RenameRefactoring(someEvent1,
-				"someNewEventName");
-
-		((AbstractSCTResource) initial.eResource()).setSerializerEnabled(true);
-		refactoring.internalExecute();
-		((AbstractSCTResource) initial.eResource()).setSerializerEnabled(false);
-
-		Statechart expected = models.loadStatechartFromResource(RENAMING
-				+ "AfterRenamingEvent.sct");
-
-		parseAllSpecifications(initial);
-		parseAllSpecifications(expected);
 		
-		compareStatecharts(initial, expected);
+		testRenaming(initial, expected, someEvent1, "someNewEventName");
 	}
 
 	@Test
@@ -113,6 +93,9 @@ public class RenameRefactoringTest extends RefactoringTest {
 		Statechart initial = models.loadStatechartFromResource(RENAMING
 				+ INITIAL_STATECHART);
 
+		Statechart expected = models.loadStatechartFromResource(RENAMING
+				+ "AfterRenamingInterface.sct");
+
 		// get element to rename
 		InterfaceScope someInterface = null;
 		EList<Scope> scopes = initial.getScopes();
@@ -121,21 +104,8 @@ public class RenameRefactoringTest extends RefactoringTest {
 				someInterface = (InterfaceScope) scope;
 			}
 		}
-
-		AbstractRefactoring<?> refactoring = new RenameRefactoring(
-				someInterface, "someNewInterfaceName");
-
-		((AbstractSCTResource) initial.eResource()).setSerializerEnabled(true);
-		refactoring.internalExecute();
-		((AbstractSCTResource) initial.eResource()).setSerializerEnabled(false);
-
-		Statechart expected = models.loadStatechartFromResource(RENAMING
-				+ "AfterRenamingInterface.sct");
-
-		parseAllSpecifications(initial);
-		parseAllSpecifications(expected);
 		
-		compareStatecharts(initial, expected);
+		testRenaming(initial, expected, someInterface, "someNewInterfaceName");
 	}
 
 	@Ignore
@@ -143,5 +113,21 @@ public class RenameRefactoringTest extends RefactoringTest {
 	public void testNoRenamingIntoExistingName() {
 		fail("Not yet implemented.");
 	}
+	
+	private void testRenaming(Statechart initial, Statechart expected, NamedElement elementToRename, String newName) {
+		RenameRefactoring refactoring = new RenameRefactoring();
+		
+		refactoring.setContextObjects(Lists.newArrayList(elementToRename));
+		refactoring.setNewName(newName);
+
+		AbstractSCTResource initialRes = (AbstractSCTResource) initial.eResource();
+		initialRes.setSerializerEnabled(true);
+		refactoring.internalExecute();
+		initialRes.setSerializerEnabled(false);
+
+		initialRes.linkSpecificationElements();
+		
+		compareStatecharts(initial, expected);
+	}
 
 }

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

@@ -8,7 +8,7 @@
  * 	committers of YAKINDU - initial API and implementation
  * 
  */
-package org.yakindu.sct.refactoring.refactor;
+package org.yakindu.sct.refactoring.refactor.impl;
 
 import static org.yakindu.sct.refactoring.test.models.RefactoringTestModels.EXPECTED_STATECHART;
 import static org.yakindu.sct.refactoring.test.models.RefactoringTestModels.INITIAL_STATECHART;
@@ -16,6 +16,8 @@ import static org.yakindu.sct.refactoring.test.models.RefactoringTestModels.UNFO
 
 import org.junit.Test;
 import org.yakindu.sct.model.sgraph.State;
+import org.yakindu.sct.refactoring.refactor.AbstractRefactoring;
+import org.yakindu.sct.refactoring.refactor.StateBasedRefactoringTest;
 import org.yakindu.sct.refactoring.refactor.impl.UnfoldEntryActionsRefactoring;
 
 import com.google.common.collect.Lists;

+ 3 - 1
test-plugins/org.yakindu.sct.refactoring.tests/src/org/yakindu/sct/refactoring/refactor/UnfoldExitActionsRefactoringTest.java

@@ -8,7 +8,7 @@
  * 	committers of YAKINDU - initial API and implementation
  * 
  */
-package org.yakindu.sct.refactoring.refactor;
+package org.yakindu.sct.refactoring.refactor.impl;
 
 import static org.yakindu.sct.refactoring.test.models.RefactoringTestModels.EXPECTED_STATECHART;
 import static org.yakindu.sct.refactoring.test.models.RefactoringTestModels.INITIAL_STATECHART;
@@ -16,6 +16,8 @@ import static org.yakindu.sct.refactoring.test.models.RefactoringTestModels.UNFO
 
 import org.junit.Test;
 import org.yakindu.sct.model.sgraph.State;
+import org.yakindu.sct.refactoring.refactor.AbstractRefactoring;
+import org.yakindu.sct.refactoring.refactor.StateBasedRefactoringTest;
 import org.yakindu.sct.refactoring.refactor.impl.UnfoldExitActionsRefactoring;
 
 import com.google.common.collect.Lists;