001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * Portions Copyrighted 2007 Sun Microsystems, Inc.
027: */
028: package org.netbeans.modules.refactoring.java;
029:
030: import org.netbeans.modules.refactoring.api.RenameRefactoring;
031: import org.openide.filesystems.FileObject;
032: import org.openide.util.lookup.Lookups;
033:
034: /**
035: *
036: * @author Jiri Prox
037: */
038: public class RenameClass2Test extends RefactoringElementTestCase {
039:
040: public RenameClass2Test(String name) {
041: super (name);
042: }
043:
044: public void testRenameEmptyClass() throws Exception {
045: String content = "\n" + "package org;\n" + "\n"
046: + "public class MyClass {\n" + "\n" + "}\n" + "\n";
047:
048: createClass("MyClass", "org", content);
049: FileObject test = getFileInProject("default",
050: "src/org/MyClass.java");
051: final RenameRefactoring renameRefactoring = new RenameRefactoring(
052: Lookups.singleton(test));
053: perform(renameRefactoring, new ParameterSetter() {
054: public void setParameters() {
055: renameRefactoring.setNewName("newName");
056: }
057: }, false);
058: }
059:
060: public void testRenameCtor() throws Exception {
061: String content = "\n" + "package org;\n" + "\n"
062: + "public class MyClass2 {\n"
063: + " public MyClass2() {\n" + " \n" + " }\n"
064: + "\n" + "}\n" + "\n";
065:
066: createClass("MyClass2", "org", content);
067: FileObject test = getFileInProject("default",
068: "src/org/MyClass2.java");
069: final RenameRefactoring renameRefactoring = new RenameRefactoring(
070: Lookups.singleton(test));
071: perform(renameRefactoring, new ParameterSetter() {
072: public void setParameters() {
073: renameRefactoring.setNewName("NewClass2");
074: }
075: }, false);
076: }
077:
078: public void testRenameClassField() throws Exception {
079: String content = "\n" + "package org;\n" + "\n"
080: + "public class MyClass3 {\n" + "\n" + "}\n" + "\n";
081: createClass("MyClass3", "org", content);
082: content = "\n" + "package org;\n" + "\n"
083: + "public class MyClass3Test {\n"
084: + " MyClass3 field;" + "}\n" + "\n";
085: createClass("MyClass3Test", "org", content);
086: FileObject test = getFileInProject("default",
087: "src/org/MyClass3.java");
088: final RenameRefactoring renameRefactoring = new RenameRefactoring(
089: Lookups.singleton(test));
090: perform(renameRefactoring, new ParameterSetter() {
091: public void setParameters() {
092: renameRefactoring.setNewName("NewClass3");
093: }
094: }, false);
095: }
096:
097: public void testRenameGenerics() throws Exception {
098: String content = "\n" + "package org;\n" + "\n"
099: + "import java.util.List;\n" + "\n"
100: + "public class MyClass4 {\n"
101: + " List<MyClass4> list;\n" + "}\n" + "\n";
102: createClass("MyClass4", "org", content);
103: FileObject test = getFileInProject("default",
104: "src/org/MyClass4.java");
105: final RenameRefactoring renameRefactoring = new RenameRefactoring(
106: Lookups.singleton(test));
107: perform(renameRefactoring, new ParameterSetter() {
108: public void setParameters() {
109: renameRefactoring.setNewName("NewClass4");
110: }
111: }, false);
112: }
113:
114: public void testRenameGenerics2() throws Exception {
115: String content = "\n" + "package org;\n" + "\n"
116: + "import java.util.List;\n" + "\n"
117: + "public class MyClass5 {\n"
118: + " List<? extends MyClass5> list;\n" + "}\n" + "\n";
119: createClass("MyClass5", "org", content);
120: FileObject test = getFileInProject("default",
121: "src/org/MyClass5.java");
122: final RenameRefactoring renameRefactoring = new RenameRefactoring(
123: Lookups.singleton(test));
124: perform(renameRefactoring, new ParameterSetter() {
125: public void setParameters() {
126: renameRefactoring.setNewName("NewClass5");
127: }
128: }, false);
129: }
130:
131: public void testRenameReturnType() throws Exception {
132: String content = "\n" + "package org;\n" + "\n"
133: + "import java.util.List;\n" + "\n"
134: + "public class MyClass5a {\n" + " \n"
135: + " public MyClass5a get() { return null;}\n"
136: + " \n" + "}\n" + "\n";
137: createClass("MyClass5a", "org", content);
138: FileObject test = getFileInProject("default",
139: "src/org/MyClass5a.java");
140: final RenameRefactoring renameRefactoring = new RenameRefactoring(
141: Lookups.singleton(test));
142: perform(renameRefactoring, new ParameterSetter() {
143: public void setParameters() {
144: renameRefactoring.setNewName("NewClass5a");
145: }
146: }, false);
147: }
148:
149: public void testRenameExtends() throws Exception {
150: String content = "\n" + "package org;\n" + "\n"
151: + "public class MyClass6 {\n" + " \n" + "}\n" + "\n";
152: createClass("MyClass6", "org", content);
153: content = "\n" + "package org;\n" + "\n"
154: + "public class MyClass6Test extends MyClass6 {\n"
155: + " \n" + "}\n" + "\n";
156: createClass("MyClass6Test", "org", content);
157: FileObject test = getFileInProject("default",
158: "src/org/MyClass6.java");
159: final RenameRefactoring renameRefactoring = new RenameRefactoring(
160: Lookups.singleton(test));
161: perform(renameRefactoring, new ParameterSetter() {
162: public void setParameters() {
163: renameRefactoring.setNewName("NewClass6");
164: }
165: }, false);
166: }
167:
168: public void testRenameImplements() throws Exception {
169: String content = "\n" + "package org;\n" + "\n"
170: + "public interface MyClass7 {\n" + " \n" + "}\n"
171: + "\n";
172: createClass("MyClass7", "org", content);
173: content = "\n" + "package org;\n" + "\n"
174: + "public class MyClass7Test implements MyClass7 {\n"
175: + " \n" + "}\n" + "\n";
176: createClass("MyClass7Test", "org", content);
177: FileObject test = getFileInProject("default",
178: "src/org/MyClass7.java");
179: final RenameRefactoring renameRefactoring = new RenameRefactoring(
180: Lookups.singleton(test));
181: perform(renameRefactoring, new ParameterSetter() {
182: public void setParameters() {
183: renameRefactoring.setNewName("NewClass7");
184: }
185: }, false);
186: }
187:
188: public void testRenameThrows() throws Exception {
189: String content = "\n" + "package org;\n" + "\n"
190: + "public class MyClass8 extends Exception {\n"
191: + " \n" + "}\n" + "\n";
192: createClass("MyClass8", "org", content);
193: content = "\n" + "package org;\n" + "\n"
194: + "public class MyClass8Test {\n" + " \n"
195: + " public void method() throws MyClass8 {}\n"
196: + " \n" + "}\n" + "\n";
197: createClass("MyClass8Test", "org", content);
198: FileObject test = getFileInProject("default",
199: "src/org/MyClass8.java");
200: final RenameRefactoring renameRefactoring = new RenameRefactoring(
201: Lookups.singleton(test));
202: perform(renameRefactoring, new ParameterSetter() {
203: public void setParameters() {
204: renameRefactoring.setNewName("NewClass8");
205: }
206: }, false);
207: }
208:
209: public void testRenameAnnotation() throws Exception {
210: String content = "\n" + "package org;\n" + "\n"
211: + "public @interface MyClass9 {\n" + " \n" + "}\n"
212: + "\n";
213: createClass("MyClass9", "org", content);
214: content = "\n" + "package org;\n" + "\n" + "@MyClass9\n"
215: + "public class MyClass9Test {\n" + " \n" + "}\n"
216: + "\n";
217: createClass("MyClass9Test", "org", content);
218: FileObject test = getFileInProject("default",
219: "src/org/MyClass9.java");
220: final RenameRefactoring renameRefactoring = new RenameRefactoring(
221: Lookups.singleton(test));
222: perform(renameRefactoring, new ParameterSetter() {
223: public void setParameters() {
224: renameRefactoring.setNewName("NewClass9");
225: }
226: }, false);
227: }
228:
229: public void testRenameEnum() throws Exception {
230: String content = "\n" + "package org;\n" + "\n"
231: + "public enum MyClass10 {\n" + " \n" + "}\n" + "\n";
232: createClass("MyClass10", "org", content);
233: content = "\n" + "package org;\n" + "\n"
234: + "public class MyClass10Test {\n" + " \n"
235: + " MyClass10 myEnum;\n" + " \n" + "}\n" + "\n";
236: createClass("MyClass10Test", "org", content);
237: FileObject test = getFileInProject("default",
238: "src/org/MyClass10.java");
239: final RenameRefactoring renameRefactoring = new RenameRefactoring(
240: Lookups.singleton(test));
241: perform(renameRefactoring, new ParameterSetter() {
242: public void setParameters() {
243: renameRefactoring.setNewName("NewClass10");
244: }
245: }, false);
246: }
247:
248: }
|