001: package org.acm.seguin.refactor.field;
002:
003: import java.io.File;
004: import java.util.Iterator;
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.PackageSummary;
009: import org.acm.seguin.summary.query.GetTypeSummary;
010: import org.acm.seguin.junit.FileCompare;
011: import org.acm.seguin.junit.DirSourceTestCase;
012: import org.acm.seguin.refactor.RefactoringException;
013:
014: /**
015: * Test cases for the PushDownFieldRefactoring object
016: *
017: *@author Chris Seguin
018: */
019: public class TestPushDownFieldRefactoring extends DirSourceTestCase {
020: /**
021: * Constructor for the TestPushDownFieldRefactoring object
022: *
023: *@param name Description of Parameter
024: */
025: public TestPushDownFieldRefactoring(String name) {
026: super (name);
027: }
028:
029: /**
030: * A unit test for JUnit
031: *
032: *@exception RefactoringException Description of Exception
033: */
034: public void test1() throws RefactoringException {
035: PushDownFieldRefactoring pdfr = new PushDownFieldRefactoring();
036: pdfr.setField("value1");
037: pdfr.setClass("imp.inh", "BaseClass");
038: pdfr.addChild("imp.inh", "ChildOneClass");
039:
040: pdfr.run();
041:
042: // Check things out
043: File check = new File(this .check + "\\ut2\\step4");
044: File dest = new File(root + "\\imp\\inh");
045:
046: FileCompare.assertEquals("BaseClass is incorrect", new File(
047: check, "BaseClass.java"), new File(dest,
048: "BaseClass.java"));
049: FileCompare.assertEquals("ChildOneClass is incorrect",
050: new File(check, "ChildOneClass.java"), new File(dest,
051: "ChildOneClass.java"));
052: }
053:
054: /**
055: * A unit test for JUnit
056: *
057: *@exception RefactoringException Description of Exception
058: */
059: public void test2() throws RefactoringException {
060: PushDownFieldRefactoring pdfr = new PushDownFieldRefactoring();
061: pdfr.setField("value2");
062: pdfr.setClass("imp.inh", "BaseClass");
063: pdfr.addChild("imp.inh", "ChildOneClass");
064: pdfr.addChild("imp.inh", "ChildTwoClass");
065:
066: pdfr.run();
067:
068: // Check things out
069: File check = new File(this .check + "\\ut2\\step5");
070: File dest = new File(root + "\\imp\\inh");
071:
072: FileCompare.assertEquals("BaseClass is incorrect", new File(
073: check, "BaseClass.java"), new File(dest,
074: "BaseClass.java"));
075: FileCompare.assertEquals("ChildOneClass is incorrect",
076: new File(check, "ChildOneClass.java"), new File(dest,
077: "ChildOneClass.java"));
078: FileCompare.assertEquals("ChildTwoClass is incorrect",
079: new File(check, "ChildTwoClass.java"), new File(dest,
080: "ChildTwoClass.java"));
081: }
082:
083: /**
084: * A unit test for JUnit
085: */
086: public void test3() {
087: PushDownFieldRefactoring pdfr = new PushDownFieldRefactoring();
088: pdfr.setField("value2");
089: pdfr.setClass("imp.inh", "BaseClass");
090: pdfr.addChild("imp.inh", "ChildOneClass");
091: pdfr.addChild("imp", "Associate");
092:
093: boolean exceptionThrown = false;
094: try {
095: pdfr.run();
096: } catch (RefactoringException re) {
097: assertEquals(
098: "Incorrect message",
099: "Trying to push a field from BaseClass to Associate and the destination is not a subclass of the source",
100: re.getMessage());
101: exceptionThrown = true;
102: }
103:
104: assertTrue("No exception thrown", exceptionThrown);
105: }
106:
107: /**
108: * The JUnit setup method
109: */
110: protected void setUp() {
111: File cleanDir = new File(clean);
112: File destDir = new File(root + "\\imp\\inh");
113:
114: (new FileCopy(new File(cleanDir, "imp_inh_BaseClass.java"),
115: new File(destDir, "BaseClass.java"), false)).run();
116: (new FileCopy(new File(cleanDir, "imp_inh_ChildOneClass.java"),
117: new File(destDir, "ChildOneClass.java"), false)).run();
118: (new FileCopy(new File(cleanDir, "imp_inh_ChildTwoClass.java"),
119: new File(destDir, "ChildTwoClass.java"), false)).run();
120:
121: (new SummaryTraversal(root)).run();
122: }
123:
124: /**
125: * The teardown method for JUnit
126: */
127: protected void tearDown() {
128: File destDir = new File(root + "\\imp\\inh");
129: (new File(destDir, "BaseClass.java")).delete();
130: (new File(destDir, "ChildOneClass.java")).delete();
131: (new File(destDir, "ChildTwoClass.java")).delete();
132: }
133: }
|