001: package org.acm.seguin.refactor.method;
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 method refactoring.
012: *
013: * @author Chris Seguin
014: */
015: public class TestRenameMethodRefactoring extends DirSourceTestCase {
016: private File impDest;
017: private File dest;
018:
019: /**
020: * Constructor for the TestRenameMethodRefactoring object
021: *
022: * @param name the name of the unit test to run
023: */
024: public TestRenameMethodRefactoring(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: RenameMethodRefactoring rmr = new RenameMethodRefactoring();
035: rmr.setClass("method", "RenameMethodTest");
036: rmr.setMethod("code");
037: rmr.setParams(new String[0]);
038: rmr.setNewMethodName("newCode");
039:
040: rmr.run();
041:
042: // Check things out
043: File check = new File(this .check + "\\ut4\\step1");
044:
045: FileCompare.assertEquals("RenameMethodTest is incorrect",
046: new File(check, "RenameMethodTest.java"), new File(
047: dest, "RenameMethodTest.java"));
048: FileCompare.assertEquals("UsesMethodTest is incorrect",
049: new File(check, "UsesMethodTest.java"), new File(dest,
050: "UsesMethodTest.java"));
051: FileCompare.assertEquals("InheritMethodTest is incorrect",
052: new File(check, "InheritMethodTest.java"), new File(
053: dest, "InheritMethodTest.java"));
054: }
055:
056: public void test02() throws RefactoringException {
057: RenameMethodRefactoring rmr = new RenameMethodRefactoring();
058: rmr.setClass("method", "RenameMethodTest");
059: rmr.setMethod("newCode");
060: rmr.setParams(new String[0]);
061: rmr.setNewMethodName("code");
062:
063: rmr.run();
064:
065: // Check things out
066: File check = new File(this .check + "\\ut4\\step2");
067:
068: FileCompare.assertEquals("RenameMethodTest is incorrect",
069: new File(check, "RenameMethodTest.java"), new File(
070: dest, "RenameMethodTest.java"));
071: FileCompare.assertEquals("UsesMethodTest is incorrect",
072: new File(check, "UsesMethodTest.java"), new File(dest,
073: "UsesMethodTest.java"));
074: FileCompare.assertEquals("InheritMethodTest is incorrect",
075: new File(check, "InheritMethodTest.java"), new File(
076: dest, "InheritMethodTest.java"));
077: }
078:
079: /*
080: public void test03() throws RefactoringException {
081: RenameMethodRefactoring rmr = new RenameMethodRefactoring();
082: rmr.setClass("method", "RenameMethodTest");
083: rmr.setMethod("protectedMethod");
084: rmr.setParams(new String[] { "int" } );
085: rmr.setNewMethodName("xxx");
086:
087: rmr.run();
088:
089: // Check things out
090: File check = new File(this.check + "\\ut4\\step2");
091:
092: FileCompare.assertEquals("RenameMethodTest is incorrect",
093: new File(check, "RenameMethodTest.java"),
094: new File(dest, "RenameMethodTest.java"));
095: FileCompare.assertEquals("UsesMethodTest is incorrect",
096: new File(check, "UsesMethodTest.java"),
097: new File(dest, "UsesMethodTest.java"));
098: FileCompare.assertEquals("InheritMethodTest is incorrect",
099: new File(check, "InheritMethodTest.java"),
100: new File(dest, "InheritMethodTest.java"));
101: }
102:
103:
104: public void test04() throws RefactoringException {
105: RenameMethodRefactoring rmr = new RenameMethodRefactoring();
106: rmr.setClass("method", "RenameMethodTest");
107: rmr.setMethod("xxx");
108: rmr.setParams(new String[] { "int" } );
109: rmr.setNewMethodName("protectedMethod");
110:
111: rmr.run();
112:
113: // Check things out
114: File check = new File(this.check + "\\ut4\\step2");
115:
116: FileCompare.assertEquals("RenameMethodTest is incorrect",
117: new File(check, "RenameMethodTest.java"),
118: new File(dest, "RenameMethodTest.java"));
119: FileCompare.assertEquals("UsesMethodTest is incorrect",
120: new File(check, "UsesMethodTest.java"),
121: new File(dest, "UsesMethodTest.java"));
122: FileCompare.assertEquals("InheritMethodTest is incorrect",
123: new File(check, "InheritMethodTest.java"),
124: new File(dest, "InheritMethodTest.java"));
125: }
126:
127:
128: public void test05() throws RefactoringException {
129: RenameMethodRefactoring rmr = new RenameMethodRefactoring();
130: rmr.setClass("method", "RenameMethodTest");
131: rmr.setMethod("packageProtectedMethod");
132: rmr.setParams(new String[] { "int" } );
133: rmr.setNewMethodName("xxx");
134:
135: rmr.run();
136:
137: // Check things out
138: File check = new File(this.check + "\\ut4\\step2");
139:
140: FileCompare.assertEquals("RenameMethodTest is incorrect",
141: new File(check, "RenameMethodTest.java"),
142: new File(dest, "RenameMethodTest.java"));
143: FileCompare.assertEquals("UsesMethodTest is incorrect",
144: new File(check, "UsesMethodTest.java"),
145: new File(dest, "UsesMethodTest.java"));
146: FileCompare.assertEquals("InheritMethodTest is incorrect",
147: new File(check, "InheritMethodTest.java"),
148: new File(dest, "InheritMethodTest.java"));
149: }
150:
151:
152: public void test06() throws RefactoringException {
153: RenameMethodRefactoring rmr = new RenameMethodRefactoring();
154: rmr.setClass("method", "RenameMethodTest");
155: rmr.setMethod("xxx");
156: rmr.setParams(new String[] { "int" } );
157: rmr.setNewMethodName("packageProtectedMethod");
158:
159: rmr.run();
160:
161: // Check things out
162: File check = new File(this.check + "\\ut4\\step2");
163:
164: FileCompare.assertEquals("RenameMethodTest is incorrect",
165: new File(check, "RenameMethodTest.java"),
166: new File(dest, "RenameMethodTest.java"));
167: FileCompare.assertEquals("UsesMethodTest is incorrect",
168: new File(check, "UsesMethodTest.java"),
169: new File(dest, "UsesMethodTest.java"));
170: FileCompare.assertEquals("InheritMethodTest is incorrect",
171: new File(check, "InheritMethodTest.java"),
172: new File(dest, "InheritMethodTest.java"));
173: }
174:
175:
176: public void test07() throws RefactoringException {
177: RenameMethodRefactoring rmr = new RenameMethodRefactoring();
178: rmr.setClass("method", "RenameMethodTest");
179: rmr.setMethod("privateMethod");
180: rmr.setParams(new String[] { "int" } );
181: rmr.setNewMethodName("xxx");
182:
183: rmr.run();
184:
185: // Check things out
186: File check = new File(this.check + "\\ut4\\step2");
187:
188: FileCompare.assertEquals("RenameMethodTest is incorrect",
189: new File(check, "RenameMethodTest.java"),
190: new File(dest, "RenameMethodTest.java"));
191: FileCompare.assertEquals("UsesMethodTest is incorrect",
192: new File(check, "UsesMethodTest.java"),
193: new File(dest, "UsesMethodTest.java"));
194: FileCompare.assertEquals("InheritMethodTest is incorrect",
195: new File(check, "InheritMethodTest.java"),
196: new File(dest, "InheritMethodTest.java"));
197: }
198:
199:
200: public void test08() throws RefactoringException {
201: RenameMethodRefactoring rmr = new RenameMethodRefactoring();
202: rmr.setClass("method", "RenameMethodTest");
203: rmr.setMethod("xxx");
204: rmr.setParams(new String[] { "int" } );
205: rmr.setNewMethodName("privateMethod");
206:
207: rmr.run();
208:
209: // Check things out
210: File check = new File(this.check + "\\ut4\\step2");
211:
212: FileCompare.assertEquals("RenameMethodTest is incorrect",
213: new File(check, "RenameMethodTest.java"),
214: new File(dest, "RenameMethodTest.java"));
215: FileCompare.assertEquals("UsesMethodTest is incorrect",
216: new File(check, "UsesMethodTest.java"),
217: new File(dest, "UsesMethodTest.java"));
218: FileCompare.assertEquals("InheritMethodTest is incorrect",
219: new File(check, "InheritMethodTest.java"),
220: new File(dest, "InheritMethodTest.java"));
221: }
222:
223:
224: public void test03() throws RefactoringException {
225: RenameMethodRefactoring rmr = new RenameMethodRefactoring();
226: rmr.setClass("method", "RenameMethodTest");
227: rmr.setMethod("height");
228: rmr.setParams(new String[0]);
229: rmr.setNewMethodName("width");
230:
231: rmr.run();
232:
233: // Check things out
234: File check = new File(this.check + "\\ut4\\step3");
235:
236: FileCompare.assertEquals("RenameMethodTest is incorrect",
237: new File(check, "RenameMethodTest.java"),
238: new File(dest, "RenameMethodTest.java"));
239: FileCompare.assertEquals("UsesMethodTest is incorrect",
240: new File(check, "UsesMethodTest.java"),
241: new File(dest, "UsesMethodTest.java"));
242: FileCompare.assertEquals("InheritMethodTest is incorrect",
243: new File(check, "InheritMethodTest.java"),
244: new File(dest, "InheritMethodTest.java"));
245: }
246:
247:
248: public void test04() throws RefactoringException {
249: RenameMethodRefactoring rmr = new RenameMethodRefactoring();
250: rmr.setClass("method", "RenameMethodTest");
251: rmr.setMethod("width");
252: rmr.setParams(new String[0]);
253: rmr.setNewMethodName("height");
254:
255: rmr.run();
256:
257: // Check things out
258: File check = new File(this.check + "\\ut4\\step4");
259:
260: FileCompare.assertEquals("RenameMethodTest is incorrect",
261: new File(check, "RenameMethodTest.java"),
262: new File(dest, "RenameMethodTest.java"));
263: FileCompare.assertEquals("UsesMethodTest is incorrect",
264: new File(check, "UsesMethodTest.java"),
265: new File(dest, "UsesMethodTest.java"));
266: FileCompare.assertEquals("InheritMethodTest is incorrect",
267: new File(check, "InheritMethodTest.java"),
268: new File(dest, "InheritMethodTest.java"));
269: }
270:
271:
272: public void test05() {
273: RenameMethodRefactoring rmr = new RenameMethodRefactoring();
274: rmr.setClass("method", "RenameMethodTest");
275: rmr.setMethod("code");
276: rmr.setParams(new String[] { "int" });
277: rmr.setNewMethodName("newCode");
278:
279: boolean exceptionThrown = false;
280:
281: try {
282: rmr.run();
283: } catch (RefactoringException re) {
284: exceptionThrown = true;
285: assertEquals("Incorrect exception", "No method named crazy is contained in RenameMethodTest", re.getMessage());
286: }
287:
288: assertTrue("No exception thrown", exceptionThrown);
289: }
290:
291:
292:
293: public void test06() {
294: RenameMethodRefactoring rmr = new RenameMethodRefactoring();
295: rmr.setClass("method", "RenameMethodTest");
296: rmr.setMethod("newCode");
297: rmr.setParams(new String[] { "int" });
298: rmr.setNewMethodName("code");
299:
300: boolean exceptionThrown = false;
301:
302: try {
303: rmr.run();
304: } catch (RefactoringException re) {
305: exceptionThrown = true;
306: assertEquals("Incorrect exception", "A method named code already exists in class RenameMethodTest", re.getMessage());
307: }
308:
309: assertTrue("No exception thrown", exceptionThrown);
310: }
311:
312:
313: public void test07() throws RefactoringException {
314: RenameMethodRefactoring rmr = new RenameMethodRefactoring();
315: rmr.setClass("method", "RenameMethodTest");
316: rmr.setMethod("height");
317: rmr.setParams(new String[] { "int" });
318: rmr.setNewMethodName("width");
319:
320: boolean exceptionThrown = false;
321:
322: try {
323: rmr.run();
324: } catch (RefactoringException re) {
325: exceptionThrown = true;
326: assertEquals("Incorrect exception", "A method named code already exists in class RenameMethodTest", re.getMessage());
327: }
328:
329: assertTrue("No exception thrown", exceptionThrown);
330: }
331:
332: public void test08() throws RefactoringException {
333: RenameMethodRefactoring rmr = new RenameMethodRefactoring();
334: rmr.setClass("method", "RenameMethodTest");
335: rmr.setMethod("width");
336: rmr.setParams(new String[] { "int" });
337: rmr.setNewMethodName("height");
338:
339: boolean exceptionThrown = false;
340:
341: try {
342: rmr.run();
343: } catch (RefactoringException re) {
344: exceptionThrown = true;
345: assertEquals("Incorrect exception", "A method named code already exists in class RenameMethodTest", re.getMessage());
346: }
347:
348: assertTrue("No exception thrown", exceptionThrown);
349: }
350:
351:
352: public void test09() throws RefactoringException {
353: RenameMethodRefactoring rmr = new RenameMethodRefactoring();
354: rmr.setClass("method", "InheritMethodTest");
355: rmr.setMethod("code");
356: rmr.setParams(new String[0]);
357: rmr.setNewMethodName("newCode");
358:
359: boolean exceptionThrown = false;
360:
361: try {
362: rmr.run();
363: } catch (RefactoringException re) {
364: exceptionThrown = true;
365: assertEquals("Incorrect exception", "A method named code already exists in class RenameMethodTest", re.getMessage());
366: }
367:
368: assertTrue("No exception thrown", exceptionThrown);
369: }
370:
371:
372: public void test10() throws RefactoringException {
373: RenameMethodRefactoring rmr = new RenameMethodRefactoring();
374: rmr.setClass("method", "InheritMethodTest");
375: rmr.setMethod("newCode");
376: rmr.setParams(new String[0]);
377: rmr.setNewMethodName("code");
378:
379: boolean exceptionThrown = false;
380:
381: try {
382: rmr.run();
383: } catch (RefactoringException re) {
384: exceptionThrown = true;
385: assertEquals("Incorrect exception", "A method named code already exists in class RenameMethodTest", re.getMessage());
386: }
387:
388: assertTrue("No exception thrown", exceptionThrown);
389: }
390:
391:
392: public void test11() throws RefactoringException {
393: RenameMethodRefactoring rmr = new RenameMethodRefactoring();
394: rmr.setClass("method", "InheritMethodTest");
395: rmr.setMethod("height");
396: rmr.setParams(new String[0]);
397: rmr.setNewMethodName("width");
398:
399: boolean exceptionThrown = false;
400:
401: try {
402: rmr.run();
403: } catch (RefactoringException re) {
404: exceptionThrown = true;
405: assertEquals("Incorrect exception", "A method named code already exists in class RenameMethodTest", re.getMessage());
406: }
407:
408: assertTrue("No exception thrown", exceptionThrown);
409: }
410:
411:
412: public void test12() throws RefactoringException {
413: RenameMethodRefactoring rmr = new RenameMethodRefactoring();
414: rmr.setClass("method", "InheritMethodTest");
415: rmr.setMethod("width");
416: rmr.setParams(new String[0]);
417: rmr.setNewMethodName("height");
418:
419: boolean exceptionThrown = false;
420:
421: try {
422: rmr.run();
423: } catch (RefactoringException re) {
424: exceptionThrown = true;
425: assertEquals("Incorrect exception", "A method named code already exists in class RenameMethodTest", re.getMessage());
426: }
427:
428: assertTrue("No exception thrown", exceptionThrown);
429: }
430:*/
431:
432: /**
433: * The JUnit setup method
434: *
435: */
436: protected void setUp() {
437: File cleanDir = new File(this .clean);
438: dest = new File(root + "\\method");
439: if (!dest.exists()) {
440: dest.mkdirs();
441: }
442:
443: (new FileCopy(
444: new File(cleanDir, "method_RenameMethodTest.java"),
445: new File(dest, "RenameMethodTest.java"), false)).run();
446: (new FileCopy(new File(cleanDir, "method_UsesMethodTest.java"),
447: new File(dest, "UsesMethodTest.java"), false)).run();
448: (new FileCopy(new File(cleanDir,
449: "method_InheritMethodTest.java"), new File(dest,
450: "InheritMethodTest.java"), false)).run();
451:
452: (new SummaryTraversal(root)).run();
453: }
454:
455: /**
456: * The teardown method for JUnit
457: *
458: */
459: protected void tearDown() {
460: (new File(dest, "RenameMethodTest.java")).delete();
461: (new File(dest, "UsesMethodTest.java")).delete();
462: (new File(dest, "InheritMethodTest.java")).delete();
463: }
464: }
|