001: package org.acm.seguin.refactor.field;
002:
003: import java.io.File;
004: import org.acm.seguin.io.FileCopy;
005: import org.acm.seguin.junit.DirSourceTestCase;
006: import org.acm.seguin.junit.FileCompare;
007: import org.acm.seguin.refactor.RefactoringException;
008: import org.acm.seguin.summary.SummaryTraversal;
009:
010: /**
011: * Unit tests for the rename field refactoring.
012: *
013: * @author Chris Seguin
014: */
015: public class TestRenameFieldRefactoring extends DirSourceTestCase {
016: private File impDest;
017: private File dest;
018:
019: /**
020: * Constructor for the TestRenameFieldRefactoring object
021: *
022: * @param name the name of the unit test to run
023: */
024: public TestRenameFieldRefactoring(String name) {
025: super (name);
026: }
027:
028: /**
029: * A unit test for JUnit
030: *
031: * @exception RefactoringException Description of Exception
032: */
033: public void test01() throws RefactoringException {
034: RenameFieldRefactoring rfr = new RenameFieldRefactoring();
035: rfr.setClass("field", "RenameFieldTest");
036: rfr.setField("simple");
037: rfr.setNewName("changed");
038:
039: rfr.run();
040:
041: // Check things out
042: File check = new File(this .check + "\\ut2\\step11");
043:
044: FileCompare.assertEquals("RenameFieldTest is incorrect",
045: new File(check, "RenameFieldTest.java"), new File(dest,
046: "RenameFieldTest.java"));
047: FileCompare.assertEquals("UsesFieldTest is incorrect",
048: new File(check, "UsesFieldTest.java"), new File(dest,
049: "UsesFieldTest.java"));
050: FileCompare.assertEquals("InheritFieldTest is incorrect",
051: new File(check, "InheritFieldTest.java"), new File(
052: dest, "InheritFieldTest.java"));
053: }
054:
055: /**
056: * A unit test for JUnit
057: *
058: * @exception RefactoringException Description of Exception
059: */
060: public void test02() throws RefactoringException {
061: RenameFieldRefactoring rfr = new RenameFieldRefactoring();
062: rfr.setClass("field", "RenameFieldTest");
063: rfr.setField("code");
064: rfr.setNewName("changed");
065:
066: rfr.run();
067:
068: // Check things out
069: File check = new File(this .check + "\\ut2\\step12");
070:
071: FileCompare.assertEquals("RenameFieldTest is incorrect",
072: new File(check, "RenameFieldTest.java"), new File(dest,
073: "RenameFieldTest.java"));
074: FileCompare.assertEquals("UsesFieldTest is incorrect",
075: new File(check, "UsesFieldTest.java"), new File(dest,
076: "UsesFieldTest.java"));
077: FileCompare.assertEquals("InheritFieldTest is incorrect",
078: new File(check, "InheritFieldTest.java"), new File(
079: dest, "InheritFieldTest.java"));
080: }
081:
082: /**
083: * A unit test for JUnit
084: *
085: * @exception RefactoringException Description of Exception
086: */
087: public void test03() throws RefactoringException {
088: RenameFieldRefactoring rfr = new RenameFieldRefactoring();
089: rfr.setClass("field", "RenameFieldTest");
090: rfr.setField("height");
091: rfr.setNewName("changed");
092:
093: rfr.run();
094:
095: // Check things out
096: File check = new File(this .check + "\\ut2\\step13");
097:
098: FileCompare.assertEquals("RenameFieldTest is incorrect",
099: new File(check, "RenameFieldTest.java"), new File(dest,
100: "RenameFieldTest.java"));
101: FileCompare.assertEquals("UsesFieldTest is incorrect",
102: new File(check, "UsesFieldTest.java"), new File(dest,
103: "UsesFieldTest.java"));
104: FileCompare.assertEquals("InheritFieldTest is incorrect",
105: new File(check, "InheritFieldTest.java"), new File(
106: dest, "InheritFieldTest.java"));
107: }
108:
109: /**
110: * A unit test for JUnit
111: *
112: * @exception RefactoringException Description of Exception
113: */
114: public void test04() throws RefactoringException {
115: RenameFieldRefactoring rfr = new RenameFieldRefactoring();
116: rfr.setClass("field", "RenameFieldTest");
117: rfr.setField("CODE_ON");
118: rfr.setNewName("changed");
119:
120: rfr.run();
121:
122: // Check things out
123: File check = new File(this .check + "\\ut2\\step14");
124:
125: FileCompare.assertEquals("RenameFieldTest is incorrect",
126: new File(check, "RenameFieldTest.java"), new File(dest,
127: "RenameFieldTest.java"));
128: FileCompare.assertEquals("UsesFieldTest is incorrect",
129: new File(check, "UsesFieldTest.java"), new File(dest,
130: "UsesFieldTest.java"));
131: FileCompare.assertEquals("InheritFieldTest is incorrect",
132: new File(check, "InheritFieldTest.java"), new File(
133: dest, "InheritFieldTest.java"));
134: }
135:
136: /**
137: * A unit test for JUnit
138: *
139: */
140: public void test05() {
141: RenameFieldRefactoring rfr = new RenameFieldRefactoring();
142: rfr.setClass("field", "RenameFieldTest");
143: rfr.setField("crazy");
144: rfr.setNewName("changed");
145:
146: boolean exceptionThrown = false;
147:
148: try {
149: rfr.run();
150: } catch (RefactoringException re) {
151: exceptionThrown = true;
152: assertEquals(
153: "Incorrect exception",
154: "No field named crazy is contained in RenameFieldTest",
155: re.getMessage());
156: }
157:
158: assertTrue("No exception thrown", exceptionThrown);
159: }
160:
161: /**
162: * A unit test for JUnit
163: *
164: */
165: public void test06() {
166: RenameFieldRefactoring rfr = new RenameFieldRefactoring();
167: rfr.setClass("field", "RenameFieldTest");
168: rfr.setField("simple");
169: rfr.setNewName("code");
170:
171: boolean exceptionThrown = false;
172:
173: try {
174: rfr.run();
175: } catch (RefactoringException re) {
176: exceptionThrown = true;
177: assertEquals(
178: "Incorrect exception",
179: "A field named code already exists in class RenameFieldTest",
180: re.getMessage());
181: }
182:
183: assertTrue("No exception thrown", exceptionThrown);
184: }
185:
186: /**
187: * A unit test for JUnit
188: *
189: * @exception RefactoringException Description of Exception
190: */
191: public void test07() throws RefactoringException {
192: RenameFieldRefactoring rfr = new RenameFieldRefactoring();
193: rfr.setClass("", "XDateChooser");
194: rfr.setField("_maxDate");
195: rfr.setNewName("_maximumDate");
196:
197: rfr.run();
198:
199: // Check things out
200: File check = new File(this .check + "\\ut2\\step15");
201:
202: FileCompare.assertEquals("XDateChooser is incorrect", new File(
203: check, "XDateChooser.java"), new File(root
204: + "\\XDateChooser.java"));
205: }
206:
207: /**
208: * A unit test for JUnit
209: *
210: * @exception RefactoringException Description of Exception
211: */
212: public void test08() throws RefactoringException {
213: RenameFieldRefactoring rfr = new RenameFieldRefactoring();
214: rfr.setClass("field", "RenameFieldTest");
215: rfr.setField("childObject");
216: rfr.setNewName("myChild");
217:
218: rfr.run();
219:
220: // Check things out
221: File check = new File(this .check + "\\ut2\\step16");
222:
223: FileCompare.assertEquals("RenameFieldTest is incorrect",
224: new File(check, "RenameFieldTest.java"), new File(dest,
225: "RenameFieldTest.java"));
226: FileCompare.assertEquals("UsesFieldTest is incorrect",
227: new File(check, "UsesFieldTest.java"), new File(dest,
228: "UsesFieldTest.java"));
229: FileCompare.assertEquals("InheritFieldTest is incorrect",
230: new File(check, "InheritFieldTest.java"), new File(
231: dest, "InheritFieldTest.java"));
232: }
233:
234: /**
235: * The JUnit setup method
236: *
237: */
238: protected void setUp() {
239: File cleanDir = new File(this .clean);
240: dest = new File(root + "\\field");
241: if (!dest.exists()) {
242: dest.mkdirs();
243: }
244:
245: (new FileCopy(new File(cleanDir, "field_RenameFieldTest.java"),
246: new File(dest, "RenameFieldTest.java"), false)).run();
247: (new FileCopy(new File(cleanDir, "field_UsesFieldTest.java"),
248: new File(dest, "UsesFieldTest.java"), false)).run();
249: (new FileCopy(
250: new File(cleanDir, "field_InheritFieldTest.java"),
251: new File(dest, "InheritFieldTest.java"), false)).run();
252: (new FileCopy(new File(cleanDir, "XDateChooser.java"),
253: new File(root + "\\XDateChooser.java"), false)).run();
254:
255: (new SummaryTraversal(root)).run();
256: }
257:
258: /**
259: * The teardown method for JUnit
260: *
261: */
262: protected void tearDown() {
263: (new File(dest, "RenameFieldTest.java")).delete();
264: (new File(dest, "UsesFieldTest.java")).delete();
265: (new File(dest, "InheritFieldTest.java")).delete();
266: (new File(root + "\\XDateChooser.java")).delete();
267: }
268: }
|