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