001: /*
002: * Author: Chris Seguin
003: *
004: * This software has been developed under the copyleft
005: * rules of the GNU General Public License. Please
006: * consult the GNU General Public License for more
007: * details about use and distribution of this software.
008: */
009: package org.acm.seguin.refactor.type;
010:
011: import java.io.File;
012: import org.acm.seguin.io.FileCopy;
013: import org.acm.seguin.junit.DirSourceTestCase;
014: import org.acm.seguin.junit.FileCompare;
015: import net.sourceforge.jrefactory.ast.ASTClassDeclaration;
016: import net.sourceforge.jrefactory.ast.ASTCompilationUnit;
017: import net.sourceforge.jrefactory.ast.ASTName;
018: import net.sourceforge.jrefactory.ast.ASTPackageDeclaration;
019: import net.sourceforge.jrefactory.ast.ASTTypeDeclaration;
020: import net.sourceforge.jrefactory.ast.ASTUnmodifiedClassDeclaration;
021: import org.acm.seguin.refactor.RefactoringException;
022: import org.acm.seguin.summary.PackageSummary;
023: import org.acm.seguin.summary.SummaryTraversal;
024: import org.acm.seguin.summary.TypeSummary;
025: import org.acm.seguin.summary.query.GetTypeSummary;
026:
027: /**
028: * Unit test for extracting an interface
029: *
030: *@author Grant Watson
031: *@created November 27, 2000
032: */
033: public class TestExtractInterface extends DirSourceTestCase {
034: /**
035: * Constructor for the TestExtractInterface object
036: *
037: *@param name Description of Parameter
038: */
039: public TestExtractInterface(String name) {
040: super (name);
041: }
042:
043: /**
044: * This test ensures that a new interface is extracted correctly from a
045: * single class that extends nothing and implements nothing. All methods in
046: * this class are public.
047: *
048: *@exception RefactoringException Description of Exception
049: */
050: public void test01() throws RefactoringException {
051: ExtractInterfaceRefactoring eir = new ExtractInterfaceRefactoring();
052: eir.addImplementingClass("testextractinterface", "Supplier1");
053: eir.setInterfaceName("Supplier1Only");
054: eir.run();
055: File destDir = new File(root + "\\testextractinterface");
056: File checkDir = new File(check + "\\testextractinterface");
057: FileCompare.assertEquals(
058: "Extracted interface Supplier1Only in error", new File(
059: checkDir, "Supplier1Only.java"), new File(
060: destDir, "Supplier1Only.java"));
061: FileCompare.assertEquals("Original class Supplier in error",
062: new File(checkDir, "Supplier1.java"), new File(destDir,
063: "Supplier1.java"));
064: }
065:
066: /**
067: * This test ensures that a new interface is extracted correctly from a
068: * single class that extends something but implements nothing. All methods
069: * in this class are public.
070: *
071: *@exception RefactoringException Description of Exception
072: */
073: public void test02() throws RefactoringException {
074: ExtractInterfaceRefactoring eir = new ExtractInterfaceRefactoring();
075: eir.addImplementingClass("testextractinterface", "Supplier2");
076: eir.setInterfaceName("Supplier2Only");
077: eir.run();
078: File destDir = new File(root + "\\testextractinterface");
079: File checkDir = new File(check + "\\testextractinterface");
080: FileCompare.assertEquals(
081: "Extracted interface Supplier2Only in error", new File(
082: checkDir, "Supplier2Only.java"), new File(
083: destDir, "Supplier2Only.java"));
084: FileCompare.assertEquals("Original class Supplier in error",
085: new File(checkDir, "Supplier2.java"), new File(destDir,
086: "Supplier2.java"));
087: }
088:
089: /**
090: * This test ensures that a new interface is extracted correctly from a
091: * single class that extends nothing but implements something. All methods
092: * in this class are public.
093: *
094: *@exception RefactoringException Description of Exception
095: */
096: public void test03() throws RefactoringException {
097: ExtractInterfaceRefactoring eir = new ExtractInterfaceRefactoring();
098: eir.addImplementingClass("testextractinterface", "Supplier3");
099: eir.setInterfaceName("Supplier3Only");
100: eir.run();
101: File destDir = new File(root + "\\testextractinterface");
102: File checkDir = new File(check + "\\testextractinterface");
103: FileCompare.assertEquals(
104: "Extracted interface Supplier3Only in error", new File(
105: checkDir, "Supplier3Only.java"), new File(
106: destDir, "Supplier3Only.java"));
107: FileCompare.assertEquals("Original class Supplier in error",
108: new File(checkDir, "Supplier3.java"), new File(destDir,
109: "Supplier3.java"));
110: }
111:
112: /**
113: * This test ensures that a new interface is extracted correctly from a
114: * single class that extends something and implements something. All methods
115: * in this class are public.
116: *
117: *@exception RefactoringException Description of Exception
118: */
119: public void test04() throws RefactoringException {
120: ExtractInterfaceRefactoring eir = new ExtractInterfaceRefactoring();
121: eir.addImplementingClass("testextractinterface", "Supplier4");
122: eir.setInterfaceName("Supplier4Only");
123: eir.run();
124: File destDir = new File(root + "\\testextractinterface");
125: File checkDir = new File(check + "\\testextractinterface");
126: FileCompare.assertEquals(
127: "Extracted interface Supplier4Only in error", new File(
128: checkDir, "Supplier4Only.java"), new File(
129: destDir, "Supplier4Only.java"));
130: FileCompare.assertEquals("Original class Supplier in error",
131: new File(checkDir, "Supplier4.java"), new File(destDir,
132: "Supplier4.java"));
133: }
134:
135: /**
136: * This test ensures that a new interface is extracted correctly when two
137: * classes are specified.
138: *
139: *@exception RefactoringException Description of Exception
140: */
141: public void test05() throws RefactoringException {
142: ExtractInterfaceRefactoring eir = new ExtractInterfaceRefactoring();
143: eir.addImplementingClass("testextractinterface", "Employee");
144: eir.addImplementingClass("testextractinterface", "Customer");
145: eir.setInterfaceName("Person");
146: eir.run();
147: File destDir = new File(root + "\\testextractinterface");
148: File checkDir = new File(check + "\\testextractinterface");
149: FileCompare.assertEquals("Extracted interface Person in error",
150: new File(checkDir, "Person.java"), new File(destDir,
151: "Person.java"));
152: FileCompare.assertEquals("Original file Employee in error",
153: new File(checkDir, "Employee.java"), new File(destDir,
154: "Employee.java"));
155: FileCompare.assertEquals("Original file Customer in error",
156: new File(checkDir, "Customer.java"), new File(destDir,
157: "Customer.java"));
158:
159: (new File(destDir, "Person.java")).delete();
160: (new File(destDir, "Customer.java")).delete();
161: (new File(destDir, "Employee.java")).delete();
162: }
163:
164: /**
165: * A unit test for JUnit
166: *
167: *@exception RefactoringException Description of Exception
168: */
169: public void test06() throws RefactoringException {
170: ExtractInterfaceRefactoring eir = new ExtractInterfaceRefactoring();
171: eir.addImplementingClass("testextractinterface", "Employee");
172: eir.addImplementingClass("testextractinterface", "Customer");
173: eir.setInterfaceName("Person");
174: eir.setPackageName("");
175: eir.run();
176: File destDir = new File(root + "\\testextractinterface");
177: File checkDir = new File(check + "\\ut1\\step40");
178: FileCompare.assertEquals("Extracted interface Person in error",
179: new File(checkDir, "Person.java"), new File(root,
180: "Person.java"));
181: FileCompare.assertEquals("Original file Employee in error",
182: new File(checkDir, "Employee.java"), new File(destDir,
183: "Employee.java"));
184: FileCompare.assertEquals("Original file Customer in error",
185: new File(checkDir, "Customer.java"), new File(destDir,
186: "Customer.java"));
187: (new File(root, "Person.java")).delete();
188: (new File(destDir, "Customer.java")).delete();
189: (new File(destDir, "Employee.java")).delete();
190: }
191:
192: /**
193: * The JUnit setup method
194: */
195: protected void setUp() {
196: File cleanDir = new File(clean + "\\testextractinterface");
197: File destDir = new File(root + "\\testextractinterface");
198: File impDir = new File(root + "\\imp");
199:
200: (new FileCopy(new File(cleanDir, "Employee.java"), new File(
201: destDir, "Employee.java"), false)).run();
202:
203: (new FileCopy(new File(cleanDir, "Customer.java"), new File(
204: destDir, "Customer.java"), false)).run();
205:
206: (new FileCopy(new File(cleanDir, "Supplier1.java"), new File(
207: destDir, "Supplier1.java"), false)).run();
208:
209: (new FileCopy(new File(cleanDir, "Supplier2.java"), new File(
210: destDir, "Supplier2.java"), false)).run();
211:
212: (new FileCopy(new File(cleanDir, "Supplier3.java"), new File(
213: destDir, "Supplier3.java"), false)).run();
214:
215: (new FileCopy(new File(cleanDir, "Supplier4.java"), new File(
216: destDir, "Supplier4.java"), false)).run();
217:
218: (new SummaryTraversal(root)).run();
219: }
220:
221: /**
222: * Cleanup the working directory
223: */
224: protected void tearDown() {
225: }
226:
227: /**
228: * Description of the Method
229: *
230: *@param args Description of Parameter
231: */
232: public static void main(String args[]) {
233: //junit.swingui.LoadingTestRunner runner = new junit.swingui.LoadingTestRunner();
234: junit.swingui.TestRunner runner = new junit.swingui.TestRunner();
235: runner.main(new String[0]);
236: }
237: }
|