001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.ui.tests.refactoring;
011:
012: import junit.framework.Test;
013: import junit.framework.TestSuite;
014:
015: import org.eclipse.core.runtime.NullProgressMonitor;
016:
017: import org.eclipse.jdt.core.ICompilationUnit;
018: import org.eclipse.jdt.core.IMethod;
019: import org.eclipse.jdt.core.IType;
020:
021: import org.eclipse.jdt.internal.corext.refactoring.rename.RenameMethodProcessor;
022: import org.eclipse.jdt.internal.corext.refactoring.rename.RenameNonVirtualMethodProcessor;
023: import org.eclipse.ltk.core.refactoring.RefactoringCore;
024: import org.eclipse.ltk.core.refactoring.RefactoringStatus;
025: import org.eclipse.ltk.core.refactoring.participants.RenameArguments;
026: import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring;
027:
028: public class RenamePrivateMethodTests extends RefactoringTest {
029:
030: private static final Class clazz = RenamePrivateMethodTests.class;
031: private static final String REFACTORING_PATH = "RenamePrivateMethod/";
032:
033: public RenamePrivateMethodTests(String name) {
034: super (name);
035: }
036:
037: public static Test suite() {
038: return new RefactoringTestSetup(new TestSuite(clazz));
039: }
040:
041: public static Test setUpTest(Test test) {
042: return new RefactoringTestSetup(test);
043: }
044:
045: protected String getRefactoringPath() {
046: return REFACTORING_PATH;
047: }
048:
049: private void helper1_0(String methodName, String newMethodName,
050: String[] signatures) throws Exception {
051: IType classA = getType(
052: createCUfromTestFile(getPackageP(), "A"), "A");
053: RenameMethodProcessor processor = new RenameNonVirtualMethodProcessor(
054: classA.getMethod(methodName, signatures));
055: RenameRefactoring refactoring = new RenameRefactoring(processor);
056: processor.setNewElementName(newMethodName);
057: RefactoringStatus result = performRefactoring(refactoring);
058: assertNotNull("precondition was supposed to fail", result);
059: }
060:
061: private void helper1() throws Exception {
062: helper1_0("m", "k", new String[0]);
063: }
064:
065: private void helper2_0(String methodName, String newMethodName,
066: String[] signatures, boolean updateReferences,
067: boolean createDelegate) throws Exception {
068: ParticipantTesting.reset();
069: ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
070: IType classA = getType(cu, "A");
071: IMethod method = classA.getMethod(methodName, signatures);
072: String[] handles = ParticipantTesting.createHandles(method);
073: RenameMethodProcessor processor = new RenameNonVirtualMethodProcessor(
074: method);
075: RenameRefactoring refactoring = new RenameRefactoring(processor);
076: processor.setUpdateReferences(updateReferences);
077: processor.setNewElementName(newMethodName);
078: processor.setDelegateUpdating(createDelegate);
079: assertEquals("was supposed to pass", null,
080: performRefactoring(refactoring));
081: assertEqualLines("invalid renaming",
082: getFileContents(getOutputTestFileName("A")), cu
083: .getSource());
084:
085: ParticipantTesting.testRename(handles,
086: new RenameArguments[] { new RenameArguments(
087: newMethodName, updateReferences) });
088:
089: assertTrue("anythingToUndo", RefactoringCore.getUndoManager()
090: .anythingToUndo());
091: assertTrue("! anythingToRedo", !RefactoringCore
092: .getUndoManager().anythingToRedo());
093: //assertEquals("1 to undo", 1, Refactoring.getUndoManager().getRefactoringLog().size());
094:
095: RefactoringCore.getUndoManager().performUndo(null,
096: new NullProgressMonitor());
097: assertEqualLines("invalid undo",
098: getFileContents(getInputTestFileName("A")), cu
099: .getSource());
100:
101: assertTrue("! anythingToUndo", !RefactoringCore
102: .getUndoManager().anythingToUndo());
103: assertTrue("anythingToRedo", RefactoringCore.getUndoManager()
104: .anythingToRedo());
105: //assertEquals("1 to redo", 1, Refactoring.getUndoManager().getRedoStack().size());
106:
107: RefactoringCore.getUndoManager().performRedo(null,
108: new NullProgressMonitor());
109: assertEqualLines("invalid redo",
110: getFileContents(getOutputTestFileName("A")), cu
111: .getSource());
112: }
113:
114: private void helper2_0(String methodName, String newMethodName,
115: String[] signatures) throws Exception {
116: helper2_0(methodName, newMethodName, signatures, true, false);
117: }
118:
119: private void helper2(boolean updateReferences) throws Exception {
120: helper2_0("m", "k", new String[0], updateReferences, false);
121: }
122:
123: private void helper2() throws Exception {
124: helper2(true);
125: }
126:
127: private void helperDelegate() throws Exception {
128: helper2_0("m", "k", new String[0], true, true);
129: }
130:
131: public void testFail0() throws Exception {
132: helper1();
133: }
134:
135: public void testFail1() throws Exception {
136: helper1();
137: }
138:
139: public void testFail2() throws Exception {
140: helper1();
141: }
142:
143: public void testFail5() throws Exception {
144: helper1();
145: }
146:
147: public void test0() throws Exception {
148: helper2();
149: }
150:
151: public void test10() throws Exception {
152: helper2();
153: }
154:
155: public void test11() throws Exception {
156: helper2();
157: }
158:
159: public void test12() throws Exception {
160: helper2();
161: }
162:
163: public void test13() throws Exception {
164: helper2();
165: }
166:
167: public void test14() throws Exception {
168: helper2();
169: }
170:
171: public void test15() throws Exception {
172: helper2_0("m", "k", new String[] { "I" });
173: }
174:
175: public void test16() throws Exception {
176: helper2_0("m", "fred", new String[] { "I" });
177: }
178:
179: public void test17() throws Exception {
180: helper2_0("m", "kk", new String[] { "I" });
181: }
182:
183: public void test18() throws Exception {
184: ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
185: ICompilationUnit cuC = createCUfromTestFile(getPackageP(), "C");
186:
187: IType classB = getType(cu, "B");
188: RenameMethodProcessor processor = new RenameNonVirtualMethodProcessor(
189: classB.getMethod("m", new String[] { "I" }));
190: RenameRefactoring refactoring = new RenameRefactoring(processor);
191: processor.setNewElementName("kk");
192:
193: assertEquals("was supposed to pass", null,
194: performRefactoring(refactoring));
195: assertEqualLines("invalid renaming A",
196: getFileContents(getOutputTestFileName("A")), cu
197: .getSource());
198: assertEqualLines("invalid renaming C",
199: getFileContents(getOutputTestFileName("C")), cuC
200: .getSource());
201:
202: }
203:
204: public void test2() throws Exception {
205: helper2_0("m", "fred", new String[0]);
206: }
207:
208: public void test20() throws Exception {
209: helper2_0("m", "fred", new String[] { "I" });
210: }
211:
212: public void test23() throws Exception {
213: helper2_0("m", "k", new String[0]);
214: }
215:
216: public void test24() throws Exception {
217: helper2_0("m", "k", new String[] { "QString;" });
218: }
219:
220: public void test25() throws Exception {
221: helper2_0("m", "k", new String[] { "[QString;" });
222: }
223:
224: public void test26() throws Exception {
225: helper2_0("m", "k", new String[0]);
226: }
227:
228: public void test27() throws Exception {
229: helper2_0("m", "k", new String[0], false, false);
230: }
231:
232: public void testAnon0() throws Exception {
233: helper2();
234: }
235:
236: public void testDelegate01() throws Exception {
237: // simple static delegate
238: helperDelegate();
239: }
240: }
|