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.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 pullup field refactoring.
012: *
013: *@author Chris Seguin
014: */
015: public class TestPushUpFieldRefactoring extends DirSourceTestCase {
016: private File impDest;
017: private File dest;
018:
019: /**
020: * Constructor for the TestPullUpFieldRefactoring object
021: *
022: *@param name the name of the unit test to run
023: */
024: public TestPushUpFieldRefactoring(String name) {
025: super (name);
026: }
027:
028: /**
029: * A unit test for JUnit
030: */
031: public void test1() {
032: PushUpFieldRefactoring puff = new PushUpFieldRefactoring();
033: puff.setClass("field.pullup", "Child");
034: puff.setField("panel1");
035:
036: boolean exceptionThrown = false;
037: try {
038: puff.run();
039: } catch (RefactoringException re) {
040: exceptionThrown = true;
041: assertEquals(
042: "Incorrect message",
043: "Field named panel1 already exists in parent class",
044: re.getMessage());
045: }
046:
047: assertTrue("No exception thrown", exceptionThrown);
048: }
049:
050: /**
051: * A unit test for JUnit
052: */
053: public void test2() {
054: PushUpFieldRefactoring puff = new PushUpFieldRefactoring();
055: puff.setClass("field.pullup", "Child");
056: puff.setField("panel2");
057:
058: boolean exceptionThrown = false;
059: try {
060: puff.run();
061: } catch (RefactoringException re) {
062: exceptionThrown = true;
063: assertEquals(
064: "Incorrect message",
065: "Field named panel2 already exists in an ancestor class",
066: re.getMessage());
067: }
068:
069: assertTrue("No exception thrown", exceptionThrown);
070: }
071:
072: /**
073: * A unit test for JUnit
074: *
075: *@exception RefactoringException Description of Exception
076: */
077: public void test3() throws RefactoringException {
078: PushUpFieldRefactoring puff = new PushUpFieldRefactoring();
079: puff.setClass("field.pullup", "Child");
080: puff.setField("panel3");
081:
082: puff.run();
083:
084: // Check things out
085: File check = new File(this .check + "\\ut2\\step1");
086:
087: FileCompare.assertEquals("Child is incorrect", new File(check,
088: "Child.java"), new File(dest, "Child.java"));
089: FileCompare.assertEquals("Child2 is incorrect", new File(check,
090: "Child2.java"), new File(dest, "Child2.java"));
091: FileCompare.assertEquals("Parent is incorrect", new File(check,
092: "Parent.java"), new File(dest, "Parent.java"));
093: }
094:
095: /**
096: * A unit test for JUnit
097: *
098: *@exception RefactoringException Description of Exception
099: */
100: public void test4() throws RefactoringException {
101: PushUpFieldRefactoring puff = new PushUpFieldRefactoring();
102: puff.setClass("field.pullup", "Child");
103: puff.setField("panel4");
104:
105: puff.run();
106:
107: // Check things out
108: File check = new File(this .check + "\\ut2\\step2");
109:
110: FileCompare.assertEquals("Child is incorrect", new File(check,
111: "Child.java"), new File(dest, "Child.java"));
112: FileCompare.assertEquals("Child2 is incorrect", new File(check,
113: "Child2.java"), new File(dest, "Child2.java"));
114: FileCompare.assertEquals("Parent is incorrect", new File(check,
115: "Parent.java"), new File(dest, "Parent.java"));
116: }
117:
118: /**
119: * A unit test for JUnit
120: *
121: *@exception RefactoringException Description of Exception
122: */
123: public void test5() throws RefactoringException {
124: PushUpFieldRefactoring puff = new PushUpFieldRefactoring();
125: puff.setClass("field.pullup", "Child");
126: puff.setField("panel5");
127:
128: puff.run();
129:
130: // Check things out
131: File check = new File(this .check + "\\ut2\\step3");
132:
133: FileCompare.assertEquals("Child is incorrect", new File(check,
134: "Child.java"), new File(dest, "Child.java"));
135: FileCompare.assertEquals("Child2 is incorrect", new File(check,
136: "Child2.java"), new File(dest, "Child2.java"));
137: FileCompare.assertEquals("Parent is incorrect", new File(check,
138: "Parent.java"), new File(dest, "Parent.java"));
139: }
140:
141: /**
142: * A unit test for JUnit
143: */
144: public void test6() {
145: PushUpFieldRefactoring puff = new PushUpFieldRefactoring();
146: puff.setClass("field.pullup", "Child");
147: puff.setField("panel7");
148:
149: boolean exceptionThrown = false;
150: try {
151: puff.run();
152: } catch (RefactoringException re) {
153: exceptionThrown = true;
154: assertEquals("Incorrect message",
155: "Field named panel7 does not exist in Child", re
156: .getMessage());
157: }
158:
159: assertTrue("No exception thrown", exceptionThrown);
160: }
161:
162: /**
163: * The JUnit setup method
164: */
165: protected void setUp() {
166: File cleanDir = new File(this .clean);
167: dest = new File(root + "\\field\\pullup");
168: if (!dest.exists()) {
169: dest.mkdirs();
170: }
171:
172: (new FileCopy(new File(cleanDir, "field_pullup_Child.java"),
173: new File(dest, "Child.java"), false)).run();
174: (new FileCopy(new File(cleanDir, "field_pullup_Child2.java"),
175: new File(dest, "Child2.java"), false)).run();
176:
177: (new FileCopy(new File(cleanDir, "field_pullup_Parent.java"),
178: new File(dest, "Parent.java"), false)).run();
179:
180: (new FileCopy(new File(cleanDir,
181: "field_pullup_Grandparent.java"), new File(dest,
182: "Grandparent.java"), false)).run();
183:
184: (new SummaryTraversal(root)).run();
185: }
186:
187: /**
188: * The teardown method for JUnit
189: */
190: protected void tearDown() {
191: (new File(dest, "Child.java")).delete();
192: (new File(dest, "Child2.java")).delete();
193: (new File(dest, "Parent.java")).delete();
194: (new File(dest, "Grandparent.java")).delete();
195: }
196: }
|