Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2010-08-20 19:29:34 -0400
committerStephan Herrmann2010-08-20 19:29:34 -0400
commita1919769c6f945e3ad6ebe1768b791fd6783ffe7 (patch)
tree501ee93d2cc0b6784d3f3c4a68d5e6293555e7ef
parent37a8e275f46e6bb30f5b4e32a034fe1eff9f9108 (diff)
downloadorg.eclipse.objectteams-a1919769c6f945e3ad6ebe1768b791fd6783ffe7.tar.gz
org.eclipse.objectteams-a1919769c6f945e3ad6ebe1768b791fd6783ffe7.tar.xz
org.eclipse.objectteams-a1919769c6f945e3ad6ebe1768b791fd6783ffe7.zip
re-enable a few tests which Jogeb commented out during his work (not interesting at that time).
only relevant change: do expect Info that this refactoring is not fully OT-aware (4 tests).
-rw-r--r--testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/move/MoveInstanceMethodTests.java485
1 files changed, 249 insertions, 236 deletions
diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/move/MoveInstanceMethodTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/move/MoveInstanceMethodTests.java
index 70b68428c..a336af26f 100644
--- a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/move/MoveInstanceMethodTests.java
+++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/move/MoveInstanceMethodTests.java
@@ -95,6 +95,21 @@ public class MoveInstanceMethodTests extends RefactoringTest
endColumn, newReceiverType, newReceiverName, null,
inlineDelegator, removeDelegator, expectWarning);
}
+
+ private void performAndCheckSelectedCU_passing_std_info(
+ String[] cuQNames, String selectionCuQName,
+ int startLine, int startColumn, int endLine, int endColumn,
+ int newReceiverType, String newReceiverName,
+ boolean inlineDelegator, boolean removeDelegator, boolean expectWarning)
+ throws Exception
+ {
+ int selectionCuIndex = firstIndexOf(selectionCuQName, cuQNames);
+ Assert.isTrue(selectionCuIndex != -1,
+ "parameter selectionCuQName must match some String in cuQNames.");
+ performRefactoring_passing_expecting_specific_warning(cuQNames, selectionCuIndex, startLine, startColumn, endLine,
+ endColumn, newReceiverType, newReceiverName, null,
+ inlineDelegator, removeDelegator, "The 'Move Instance Method' Refactoring is not yet fully OT-aware!");
+ }
private int firstIndexOf(String one, String[] others)
{
@@ -150,7 +165,12 @@ public class MoveInstanceMethodTests extends RefactoringTest
}
preconditionResult.merge(ref.checkFinalConditions(new NullProgressMonitor()));
if (!expectWarning) {
- assertTrue("precondition was supposed to pass", preconditionResult
+ if (!preconditionResult.isOK()) {
+ System.out.println(getName()+":"+preconditionResult);
+ System.out.println("Error:"+preconditionResult.getMessageMatchingSeverity(RefactoringStatus.ERROR));
+ System.out.println("Warning:"+preconditionResult.getMessageMatchingSeverity(RefactoringStatus.WARNING));
+ }
+ assertTrue("precondition was supposed to pass", preconditionResult
.isOK());
assertFalse("no warnings expected", preconditionResult.hasWarning());
@@ -166,6 +186,59 @@ public class MoveInstanceMethodTests extends RefactoringTest
getFileContents(outputTestFileName), cus[idx].getSource());
}
}
+
+ private void performRefactoring_passing_expecting_specific_warning(
+ String[] cuQNames, int selectionCuIndex,
+ int startLine, int startColumn, int endLine, int endColumn,
+ int newReceiverType, String newReceiverName, String newMethodName,
+ boolean inlineDelegator, boolean removeDelegator, String expectedWarning)
+ throws Exception
+ {
+ Assert.isTrue(0 <= selectionCuIndex
+ && selectionCuIndex < cuQNames.length);
+
+ toSucceed = true;
+
+ ICompilationUnit[] cus = createCUs(cuQNames);
+ ICompilationUnit selectionCu = cus[selectionCuIndex];
+
+ ISourceRange selection = TextRangeUtil.getSelection(selectionCu,
+ startLine, startColumn, endLine, endColumn);
+ IMethod method = getMethod(selectionCu, selection);
+ assertNotNull(method);
+ MoveInstanceMethodProcessor refProc = new MoveInstanceMethodProcessor(
+ method,
+ JavaPreferencesSettings.getCodeGenerationSettings(selectionCu.getJavaProject()));
+ Refactoring ref= new MoveRefactoring(refProc);
+
+ assertNotNull("refactoring should be created", ref);
+ RefactoringStatus preconditionResult= ref
+ .checkInitialConditions(new NullProgressMonitor());
+
+ assertTrue("activation was supposed to be successful",
+ preconditionResult.isOK());
+
+ chooseNewReceiver(refProc, newReceiverType, newReceiverName);
+
+ refProc.setInlineDelegator(inlineDelegator);
+ refProc.setRemoveDelegator(removeDelegator);
+ refProc.setDeprecateDelegates(false);
+ if (newMethodName != null)
+ {
+ refProc.setMethodName(newMethodName);
+ }
+ preconditionResult.merge(ref.checkFinalConditions(new NullProgressMonitor()));
+ assertTrue("expected a warning", preconditionResult.hasInfo());
+ assertEquals("expected specific warning", expectedWarning, preconditionResult.getMessageMatchingSeverity(RefactoringStatus.INFO));
+
+ performChange(ref, false);
+ for (int idx = 0; idx < cus.length; idx++)
+ {
+ String outputTestFileName = getOutputTestFileName(getSimpleName(cuQNames[idx]));
+ assertEqualLines("Incorrect inline in " + outputTestFileName,
+ getFileContents(outputTestFileName), cus[idx].getSource());
+ }
+ }
private void performAndCheckSelectedCU_failing(
String[] cuQNames, String selectionCuQName,
@@ -205,40 +278,33 @@ public class MoveInstanceMethodTests extends RefactoringTest
method,
JavaPreferencesSettings.getCodeGenerationSettings(selectionCu.getJavaProject()));
Refactoring ref= new MoveRefactoring(refProc);
- if (ref == null)
- {
- assertTrue(errorCode != 0);
- }
- else
- {
- RefactoringStatus result= ref.checkInitialConditions(
- new NullProgressMonitor());
-
- if (!result.isOK())
- {
- assertEquals(errorCode, result.getEntryMatchingSeverity(
- RefactoringStatus.ERROR).getCode());
- return;
- }
- else
- {
- chooseNewReceiver(refProc, newReceiverType, newReceiverName);
-
- refProc.setInlineDelegator(inlineDelegator);
- refProc.setRemoveDelegator(removeDelegator);
- refProc.setDeprecateDelegates(false);
- if (newMethodName != null)
- refProc.setMethodName(newMethodName);
-
- result.merge(ref
- .checkFinalConditions(new NullProgressMonitor()));
-
- assertTrue("precondition checking is expected to fail.", !result.isOK());
- assertNotNull("precondition result is expected to contain an error.", result.getEntryMatchingSeverity(RefactoringStatus.ERROR));
- assertEquals(errorCode, result.getEntryMatchingSeverity(
- RefactoringStatus.ERROR).getCode());
- }
- }
+ RefactoringStatus result= ref.checkInitialConditions(
+ new NullProgressMonitor());
+
+ if (!result.isOK())
+ {
+ assertEquals(errorCode, result.getEntryMatchingSeverity(
+ RefactoringStatus.ERROR).getCode());
+ return;
+ }
+ else
+ {
+ chooseNewReceiver(refProc, newReceiverType, newReceiverName);
+
+ refProc.setInlineDelegator(inlineDelegator);
+ refProc.setRemoveDelegator(removeDelegator);
+ refProc.setDeprecateDelegates(false);
+ if (newMethodName != null)
+ refProc.setMethodName(newMethodName);
+
+ result.merge(ref
+ .checkFinalConditions(new NullProgressMonitor()));
+
+ assertTrue("precondition checking is expected to fail.", !result.isOK());
+ assertNotNull("precondition result is expected to contain an error.", result.getEntryMatchingSeverity(RefactoringStatus.ERROR));
+ assertEquals(errorCode, result.getEntryMatchingSeverity(
+ RefactoringStatus.ERROR).getCode());
+ }
}
private void performConditionChecking_warnings(
@@ -267,38 +333,31 @@ public class MoveInstanceMethodTests extends RefactoringTest
method,
JavaPreferencesSettings.getCodeGenerationSettings(selectionCu.getJavaProject()));
Refactoring ref = new MoveRefactoring(refProc);
- if (ref == null)
- {
- assertTrue(errorCode != 0);
- }
- else
- {
- RefactoringStatus result = ref.checkInitialConditions(
- new NullProgressMonitor());
- if (!result.isOK())
- {
- assertEquals(errorCode, result.getEntryMatchingSeverity(
- RefactoringStatus.ERROR).getCode());
- return;
- }
- else
- {
- chooseNewReceiver(refProc, newReceiverType, newReceiverName);
-
- refProc.setInlineDelegator(inlineDelegator);
- refProc.setRemoveDelegator(removeDelegator);
- refProc.setDeprecateDelegates(false);
- if (newMethodName != null)
- refProc.setMethodName(newMethodName);
-
- result.merge(ref
- .checkFinalConditions(new NullProgressMonitor()));
-
- assertTrue("warnings expected", result.hasWarning());
- assertEquals(errorCode, result.getEntryMatchingSeverity(
- RefactoringStatus.WARNING).getCode());
- }
- }
+ RefactoringStatus result = ref.checkInitialConditions(
+ new NullProgressMonitor());
+ if (!result.isOK())
+ {
+ assertEquals(errorCode, result.getEntryMatchingSeverity(
+ RefactoringStatus.ERROR).getCode());
+ return;
+ }
+ else
+ {
+ chooseNewReceiver(refProc, newReceiverType, newReceiverName);
+
+ refProc.setInlineDelegator(inlineDelegator);
+ refProc.setRemoveDelegator(removeDelegator);
+ refProc.setDeprecateDelegates(false);
+ if (newMethodName != null)
+ refProc.setMethodName(newMethodName);
+
+ result.merge(ref
+ .checkFinalConditions(new NullProgressMonitor()));
+
+ assertTrue("warnings expected", result.hasWarning());
+ assertEquals(errorCode, result.getEntryMatchingSeverity(
+ RefactoringStatus.WARNING).getCode());
+ }
}
private ICompilationUnit[] createCUs(String[] qualifiedNames)
@@ -379,175 +438,129 @@ public class MoveInstanceMethodTests extends RefactoringTest
// TODO(SH): more tests for combinations of inline,removeDelegate!
/* Testing receiver types */
- // TODO: commented passing tests
- // public void testFieldNewReceiver() throws Exception
- // {
- // performAndCheckSelectedCU_passing(
- // new String[] {"p.A", "p.B"}, "p.A",
- // 7, 17, 7, 19, FIELD, "b", true, true, true);// warn:
- // change-field-to-default-vis
- // }
- //
- // public void testParameterNewReceiver() throws Exception
- // {
- // performAndCheckSelectedCU_passing(
- // new String[] {"p.A", "p.B"}, "p.A",
- // 5, 17, 5, 19, PARAMETER, "b", true, true, false);
- // }
- //
- // /* Testing team classes */
- // public void testTeamclass1() throws Exception
- // {
- // performAndCheckSelectedCU_passing(
- // new String[] {"p.T", "p.O"}, "p.O",
- // 7, 17, 7, 20, FIELD, "_t", true, true, true);// warn:
- // change-field-to-default-vis
- // }
- //
- // public void testTeamclass2() throws Exception
- // {
- // performAndCheckSelectedCU_passing(
- // new String[] {"p.T", "p.O"}, "p.O",
- // 5, 17, 5, 20, PARAMETER, "t", false, false, false);
- // }
- //
- // /* Testing role classes */
- // public void testRoleclass1() throws Exception
- // {
- // performAndCheckSelectedCU_passing(
- // new String[] {"p.T", "p.O"}, "p.O",
- // 8, 17, 8, 20, FIELD, "_r", true, false, false);
- // }
- //
- // public void testRoleclass2() throws Exception
- // {
- // performAndCheckSelectedCU_passing(
- // new String[] {"p.T", "p.O"}, "p.O",
- // 7, 17, 7, 20, PARAMETER, "r", true, false, false);
- // }
- //
- // /* Testing nested teams */
- // public void testNestedTeam1() throws Exception
- // {
- // performAndCheckSelectedCU_passing(
- // new String[] {"p.T", "p.O"}, "p.O",
- // 8, 17, 8, 20, FIELD, "_nT", true, false, false);
- // }
- //
- // public void testNestedTeam2() throws Exception
- // {
- // performAndCheckSelectedCU_passing(
- // new String[] {"p.T", "p.O"}, "p.O",
- // 7, 17, 7, 20, PARAMETER, "nT", true, false, false);
- // }
- //
- // /* Testing role files */
- // //TODO(gbr) implement tests for role files
- // // public void testRoleFile1() throws Exception
- // // {
- // // }
- // //
- // // public void testRoleFile2() throws Exception
- // // {
- // // }
- //
- // public void testRoleClassWithLongMethodSpecsInCallinBinding()
- // throws Exception
- // {
- // performConditionChecking_warnings(
- // new String[] {"p.O", "p.S", "p.B", "p.T"}, "p.O",
- // 8, 17, 8, 18, FIELD, "_s", null, true, true,
- // // FIXME(SH):
- // //OTRefactoringStatusCodes.OVERLOADING
- // -1
- // );
- // }
- //
- // public void testRoleClassWithLongMethodSpecsInCalloutBinding()
- // throws Exception
- // {
- // performConditionChecking_warnings(
- // new String[] {"p.O", "p.S", "p.B", "p.T"}, "p.O",
- // 8, 17, 8, 18, FIELD, "_s", null, true, true,
- // // FIXME(SH):
- // //OTRefactoringStatusCodes.OVERLOADING
- // -1
- // );
- // }
- //
- // public void testExplicitlyInheritedRoleClassWithLongMethodSpecs()
- // throws Exception
- // {
- // performConditionChecking_warnings(
- // new String[] {"p.O", "p.S", "p.B", "p.T"}, "p.O",
- // 8, 17, 8, 18, FIELD, "_s", null, true, true,
- // //FIXME(SH):
- // //OTRefactoringStatusCodes.OVERLOADING
- // -1
- // );
- // }
- // public void testImplicitlyInheritedRoleClassWithLongMethodSpecs()
- // throws Exception
- // {
- // performConditionChecking_warnings(
- // new String[] {"p.O", "p.S", "p.B", "p.T1", "p.T2"}, "p.O",
- // 8, 17, 8, 18, FIELD, "_s", null, true, true,
- // // FIXME(SH):
- // //OTRefactoringStatusCodes.OVERLOADING
- // -1
- // );
- // }
- // public void testTargetMethodAccessesPrivateFeatureOfEnclosingType1()
- // throws Exception
- // {
- // performAndCheckSelectedCU_passing(
- // new String[] {"p.A", "p.B", "p.C"},
- // "p.A", 8, 17, 8, 19, FIELD, "_c",
- // true, true, true);//warn: move needs to open visibility of field
- // }
- // public void testTargetMethodAccessesPrivateFeatureOfEnclosingType2()
- // throws Exception
- // {
- // performAndCheckSelectedCU_passing(
- // new String[] {"p.A", "p.B", "p.C"},
- // "p.A", 7, 17, 7, 19, PARAMETER, "c",
- // true, true, true);//warn: move needs to open visibility of field
- // }
- // public void testTargetMethodAccessesProtectedFeatureOfEnclosingType1()
- // throws Exception
-// {
- // performAndCheckSelectedCU_passing(
- // new String[] {"p1.A", "p1.B", "p2.C"},
- // "p1.A", 10, 17, 10, 19, FIELD, "_c",
- // true, true, true);//warn: move needs to open visibility of field
-// }
- // public void testTargetMethodAccessesProtectedFeatureOfEnclosingType2()
- // throws Exception
- // {
- // performAndCheckSelectedCU_passing(
- // new String[] {"p1.A", "p1.B", "p2.C"},
- // "p1.A", 9, 17, 9, 19, PARAMETER, "c",
- // true, true, true);//warn: move needs to open visibility of field
- // }
-//
- // public void
- // testTargetMethodAccessesPackageVisibleFeatureOfEnclosingType1()
- // throws Exception
-// {
- // performAndCheckSelectedCU_passing(
- // new String[] {"p1.A", "p1.B", "p2.C"},
- // "p1.A", 10, 17, 10, 19, FIELD, "_c",
- // true, true, true);//warn: move needs to open visibility of field
- // }
- // public void
- // testTargetMethodAccessesPackageVisibleFeatureOfEnclosingType2()
- // throws Exception
- // {
- // performAndCheckSelectedCU_passing(
- // new String[] {"p1.A", "p1.B", "p2.C"},
- // "p1.A", 9, 17, 9, 19, PARAMETER, "c",
- // true, true, true);//warn: move needs to open visibility of field
- // }
+ public void testFieldNewReceiver() throws Exception {
+ performAndCheckSelectedCU_passing(new String[] { "p.A", "p.B" }, "p.A", 7, 17, 7, 19, FIELD, "b", true, true,
+ true);// warn: change-field-to-default-vis
+ }
+
+ public void testParameterNewReceiver() throws Exception {
+ performAndCheckSelectedCU_passing(new String[] { "p.A", "p.B" }, "p.A", 5, 17, 5, 19, PARAMETER, "b", true,
+ true, false);
+ }
+
+ /* Testing team classes */
+ public void testTeamclass1() throws Exception {
+ performAndCheckSelectedCU_passing(new String[] { "p.T", "p.O" }, "p.O", 7, 17, 7, 20, FIELD, "_t", true, true,
+ true);// warn: change-field-to-default-vis
+ }
+
+ public void testTeamclass2() throws Exception {
+ performAndCheckSelectedCU_passing(new String[] { "p.T", "p.O" }, "p.O", 5, 17, 5, 20, PARAMETER, "t", false,
+ false, false);
+ }
+
+ /* Testing role classes */
+ public void testRoleclass1() throws Exception {
+ // XXX(SH): expect info: The 'Move Instance Method' Refactoring is not yet fully OT-aware!
+ performAndCheckSelectedCU_passing_std_info(new String[] { "p.T", "p.O" }, "p.O", 8, 17, 8, 20, FIELD, "_r", true, false,
+ false);
+ }
+
+ public void testRoleclass2() throws Exception {
+ // XXX(SH): expect info: The 'Move Instance Method' Refactoring is not yet fully OT-aware!
+ performAndCheckSelectedCU_passing_std_info(new String[] { "p.T", "p.O" }, "p.O", 7, 17, 7, 20, PARAMETER, "r", true,
+ false, false);
+ }
+
+ /* Testing nested teams */
+ public void testNestedTeam1() throws Exception {
+ // XXX(SH): expect info: The 'Move Instance Method' Refactoring is not yet fully OT-aware!
+ performAndCheckSelectedCU_passing_std_info(new String[] { "p.T", "p.O" }, "p.O", 8, 17, 8, 20, FIELD, "_nT", true,
+ false, false);
+ }
+
+ public void testNestedTeam2() throws Exception {
+ // XXX(SH): expect info: The 'Move Instance Method' Refactoring is not yet fully OT-aware!
+ performAndCheckSelectedCU_passing_std_info(new String[] { "p.T", "p.O" }, "p.O", 7, 17, 7, 20, PARAMETER, "nT", true,
+ false, false);
+ }
+
+ /* Testing role files */
+ // TODO(gbr) implement tests for role files
+ // public void testRoleFile1() throws Exception
+ // {
+ // }
+ //
+ // public void testRoleFile2() throws Exception
+ // {
+ // }
+
+ public void testRoleClassWithLongMethodSpecsInCallinBinding() throws Exception {
+ performConditionChecking_warnings(new String[] { "p.O", "p.S", "p.B", "p.T" }, "p.O", 8, 17, 8, 18, FIELD,
+ "_s", null, true, true,
+ // FIXME(SH):
+ // OTRefactoringStatusCodes.OVERLOADING
+ -1);
+ }
+
+ public void testRoleClassWithLongMethodSpecsInCalloutBinding() throws Exception {
+ performConditionChecking_warnings(new String[] { "p.O", "p.S", "p.B", "p.T" }, "p.O", 8, 17, 8, 18, FIELD,
+ "_s", null, true, true,
+ // FIXME(SH):
+ // OTRefactoringStatusCodes.OVERLOADING
+ -1);
+ }
+
+ public void testExplicitlyInheritedRoleClassWithLongMethodSpecs() throws Exception {
+ performConditionChecking_warnings(new String[] { "p.O", "p.S", "p.B", "p.T" }, "p.O", 8, 17, 8, 18, FIELD,
+ "_s", null, true, true,
+ // FIXME(SH):
+ // OTRefactoringStatusCodes.OVERLOADING
+ -1);
+ }
+
+ public void testImplicitlyInheritedRoleClassWithLongMethodSpecs() throws Exception {
+ performConditionChecking_warnings(new String[] { "p.O", "p.S", "p.B", "p.T1", "p.T2" }, "p.O", 8, 17, 8, 18,
+ FIELD, "_s", null, true, true,
+ // FIXME(SH):
+ // OTRefactoringStatusCodes.OVERLOADING
+ -1);
+ }
+
+ public void testTargetMethodAccessesPrivateFeatureOfEnclosingType1() throws Exception {
+ performAndCheckSelectedCU_passing(new String[] { "p.A", "p.B", "p.C" }, "p.A", 8, 17, 8, 19, FIELD, "_c", true,
+ true, true);// warn: move needs to open visibility of field
+ }
+
+ public void testTargetMethodAccessesPrivateFeatureOfEnclosingType2() throws Exception {
+ performAndCheckSelectedCU_passing(new String[] { "p.A", "p.B", "p.C" }, "p.A", 7, 17, 7, 19, PARAMETER, "c",
+ true, true, true);// warn: move needs to open visibility of
+ // field
+ }
+
+ public void testTargetMethodAccessesProtectedFeatureOfEnclosingType1() throws Exception {
+ performAndCheckSelectedCU_passing(new String[] { "p1.A", "p1.B", "p2.C" }, "p1.A", 10, 17, 10, 19, FIELD, "_c",
+ true, true, true);// warn: move needs to open visibility of
+ // field
+ }
+
+ public void testTargetMethodAccessesProtectedFeatureOfEnclosingType2() throws Exception {
+ performAndCheckSelectedCU_passing(new String[] { "p1.A", "p1.B", "p2.C" }, "p1.A", 9, 17, 9, 19, PARAMETER,
+ "c", true, true, true);// warn: move needs to open visibility of
+ // field
+ }
+
+ public void testTargetMethodAccessesPackageVisibleFeatureOfEnclosingType1() throws Exception {
+ performAndCheckSelectedCU_passing(new String[] { "p1.A", "p1.B", "p2.C" }, "p1.A", 10, 17, 10, 19, FIELD, "_c",
+ true, true, true);// warn: move needs to open visibility of
+ // field
+ }
+
+ public void testTargetMethodAccessesPackageVisibleFeatureOfEnclosingType2() throws Exception {
+ performAndCheckSelectedCU_passing(new String[] { "p1.A", "p1.B", "p2.C" }, "p1.A", 9, 17, 9, 19, PARAMETER,
+ "c", true, true, true);// warn: move needs to open visibility of
+ // field
+ }
//tests for ambiguity in method specs
public void testAmbiguousRoleMethodSpecifierInCallinBinding1()
throws Exception

Back to the top