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 java.net.URL;
031: import org.netbeans.modules.refactoring.api.SingleCopyRefactoring;
032: import org.openide.filesystems.FileObject;
033: import org.openide.util.lookup.Lookups;
034:
035: /**
036: *
037: * @author Jiri Prox
038: */
039: public class CopyClassTest extends RefactoringTestCase {
040:
041: public CopyClassTest(String name) {
042: super (name);
043: }
044:
045: public void testCopyClass() throws Exception {
046: FileObject test = getFileInProject("default",
047: "src/copypkg/CopyClass.java");
048: FileObject target = getFileInProject("default",
049: "src/copypkgdst");
050: final URL targetURL = target.getURL();
051: final SingleCopyRefactoring copyRefactoring = new SingleCopyRefactoring(
052: Lookups.singleton(test));
053: perform(copyRefactoring, new ParameterSetter() {
054: public void setParameters() {
055: copyRefactoring.setTarget(Lookups.singleton(targetURL));
056: copyRefactoring.setNewName("CopyClass");
057: }
058: });
059:
060: }
061:
062: public void testCopyClassToSamePackage() throws Exception {
063: FileObject test = getFileInProject("default",
064: "src/copypkg/CopyClassToSamePkg.java");
065: FileObject target = getFileInProject("default", "src/copypkg");
066: final URL targetURL = target.getURL();
067: final SingleCopyRefactoring copyRefactoring = new SingleCopyRefactoring(
068: Lookups.singleton(test));
069: perform(copyRefactoring, new ParameterSetter() {
070: public void setParameters() {
071: copyRefactoring.setTarget(Lookups.singleton(targetURL));
072: copyRefactoring.setNewName("CopyClassToSamePkg1");
073: }
074: });
075:
076: }
077:
078: public void testCopyClassWithRename() throws Exception {
079: FileObject test = getFileInProject("default",
080: "src/copypkg/CopyRename.java");
081: FileObject target = getFileInProject("default",
082: "src/copypkgdst");
083: final URL targetURL = target.getURL();
084: final SingleCopyRefactoring copyRefactoring = new SingleCopyRefactoring(
085: Lookups.singleton(test));
086: perform(copyRefactoring, new ParameterSetter() {
087: public void setParameters() {
088: copyRefactoring.setTarget(Lookups.singleton(targetURL));
089: copyRefactoring.setNewName("CopiedAndRenamed");
090: }
091: });
092: }
093:
094: public void testCopyToDefault() throws Exception {
095: FileObject test = getFileInProject("default",
096: "src/copypkg/CopyDefault.java");
097: FileObject target = getFileInProject("default", "src");
098: final URL targetURL = target.getURL();
099: final SingleCopyRefactoring copyRefactoring = new SingleCopyRefactoring(
100: Lookups.singleton(test));
101: perform(copyRefactoring, new ParameterSetter() {
102: public void setParameters() {
103: copyRefactoring.setTarget(Lookups.singleton(targetURL));
104: copyRefactoring.setNewName("CopyDefault");
105: }
106: });
107: }
108:
109: public void testCopyInvalid1() throws Exception {
110: FileObject test = getFileInProject("default",
111: "src/copypkg/CopyClassInvalid1.java");
112: FileObject target = getFileInProject("default",
113: "src/copypkgdst");
114: final URL targetURL = target.getURL();
115: final SingleCopyRefactoring copyRefactoring = new SingleCopyRefactoring(
116: Lookups.singleton(test));
117: perform(copyRefactoring, new ParameterSetter() {
118: public void setParameters() {
119: copyRefactoring.setTarget(Lookups.singleton(targetURL));
120: copyRefactoring.setNewName("CopyClassInvalid2");
121: }
122: });
123: }
124:
125: public void testCopyInvalid2() throws Exception {
126: FileObject test = getFileInProject("default",
127: "src/copypkg/CopyClassInvalid2.java");
128: FileObject target = getFileInProject("default",
129: "src/copypkgdst");
130: final URL targetURL = target.getURL();
131: final SingleCopyRefactoring copyRefactoring = new SingleCopyRefactoring(
132: Lookups.singleton(test));
133: perform(copyRefactoring, new ParameterSetter() {
134: public void setParameters() {
135: copyRefactoring.setTarget(Lookups.singleton(targetURL));
136: copyRefactoring.setNewName("CopyClassInvalid2");
137: }
138: });
139: }
140:
141: }
|