001: package org.acm.seguin.refactor.method;
002:
003: import java.io.File;
004: import org.acm.seguin.awt.Question;
005: import org.acm.seguin.summary.SummaryTraversal;
006: import org.acm.seguin.io.FileCopy;
007: import org.acm.seguin.summary.TypeSummary;
008: import org.acm.seguin.summary.MethodSummary;
009: import org.acm.seguin.summary.query.GetTypeSummary;
010: import org.acm.seguin.summary.query.GetMethodSummary;
011: import org.acm.seguin.refactor.RefactoringException;
012: import org.acm.seguin.junit.FileCompare;
013: import org.acm.seguin.junit.DirSourceTestCase;
014:
015: /**
016: * Functional tests for Push up method
017: *
018: *@author unknown
019: *@created April 5, 2000
020: */
021: public class TestPushUpMethod extends DirSourceTestCase {
022: /**
023: * Constructor for the TestPushUpMethod object
024: *
025: *@param name Description of Parameter
026: */
027: public TestPushUpMethod(String name) {
028: super (name);
029: }
030:
031: /**
032: * A unit test for JUnit
033: *
034: *@exception RefactoringException Description of Exception
035: */
036: public void test01() throws RefactoringException {
037: TypeSummary type = GetTypeSummary.query("method", "Child");
038: MethodSummary method = GetMethodSummary.query(type, "getPanel");
039:
040: PushUpMethodRefactoring pum = new PushUpMethodRefactoring();
041: pum.setMethod(method);
042:
043: pum.run();
044:
045: // Check things out
046: File checkDir = new File(check + "\\ut3\\step1");
047: File dest = new File(root + "\\method");
048:
049: FileCompare.assertEquals("Child is incorrect", new File(
050: checkDir + "\\Child.java"),
051: new File(dest, "Child.java"));
052: FileCompare
053: .assertEquals("Child2 is incorrect", new File(checkDir,
054: "Child2.java"), new File(dest, "Child2.java"));
055: FileCompare
056: .assertEquals("Parent is incorrect", new File(checkDir,
057: "Parent.java"), new File(dest, "Parent.java"));
058: }
059:
060: /*
061: * A unit test for JUnit
062: *
063: * @exception RefactoringException Description of Exception
064: * public void test02() throws RefactoringException {
065: * TypeSummary type = GetTypeSummary.query("method", "Child");
066: * MethodSummary method = GetMethodSummary.query(type, "setSleepTime");
067: * PushUpMethodRefactoring pum = new PushUpMethodRefactoring();
068: * pum.setMethod(method);
069: * pum.run();
070: * Check things out
071: * File check = new File(this.check + "\\ut3\\step2");
072: * File dest = new File(root + "\\method");
073: * FileCompare.assertEquals("Child is incorrect",
074: * new File(check, "Child.java"),
075: * new File(dest, "Child.java"));
076: * FileCompare.assertEquals("Parent is incorrect",
077: * new File(check, "Parent.java"),
078: * new File(dest, "Parent.java"));
079: * }
080: */
081:
082: /**
083: * A unit test for JUnit
084: */
085: public void test03() {
086: TypeSummary type = GetTypeSummary.query("method", "Child");
087: MethodSummary method = GetMethodSummary.query(type, "stopOne");
088:
089: PushUpMethodRefactoring pum = new PushUpMethodRefactoring();
090: pum.setMethod(method);
091:
092: boolean exceptionThrown = false;
093: try {
094: pum.run();
095: } catch (RefactoringException re) {
096: assertEquals(
097: "Incorrect message",
098: "A method with the same signature (name and parameter types) already exists in the Parent class",
099: re.getMessage());
100: exceptionThrown = true;
101: }
102:
103: assertTrue("No exception thrown", exceptionThrown);
104: }
105:
106: /**
107: * A unit test for JUnit
108: */
109: public void test04() {
110: TypeSummary type = GetTypeSummary.query("method", "Child");
111: MethodSummary method = GetMethodSummary.query(type, "stopTwo");
112:
113: PushUpMethodRefactoring pum = new PushUpMethodRefactoring();
114: pum.setMethod(method);
115:
116: boolean exceptionThrown = false;
117: try {
118: pum.run();
119: } catch (RefactoringException re) {
120: assertEquals(
121: "Incorrect message",
122: "A method with the conflicting signature (name and parameter types) already exists in the Parent class",
123: re.getMessage());
124: exceptionThrown = true;
125: }
126:
127: assertTrue("No exception thrown", exceptionThrown);
128: }
129:
130: /**
131: * A unit test for JUnit
132: */
133: public void test05() {
134: TypeSummary type = GetTypeSummary.query("method", "Child");
135: MethodSummary method = GetMethodSummary.query(type, "init");
136:
137: PushUpMethodRefactoring pum = new PushUpMethodRefactoring();
138: pum.setMethod(method);
139:
140: boolean exceptionThrown = false;
141: try {
142: pum.run();
143: } catch (RefactoringException re) {
144: assertEquals(
145: "Incorrect message",
146: "Method with a signature of init() : boolean found in child of Parent",
147: re.getMessage());
148: exceptionThrown = true;
149: }
150:
151: assertTrue("No exception thrown", exceptionThrown);
152: }
153:
154: /**
155: * The JUnit setup method
156: */
157: protected void setUp() {
158: Question.setAlwaysYes(true);
159: File cleanDir = new File(clean);
160: File destDir = new File(root + "\\method");
161: destDir.mkdir();
162:
163: (new FileCopy(new File(cleanDir, "method_Parent.java"),
164: new File(destDir, "Parent.java"), false)).run();
165: (new FileCopy(new File(cleanDir, "method_Child.java"),
166: new File(destDir, "Child.java"), false)).run();
167: (new FileCopy(new File(cleanDir, "method_Child2.java"),
168: new File(destDir, "Child2.java"), false)).run();
169:
170: (new SummaryTraversal(root)).run();
171: }
172:
173: /**
174: * The teardown method for JUnit
175: */
176: protected void tearDown() {
177: File destDir = new File(root + "\\method");
178: (new File(destDir, "Parent.java")).delete();
179: (new File(destDir, "Child.java")).delete();
180: (new File(destDir, "Child2.java")).delete();
181: Question.setAlwaysYes(false);
182: }
183: }
|