001: package org.acm.seguin.refactor.type;
002:
003: import java.io.File;
004: import org.acm.seguin.io.FileCopy;
005: import org.acm.seguin.summary.SummaryTraversal;
006: import org.acm.seguin.junit.FileCompare;
007: import org.acm.seguin.junit.DirSourceTestCase;
008: import org.acm.seguin.refactor.RefactoringException;
009:
010: /**
011: * Unit tests for the remove empty class refactoring.
012: *
013: *@author Chris Seguin
014: */
015: public class TestRemoveEmptyClassRefactoring extends DirSourceTestCase {
016: private File cleanDir;
017: private File impDest;
018: private File absDest;
019:
020: /**
021: * Constructor for the TestRemoveAbstractParent object
022: *
023: *@param name Description of Parameter
024: */
025: public TestRemoveEmptyClassRefactoring(String name) {
026: super (name);
027: }
028:
029: /**
030: * A unit test for JUnit
031: *
032: *@exception RefactoringException Description of Exception
033: */
034: public void test1() throws RefactoringException {
035: // Setup
036: (new FileCopy(new File(cleanDir, "ChildRapOne.java"), new File(
037: absDest, "ChildRapOne.java"), false)).run();
038:
039: (new FileCopy(new File(cleanDir, "RapTestOne.java"), new File(
040: absDest, "RapTestOne.java"), false)).run();
041:
042: (new FileCopy(new File(cleanDir, "ParentRapOne.java"),
043: new File(absDest, "ParentRapOne.java"), false)).run();
044:
045: (new FileCopy(new File(cleanDir, "AccessWrap.java"), new File(
046: impDest, "AccessWrap.java"), false)).run();
047:
048: (new SummaryTraversal(root)).run();
049: RemoveEmptyClassRefactoring rap = new RemoveEmptyClassRefactoring();
050: rap.setClass("abstracter", "RapTestOne");
051: rap.run();
052:
053: // Check things out
054: File check = new File(this .check + "\\ut1\\step16");
055:
056: FileCompare.assertEquals("ChildRapOne is incorrect", new File(
057: check, "ChildRapOne.java"), new File(absDest,
058: "ChildRapOne.java"));
059: FileCompare.assertEquals("ParentRapOne is incorrect", new File(
060: check, "ParentRapOne.java"), new File(absDest,
061: "ParentRapOne.java"));
062: FileCompare.assertEquals("AccessWrap is incorrect", new File(
063: check, "AccessWrap.java"), new File(impDest,
064: "AccessWrap.java"));
065: assertTrue("RapTestOne still exists", !(new File(absDest,
066: "RapTestOne.java")).exists());
067:
068: // Tear down
069: (new File(absDest, "ChildRapOne.java")).delete();
070: (new File(absDest, "ParentRapOne.java")).delete();
071: (new File(impDest, "AccessWrap.java")).delete();
072: }
073:
074: /**
075: * A unit test for JUnit
076: *
077: *@exception RefactoringException Description of Exception
078: */
079: public void test2() throws RefactoringException {
080: (new FileCopy(new File(cleanDir, "ChildRapTwo.java"), new File(
081: absDest, "ChildRapTwo.java"), false)).run();
082:
083: (new FileCopy(new File(cleanDir, "RapTestTwo.java"), new File(
084: absDest, "RapTestTwo.java"), false)).run();
085:
086: (new FileCopy(new File(cleanDir, "AccessWrap.java"), new File(
087: impDest, "AccessWrap.java"), false)).run();
088:
089: (new SummaryTraversal(root)).run();
090: RemoveEmptyClassRefactoring rap = new RemoveEmptyClassRefactoring();
091: rap.setClass("abstracter", "RapTestTwo");
092: rap.run();
093:
094: // Check things out
095: File check = new File(this .check + "\\ut1\\step17");
096: FileCompare.assertEquals("ChildRapTwo is incorrect", new File(
097: check, "ChildRapTwo.java"), new File(absDest,
098: "ChildRapTwo.java"));
099: FileCompare.assertEquals("AccessWrap is incorrect", new File(
100: check, "AccessWrap.java"), new File(impDest,
101: "AccessWrap.java"));
102: assertTrue("RapTestTwo still exists", !(new File(absDest,
103: "RapTestTwo.java")).exists());
104:
105: // Tear down
106: (new File(absDest, "ChildRapTwo.java")).delete();
107: (new File(impDest, "AccessWrap.java")).delete();
108: }
109:
110: /**
111: * A unit test for JUnit
112: *
113: *@exception RefactoringException Description of Exception
114: */
115: public void test3() throws RefactoringException {
116: (new FileCopy(new File(cleanDir, "ChildRapThree.java"),
117: new File(absDest, "ChildRapThree.java"), false)).run();
118:
119: (new FileCopy(new File(cleanDir, "RapTestThree.java"),
120: new File(absDest, "RapTestThree.java"), false)).run();
121:
122: (new FileCopy(new File(cleanDir, "ParentRapOne.java"),
123: new File(absDest, "ParentRapOne.java"), false)).run();
124:
125: (new FileCopy(new File(cleanDir, "AccessWrap.java"), new File(
126: impDest, "AccessWrap.java"), false)).run();
127:
128: (new SummaryTraversal(root)).run();
129: RemoveEmptyClassRefactoring rap = new RemoveEmptyClassRefactoring();
130: rap.setClass("abstracter", "RapTestThree");
131: try {
132: rap.run();
133: fail("No refactoring exceptions were thrown");
134: } catch (RefactoringException re) {
135: assertEquals(
136: "Incorrect refactoring exception",
137: "The RapTestThree class has at least one method or field",
138: re.getMessage());
139: }
140:
141: // Check things out
142: File check = new File(this .check + "\\ut1\\step18");
143: FileCompare.assertEquals("ChildRapThree is incorrect",
144: new File(check, "ChildRapThree.java"), new File(
145: absDest, "ChildRapThree.java"));
146: FileCompare.assertEquals("RapTestThree is incorrect", new File(
147: check, "RapTestThree.java"), new File(absDest,
148: "RapTestThree.java"));
149: FileCompare.assertEquals("ParentRapOne is incorrect", new File(
150: check, "ParentRapOne.java"), new File(absDest,
151: "ParentRapOne.java"));
152: FileCompare.assertEquals("AccessWrap is incorrect", new File(
153: check, "AccessWrap.java"), new File(impDest,
154: "AccessWrap.java"));
155:
156: // Tear down
157: (new File(absDest, "ChildRapThree.java")).delete();
158: (new File(absDest, "RapTestThree.java")).delete();
159: (new File(absDest, "ParentRapOne.java")).delete();
160: (new File(impDest, "AccessWrap.java")).delete();
161: }
162:
163: /**
164: * A unit test for JUnit
165: *
166: *@exception RefactoringException Description of Exception
167: */
168: public void test4() throws RefactoringException {
169: (new FileCopy(new File(cleanDir, "ChildRapFour.java"),
170: new File(absDest, "ChildRapFour.java"), false)).run();
171:
172: (new FileCopy(new File(cleanDir, "ChildRapFourImp.java"),
173: new File(absDest, "ChildRapFourImp.java"), false))
174: .run();
175:
176: (new FileCopy(new File(cleanDir, "RapTestFour.java"), new File(
177: absDest, "RapTestFour.java"), false)).run();
178:
179: (new FileCopy(new File(cleanDir, "ParentRapFour.java"),
180: new File(impDest, "ParentRapFour.java"), false)).run();
181:
182: (new FileCopy(new File(cleanDir, "AccessWrap.java"), new File(
183: impDest, "AccessWrap.java"), false)).run();
184:
185: File renDir = new File(root, "ren");
186: (new FileCopy(new File(cleanDir, "OtherPackageRapFour.java"),
187: new File(renDir, "OtherPackageRapFour.java"), false))
188: .run();
189:
190: (new SummaryTraversal(root)).run();
191: RemoveEmptyClassRefactoring rap = new RemoveEmptyClassRefactoring();
192: rap.setClass("abstracter", "RapTestFour");
193: rap.run();
194:
195: // Check things out
196: File check = new File(this .check + "\\ut1\\step19");
197:
198: FileCompare.assertEquals("ChildRapFour is incorrect", new File(
199: check, "ChildRapFour.java"), new File(absDest,
200: "ChildRapFour.java"));
201: FileCompare.assertEquals("ParentRapFour is incorrect",
202: new File(check, "ParentRapFour.java"), new File(
203: impDest, "ParentRapFour.java"));
204: FileCompare.assertEquals("AccessWrap is incorrect", new File(
205: check, "AccessWrap.java"), new File(impDest,
206: "AccessWrap.java"));
207: FileCompare.assertEquals("OtherPackageRapFour is incorrect",
208: new File(check, "OtherPackageRapFour.java"), new File(
209: renDir, "OtherPackageRapFour.java"));
210: FileCompare.assertEquals("ChildRapFourImp is incorrect",
211: new File(check, "ChildRapFourImp.java"), new File(
212: absDest, "ChildRapFourImp.java"));
213: assertTrue("RapTestFour still exists", !(new File(absDest,
214: "RapTestFour.java")).exists());
215:
216: // Tear down
217: (new File(absDest, "ChildRapFour.java")).delete();
218: (new File(absDest, "ParentRapFour.java")).delete();
219: (new File(impDest, "AccessWrap.java")).delete();
220: (new File(renDir, "OtherPackageRapFour.java")).delete();
221: }
222:
223: /**
224: * The JUnit setup method
225: */
226: protected void setUp() {
227: cleanDir = new File(this .clean);
228: impDest = new File(root + "\\imp");
229: absDest = new File(root + "\\abstracter");
230: }
231:
232: /**
233: * The teardown method for JUnit
234: */
235: protected void tearDown() {
236: }
237: }
|